10 #define TIMEFILL darkBlue
23 #define STATE_CREDITS 2
24 #define STATE_ENDSCREEN 3
25 #define STATE_PASSWORD 4
27 static char passwords[NUMLEVELS+1][5] =
29 "","1111","2222","3333","4444","5555","6666",
30 "7777","8888","9999","AAAA","BBBB"
37 borderStyle = sizable, hasMaximize = true, hasMinimize = true, hasClose = true;
38 text = "Bomb Squad", clientSize = Size { 640,400 };
41 char board[DIMY][DIMX];
51 double startTime, secPassed;
58 double currentTime = GetTime();
59 secPassed = currentTime - startTime;
60 if(secPassed >= TIME2)b=BOMB1;
61 else if(secPassed >= TIME1)b=BOMB3;
66 if((board[y][x]==BOMB1)||(board[y][x]==BOMB3)||(board[y][x]==BOMB5))
69 if(secPassed >= MAXTIME)
80 this, Seconds { 1 }, DelayExpired = DelayExpired
84 this, textHorzScroll = true, text = "Password",
85 anchor = Anchor { left = 0.03, top = 0.05, right = 0.84, bottom = 0.80 },
96 if((board[y][x]==BOMB1)||(board[y][x]==BOMB3)||(board[y][x]==BOMB5))
101 void SetPalette(bool flag)
103 ColorAlpha * palette = null;
106 case STATE_GAME: palette = LoadPalette(":nothing.pcx", null); break;
107 case STATE_MENU: palette = LoadPalette(":max3.pcx", null); break;
108 case STATE_CREDITS: palette = LoadPalette(":3.pcx", null); break;
109 case STATE_ENDSCREEN: palette = LoadPalette(":max3.pcx", null); break;
111 CopyBytesBy4(buffer.palette, palette, 256);
112 display.SetPalette(palette, flag);
116 void LoadLevel(int level)
125 startTime = GetTime();
126 sprintf(map,":map%d.dat",level);
128 f = FileOpen(map, read);
132 for(y=0; y<DIMY; y++)
133 for(x=0; x<DIMX; x++)
139 if(board[y][x]==PLAYER)
152 bool OnStateChange(WindowState state, Modifiers mods)
154 if(state == maximized && (Key)mods == hotKey)
156 app.fullScreen = true;
157 app.resolution = res320x200;
158 app.pixelFormat = pixelFormat8;
160 anchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
166 bool OnLoadGraphics()
169 endScreen.Load(":max3.pcx", null, null);
170 mainBitmap.Load(":max3.pcx", null, null);
171 credits.Load(":3.pcx", null, null);
172 password.Load(":password.pcx", null, null);
176 gfx[NOTHING].Load(":nothing.pcx", null, null);
177 gfx[PLAYER].Load(":player.pcx", null, null);
178 gfx[BOMB5].Load(":bomb.pcx", null, null);
179 gfx[BOMB3].Load(":deadeac.pcx", null, null);
180 gfx[BOMB1].Load(":deadeac.pcx", null, null);
181 gfx[BOMBD].Load(":deacbomb.pcx", null, null);
182 gfx[DESACTIV].Load(":desactiv.pcx", null, null);
183 gfx[BLOCK].Load(":block.pcx", null, null);
185 mapSize.w = gfx[0].width;
186 mapSize.h = gfx[0].height;
188 buffer.AllocateDD(displaySystem, 320, 200);
194 void OnUnloadGraphics()
207 void OnRedraw(Surface surface2)
209 Surface surface = buffer.GetSurface(0,0, null);
211 surface.SetBackground(black);
212 surface.Clear(colorBuffer);
219 int offX = (320 - mapSize.w * DIMX) / 2;
220 int offY = (200 - mapSize.h * DIMY - 20) / 2;
222 for(y=0; y<DIMY; y++)
223 for(x=0; x<DIMX; x++)
224 surface.Blit(gfx[board[y][x]],
225 offX + x*mapSize.w, offY + y*mapSize.h, 0,0,
226 mapSize.w,mapSize.h);
227 surface.Blit(gfx[PLAYER],
228 offX + player.x*mapSize.w, offY + player.y*mapSize.h,
229 0,0,mapSize.w,mapSize.h);
231 surface.SetForeground(TIMEBAR);
232 surface.Rectangle(0,buffer.height - 20,buffer.width-1,buffer.height-1);
233 width = (int)((buffer.width - 2)*(MAXTIME-secPassed)/MAXTIME);
234 surface.SetBackground(TIMEFILL);
235 surface.Area(1,buffer.height - 19,width,buffer.height - 2);
239 surface.Blit(mainBitmap, 0,0, 0,0, mainBitmap.width,mainBitmap.height);
242 surface.Blit(credits, 0,0, 0,0, credits.width,credits.height);
244 case STATE_ENDSCREEN:
245 surface.Blit(endScreen, 0,0, 0,0, endScreen.width,endScreen.height);
248 surface.Blit(password, 0,0,0,0,password.width, password.height);
253 surface2.Stretch(buffer, 0,0, 0,0, clientSize.w, clientSize.h,
254 buffer.width, buffer.height);
257 bool OnKeyDown(Key key, unichar character)
259 if(state == STATE_PASSWORD)
264 char * pwd = passEdit.contents;
265 for(l=1; l<=NUMLEVELS; l++)
266 if(!strcmpi(pwd,passwords[l]))
269 sprintf(string, "Wrapping to level %d...",l);
270 MessageBox { text = "Password Accepted", contents = string }.Modal();
275 else if(key != escape)
279 if(state == STATE_PASSWORD) state = STATE_MENU;
282 else if(state == STATE_MENU)
286 case s: LoadLevel(1); break;
288 state = STATE_PASSWORD;
291 case x: Destroy(0); return false;
292 case c: state = STATE_CREDITS; SetPalette(true); break;
299 if(state == STATE_GAME)
307 borderStyle = sizable, hasClose = true, hasMinimize = true, hasMaximize = true;
308 clientSize = { 640, 400 };
314 bool OnKeyHit(Key key, unichar ch)
316 if(state == STATE_GAME)
322 case up: dy=-1; break;
323 case down: dy=1; break;
324 case left: dx=-1; break;
325 case right: dx=1; break;
326 default: return true;
329 if((player.x+dx<0)||(player.y+dy<0)||(player.x+dx>=DIMX)||(player.y+dy>=DIMY))
332 if(board[player.y+dy][player.x+dx]==BLOCK) return true;
333 if((board[player.y+dy][player.x+dx]==BOMB5)
334 ||(board[player.y+dy][player.x+dx]==BOMB3)
335 ||(board[player.y+dy][player.x+dx]==BOMB1)
336 ||(board[player.y+dy][player.x+dx]==BOMBD))
338 if((player.x+dx*2<0)||(player.y+dy*2<0)||(player.x+dx*2>=DIMX)||(player.y+dy*2>=DIMY))
340 if((board[player.y+2*dy][player.x+2*dx]!=DESACTIV)&&
341 (board[player.y+2*dy][player.x+2*dx]!=NOTHING))
343 if(board[player.y+dy][player.x+dx]==BOMBD)
344 board[player.y+dy][player.x+dx]=DESACTIV;
346 board[player.y+dy][player.x+dx]=NOTHING;
347 if(board[player.y+2*dy][player.x+2*dx]==DESACTIV)
348 board[player.y+2*dy][player.x+2*dx]=BOMBD;
352 if(secPassed >= TIME2)b=BOMB1;
353 else if(secPassed >= TIME1)b=BOMB3;
355 board[player.y+2*dy][player.x+2*dx]=(byte)b;
364 if(level == NUMLEVELS)
366 state = STATE_ENDSCREEN;
372 sprintf(string, "Password to level %d is: %s",level+1,passwords[level+1]);
374 MessageBox { text = "Congratulations! You win!", contents = string }.Modal();
375 LoadLevel(level + 1);
384 class BombApp : GuiApplication
390 GuiApplication::Main();