-rw-r--r-- | noncore/games/kbill/Game.cc | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/noncore/games/kbill/Game.cc b/noncore/games/kbill/Game.cc index 624b50b..4cd5322 100644 --- a/noncore/games/kbill/Game.cc +++ b/noncore/games/kbill/Game.cc | |||
@@ -13,189 +13,189 @@ int Game::RAND(int lb, int ub) { | |||
13 | return (rand()%(ub-lb+1) + lb); | 13 | return (rand()%(ub-lb+1) + lb); |
14 | } | 14 | } |
15 | 15 | ||
16 | int Game::MAX(int x, int y) { | 16 | int Game::MAX(int x, int y) { |
17 | return (x>y ? x : y); | 17 | return (x>y ? x : y); |
18 | } | 18 | } |
19 | 19 | ||
20 | int Game::MIN(int x, int y) { | 20 | int Game::MIN(int x, int y) { |
21 | return (x<y ? x : y); | 21 | return (x<y ? x : y); |
22 | } | 22 | } |
23 | 23 | ||
24 | int Game::INTERSECT(int x1, int y1, int w1, int h1, int x2, int y2, int w2, | 24 | int Game::INTERSECT(int x1, int y1, int w1, int h1, int x2, int y2, int w2, |
25 | int h2) | 25 | int h2) |
26 | { | 26 | { |
27 | return (((x2-x1<=w1 && x2-x1>=0) || (x1-x2<=w2 && x1-x2>=0)) | 27 | return (((x2-x1<=w1 && x2-x1>=0) || (x1-x2<=w2 && x1-x2>=0)) |
28 | && ((y2-y1<=h1 && y2-y1>=0) || (y1-y2<=h2 && y1-y2>=0))); | 28 | && ((y2-y1<=h1 && y2-y1>=0) || (y1-y2<=h2 && y1-y2>=0))); |
29 | } | 29 | } |
30 | 30 | ||
31 | void Game::setup_level (unsigned int lev) { | 31 | void Game::setup_level (unsigned int lev) { |
32 | level = lev; | 32 | level = lev; |
33 | bill.setup(); | 33 | bill.setup(); |
34 | grabbed = EMPTY; | 34 | grabbed = EMPTY; |
35 | ui.set_cursor(DEFAULTC); | 35 | ui.set_cursor(DEFAULTC); |
36 | net.setup(); | 36 | net.setup(); |
37 | iteration = efficiency = 0; | 37 | iteration = efficiency = 0; |
38 | } | 38 | } |
39 | 39 | ||
40 | void Game::start(unsigned int lev) { | 40 | void Game::start(unsigned int lev) { |
41 | state = PLAYING; | 41 | state = PLAYING; |
42 | score = 0; | 42 | score = 0; |
43 | ui.restart_timer(); | 43 | ui.restart_timer(); |
44 | ui.set_pausebutton(true); | 44 | ui.set_pausebutton(true); |
45 | setup_level(lev); | 45 | setup_level(lev); |
46 | } | 46 | } |
47 | 47 | ||
48 | void Game::quit() { | 48 | void Game::quit() { |
49 | 49 | ||
50 | exit(0); | 50 | exit(0); |
51 | } | 51 | } |
52 | 52 | ||
53 | void Game::update_info() { | 53 | void Game::update_info() { |
54 | static char str[80]; | 54 | static char str[80]; |
55 | sprintf (str, "Bill:%d/%d System:%d/%d/%d Level:%d Score:%d", | 55 | sprintf (str, "Bill:%d/%d System:%d/%d/%d Level:%d Score:%d", |
56 | bill.on_screen, bill.off_screen, net.base, net.off, | 56 | bill.on_screen, bill.off_screen, net.base, net.off, |
57 | net.win, level, score); | 57 | net.win, level, score); |
58 | ui.draw_str(str, 5, scrheight-5); | 58 | ui.draw_str(str, 5, scrheight-5); |
59 | efficiency += ((100*net.base-10*net.win)/net.units); | 59 | efficiency += ((100*net.base-10*net.win)/net.units); |
60 | } | 60 | } |
61 | 61 | ||
62 | void Game::update_score (int action) { | 62 | void Game::update_score (int action) { |
63 | switch (action){ | 63 | switch (action){ |
64 | case ENDLEVEL: score+=(level*efficiency/iteration); break; | 64 | case ENDLEVEL: score+=(level*efficiency/iteration); break; |
65 | default: score+=(action*action*BILLPOINTS); | 65 | default: score+=(action*action*BILLPOINTS); |
66 | } | 66 | } |
67 | } | 67 | } |
68 | 68 | ||
69 | void Game::warp_to_level (unsigned int lev) { | 69 | void Game::warp_to_level (unsigned int lev) { |
70 | if (state==PLAYING) { | 70 | if (state==PLAYING) { |
71 | if (lev <= level) return; | 71 | if (lev <= level) return; |
72 | setup_level(lev); | 72 | setup_level(lev); |
73 | } | 73 | } |
74 | else { | 74 | else { |
75 | if (lev<=0) return; | 75 | if (lev <=0) return; |
76 | start(lev); | 76 | start(lev); |
77 | } | 77 | } |
78 | } | 78 | } |
79 | 79 | ||
80 | void Game::button_press(int x, int y) { | 80 | void Game::button_press(int x, int y) { |
81 | int i, counter=0, flag=0; | 81 | int i, counter=0, flag=0; |
82 | if (state != PLAYING) return; | 82 | if (state != PLAYING) return; |
83 | ui.set_cursor(DOWNC); | 83 | ui.set_cursor(DOWNC); |
84 | if (bucket.clicked(x, y)) { | 84 | if (bucket.clicked(x, y)) { |
85 | ui.set_cursor(BUCKETC); | 85 | ui.set_cursor(BUCKETC); |
86 | grabbed = BUCKET; | 86 | grabbed = BUCKET; |
87 | } | 87 | } |
88 | for (i=0; i < bill.MAX_BILLS && !flag; i++) { | 88 | for (i=0; i < bill.MAX_BILLS && !flag; i++) { |
89 | if (bill.list[i].state == bill.list[i].OFF | 89 | if (bill.list[i].state == bill.list[i].OFF |
90 | || bill.list[i].state == bill.list[i].DYING) | 90 | || bill.list[i].state == bill.list[i].DYING) |
91 | continue; | 91 | continue; |
92 | if (bill.list[i].state == bill.list[i].STRAY && | 92 | if (bill.list[i].state == bill.list[i].STRAY && |
93 | bill.list[i].clickedstray(x, y)) | 93 | bill.list[i].clickedstray(x, y)) |
94 | { | 94 | { |
95 | ui.set_cursor (bill.list[i].cargo); | 95 | ui.set_cursor (bill.list[i].cargo); |
96 | grabbed = i; | 96 | grabbed = i; |
97 | flag = 1; | 97 | flag = 1; |
98 | } | 98 | } |
99 | else if (bill.list[i].state != bill.list[i].STRAY && | 99 | else if (bill.list[i].state != bill.list[i].STRAY && |
100 | bill.list[i].clicked(x, y)) | 100 | bill.list[i].clicked(x, y)) |
101 | { | 101 | { |
102 | if (bill.list[i].state == bill.list[i].AT) | 102 | if (bill.list[i].state == bill.list[i].AT) |
103 | net.computers[bill.list[i].target_c].busy=0; | 103 | net.computers[bill.list[i].target_c].busy=0; |
104 | bill.list[i].index = -1; | 104 | bill.list[i].index = -1; |
105 | bill.list[i].cels = bill.dcels; | 105 | bill.list[i].cels = bill.dcels; |
106 | bill.list[i].x_offset = -2; | 106 | bill.list[i].x_offset = -2; |
107 | bill.list[i].y_offset = -15; | 107 | bill.list[i].y_offset = -15; |
108 | bill.list[i].state = bill.list[i].DYING; | 108 | bill.list[i].state = bill.list[i].DYING; |
109 | counter++; | 109 | counter++; |
110 | } | 110 | } |
111 | } | 111 | } |
112 | if (counter) update_score(counter); | 112 | if (counter) update_score(counter); |
113 | } | 113 | } |
114 | 114 | ||
115 | void Game::button_release(int x, int y) { | 115 | void Game::button_release(int x, int y) { |
116 | int i; | 116 | int i; |
117 | ui.set_cursor (DEFAULTC); | 117 | ui.set_cursor (DEFAULTC); |
118 | if (state != PLAYING || grabbed == EMPTY) | 118 | if (state != PLAYING || grabbed == EMPTY) |
119 | return; | 119 | return; |
120 | if (grabbed == BUCKET) { | 120 | if (grabbed == BUCKET) { |
121 | grabbed = EMPTY; | 121 | grabbed = EMPTY; |
122 | for (i=0; i<net.ncables; i++) | 122 | for (i=0; i<net.ncables; i++) |
123 | if (net.cables[i].onspark(x, y)) { | 123 | if (net.cables[i].onspark(x, y)) { |
124 | net.cables[i].active=0; | 124 | net.cables[i].active=0; |
125 | net.cables[i].delay = spark.delay(level); | 125 | net.cables[i].delay = spark.delay(level); |
126 | } | 126 | } |
127 | return; | 127 | return; |
128 | } | 128 | } |
129 | for (i=0; i<net.units; i++) | 129 | for (i=0; i<net.units; i++) |
130 | if (net.computers[i].oncomputer(x, y) | 130 | if (net.computers[i].oncomputer(x, y) |
131 | && | 131 | && |
132 | net.computers[i].compatible (bill.list[grabbed].cargo) | 132 | net.computers[i].compatible (bill.list[grabbed].cargo) |
133 | && | 133 | && |
134 | (net.computers[i].os == OS.WINGDOWS || | 134 | (net.computers[i].os == OS.WINGDOWS || |
135 | net.computers[i].os == OS.OFF)) | 135 | net.computers[i].os == OS.OFF)) |
136 | { | 136 | { |
137 | net.base++; | 137 | net.base++; |
138 | if (net.computers[i].os == OS.WINGDOWS) | 138 | if (net.computers[i].os == OS.WINGDOWS) |
139 | net.win--; | 139 | net.win--; |
140 | else | 140 | else |
141 | net.off--; | 141 | net.off--; |
142 | net.computers[i].os = bill.list[grabbed].cargo; | 142 | net.computers[i].os = bill.list[grabbed].cargo; |
143 | bill.list[grabbed].state = bill.list[grabbed].OFF; | 143 | bill.list[grabbed].state = bill.list[grabbed].OFF; |
144 | grabbed = EMPTY; | 144 | grabbed = EMPTY; |
145 | return; | 145 | return; |
146 | } | 146 | } |
147 | grabbed = EMPTY; | 147 | grabbed = EMPTY; |
148 | } | 148 | } |
149 | 149 | ||
150 | void Game::update() { | 150 | void Game::update() { |
151 | switch (state) { | 151 | switch (state) { |
152 | case PLAYING: | 152 | case PLAYING: |
153 | ui.clear(); | 153 | ui.clear(); |
154 | bucket.draw(); | 154 | bucket.draw(); |
155 | net.update(); | 155 | net.update(); |
156 | net.draw(); | 156 | net.draw(); |
157 | bill.update(); | 157 | bill.update(); |
158 | bill.draw(); | 158 | bill.draw(); |
159 | update_info(); | 159 | update_info(); |
160 | if (!(bill.on_screen+bill.off_screen)) { | 160 | if (!(bill.on_screen+bill.off_screen)) { |
161 | update_score(ENDLEVEL); | 161 | update_score(ENDLEVEL); |
162 | state = BETWEEN; | 162 | state = BETWEEN; |
163 | } | 163 | } |
164 | if ((net.base+net.off)<=1) state = END; | 164 | if ((net.base+net.off)<=1) state = END; |
165 | break; | 165 | break; |
166 | case END: | 166 | case END: |
167 | ui.clear(); | 167 | ui.clear(); |
168 | net.toasters(); | 168 | net.toasters(); |
169 | net.draw(); | 169 | net.draw(); |
170 | ui.refresh(); | 170 | ui.refresh(); |
171 | ui.popup_dialog(ENDGAME); | 171 | ui.popup_dialog(ENDGAME); |
172 | /* if (score > scores.score[9]) ui.popup_dialog(ENTERNAME); | 172 | /* if (score > scores.score[9]) ui.popup_dialog(ENTERNAME); |
173 | scores.update();*/ | 173 | scores.update();*/ |
174 | ui.popup_dialog(HIGHSCORE); | 174 | ui.popup_dialog(HIGHSCORE); |
175 | ui.clear(); | 175 | ui.clear(); |
176 | ui.draw_centered(logo); | 176 | ui.draw_centered(logo); |
177 | ui.kill_timer(); | 177 | ui.kill_timer(); |
178 | ui.set_pausebutton (false); | 178 | ui.set_pausebutton (false); |
179 | state = WAITING; | 179 | state = WAITING; |
180 | break; | 180 | break; |
181 | case BETWEEN: | 181 | case BETWEEN: |
182 | ui.update_scorebox(level, score); | 182 | ui.update_scorebox(level, score); |
183 | ui.popup_dialog (SCORE); | 183 | ui.popup_dialog (SCORE); |
184 | state = PLAYING; | 184 | state = PLAYING; |
185 | setup_level(++level); | 185 | setup_level(++level); |
186 | break; | 186 | break; |
187 | } | 187 | } |
188 | ui.refresh(); | 188 | ui.refresh(); |
189 | iteration++; | 189 | iteration++; |
190 | } | 190 | } |
191 | 191 | ||
192 | void Game::main(int argc, char **argv) { | 192 | void Game::main(int argc, char **argv) { |
193 | int c; | 193 | int c; |
194 | extern char *optarg; | 194 | extern char *optarg; |
195 | 195 | ||
196 | level = 0; | 196 | level = 0; |
197 | ui.initialize(&argc, argv); | 197 | ui.initialize(&argc, argv); |
198 | while (argv && argv[0] && (c = getopt(argc, argv, "l:L:")) != -1) | 198 | while (argv && argv[0] && (c = getopt(argc, argv, "l:L:")) != -1) |
199 | switch(c) { | 199 | switch(c) { |
200 | case 'l': | 200 | case 'l': |
201 | case 'L': level = MAX (1, atoi(optarg)); break; | 201 | case 'L': level = MAX (1, atoi(optarg)); break; |