2 Copyright (C) 2004 Parallel Realities
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 int offsetX = (int)(engine.playerPosX);
28 int offsetY = (int)(engine.playerPosY);
30 map.offsetX = offsetX;
31 map.offsetY = offsetY;
33 Math::limitInt(&offsetX, 0, ((MAPWIDTH - 40) * BRICKSIZE));
34 Math::limitInt(&offsetY, 0, ((MAPHEIGHT - 30) * BRICKSIZE));
36 int mapx = offsetX >> BRICKSHIFT;
37 int mapy = offsetY >> BRICKSHIFT;
40 for (int x = 0 ; x < 21 ; x++)
42 for (int y = 0 ; y < 16 ; y++)
44 brick = map.data[mapx + x][mapy + y];
46 r.x = ((x * BRICKSIZE) - (offsetX & (BRICKSIZE - 1)));
47 r.y = ((y * BRICKSIZE) - (offsetY & (BRICKSIZE - 1)));
48 r.w = r.h = BRICKSIZE;
50 if ((brick >= MAP_BREAKABLE) && (brick < MAP_WATERANIM))
52 graphics.blit(graphics.tile[brick], r.x, r.y, graphics.screen, false);
55 if ((brick >= MAP_NORESET) && (brick < MAP_DECORATION))
57 graphics.drawRect(r.x, r.y, 32, 4, graphics.yellow, graphics.screen);
65 void drawMapTopLayer()
69 int offsetX = map.offsetX;
70 int offsetY = map.offsetY;
72 Math::limitInt(&offsetX, 0, ((MAPWIDTH - 40) * BRICKSIZE));
73 Math::limitInt(&offsetY, 0, ((MAPHEIGHT - 30) * BRICKSIZE));
75 int mapx = offsetX >> BRICKSHIFT;
76 int mapy = offsetY >> BRICKSHIFT;
80 for (int x = 0 ; x < 21 ; x++)
82 for (int y = 0 ; y < 16 ; y++)
84 r.x = ((x * BRICKSIZE) - (offsetX & (BRICKSIZE - 1)));
85 r.y = ((y * BRICKSIZE) - (offsetY & (BRICKSIZE - 1)));
86 r.w = r.h = BRICKSIZE;
88 brick = map.data[mapx + x][mapy + y];
95 if ((brick < MAP_BREAKABLE) || (brick >= MAP_WATERANIM))
97 if (brick == MAP_WATER)
99 if (map.data[mapx + x][mapy + y + 1] >= MAP_BREAKABLE)
101 addBubble((mapx + x) * BRICKSIZE, (mapy + y) * BRICKSIZE);
105 if (brick == MAP_WATERANIM)
107 brick = graphics.getWaterAnim();
109 else if (brick == MAP_SLIME)
111 brick = graphics.getSlimeAnim();
113 else if ((brick >= MAP_LAVAANIM) && (brick < MAP_TOPLAYER))
115 map.data[mapx + x][mapy + y] = graphics.getLavaAnim(brick);
116 brick = map.data[mapx + x][mapy + y];
119 graphics.blit(graphics.tile[brick], r.x, r.y, graphics.screen, false);
125 void addBlips(List *blipList, int mapX, int mapY, int type)
133 blipType = graphics.getSprite("MIAArrow", true);
134 ent = (Entity*)map.miaList.getHead();
137 blipType = graphics.getSprite("ItemArrow", true);
138 ent = (Entity*)map.itemList.getHead();
141 blipType = graphics.getSprite("EnemyArrow", true);
142 ent = (Entity*)map.enemyList.getHead();
151 while (ent->next != NULL)
153 ent = (Entity*)ent->next;
155 if (ent->health <= 0)
160 if (!requiredEnemy(ent->name))
169 if ((ent->id < ITEM_MISC) || (ent->id == ITEM_MISC_INVISIBLE))
175 x = (int)(ent->x + ent->width) >> BRICKSHIFT;
176 y = (int)(ent->y + ent->height) >> BRICKSHIFT;
184 if ((x >= 165) && (y >= 125) && (x <= 475) && (y <= 355))
186 blip = new RadarBlip();
187 blip->set(x, y, type);
188 blipList->add (blip);
193 graphics.blit(blipType->image[0], 220 + (type * 50), 100, graphics.screen, true);
195 graphics.blit(blipType->image[1], 510, 140 + (type * 50), graphics.screen, true);
197 graphics.blit(blipType->image[2], 220 + (type * 50), 380, graphics.screen, true);
199 graphics.blit(blipType->image[3], 125, 140 + (type * 50), graphics.screen, true);
204 void addMiniMapDoors(SDL_Surface *panel, int mapX, int mapY)
206 Train *train = (Train*)map.trainList.getHead();
209 int width, height, color;
211 while (train->next != NULL)
213 train = (Train*)train->next;
217 color = graphics.white;
219 x = (int)train->x >> BRICKSHIFT;
221 y = (int)train->y >> BRICKSHIFT;
223 if ((x >= mapX) && (x <= mapX + 64) && (y >= mapY) && (y <= mapY + 48))
228 if (train->type == TR_TRAIN)
232 else if ((train->type >= TR_SLIDEDOOR) && (train->type <= TR_BRONZE_SLIDEDOOR))
244 case TR_GOLD_SLIDEDOOR:
245 color = graphics.yellow;
249 case TR_SILVER_SLIDEDOOR:
250 color = graphics.grey;
254 case TR_BRONZE_SLIDEDOOR:
255 color = SDL_MapRGB(graphics.screen->format, 0xff, 0x99, 0x00);
260 case TR_LOCKED_SLIDEDOOR:
261 color = SDL_MapRGB(graphics.screen->format, 0xff, 0x00, 0xff);
265 graphics.drawRect(x * 5, y * 5, width, height, color, panel);
270 void showMap(int centerX, int centerY)
280 int minX = (map.limitLeft >> BRICKSHIFT);
281 int maxX = (map.limitRight >> BRICKSHIFT) - 44;
282 int minY = (map.limitUp >> BRICKSHIFT);
283 int maxY = (map.limitDown >> BRICKSHIFT) - 33;
285 Math::limitInt(&x1, minX, maxX);
286 Math::limitInt(&x2, minX, maxX);
287 Math::limitInt(&y1, minY, maxY);
288 Math::limitInt(&y2, minY, maxY);
290 SDL_FillRect(graphics.screen, NULL, graphics.black);
291 graphics.updateScreen();
294 SDL_Surface *panel = graphics.createSurface(320, 240);
295 SDL_Surface *background = graphics.loadImage("gfx/main/mapBackground.png");
296 SDL_SetAlpha(background, SDL_SRCALPHA|SDL_RLEACCEL, 130);
298 graphics.blit(background, 0, 0, panel, false);
300 int color = graphics.black;
302 for (int y = 0 ; y < 48 ; y++)
304 for (int x = 0 ; x < 64 ; x++)
306 if (map.data[x1 + x][y1 + y] == MAP_WATER)
308 graphics.drawRect(x * 5, y * 5, 5, 5, graphics.blue, panel);
313 addMiniMapDoors(panel, x1, y1);
315 for (int y = 0 ; y < 48 ; y++)
317 for (int x = 0 ; x < 64 ; x++)
321 if (map.data[x1 + x][y1 + y] == MAP_AIR)
325 else if (map.data[x1 + x][y1 + y] == MAP_WATER)
329 else if (map.data[x1 + x][y1 + y] == MAP_SLIME)
331 color = graphics.green;
333 else if (map.data[x1 + x][y1 + y] == MAP_LAVA)
335 color = graphics.red;
337 else if (map.data[x1 + x][y1 + y] >= MAP_DECORATION)
341 if (map.data[x1 + x][y1 + y - 1] == MAP_WATER)
343 color = graphics.blue;
345 else if (map.data[x1 + x][y1 + y + 1] == MAP_WATER)
347 color = graphics.blue;
350 else if (map.data[x1 + x][y1 + y] < MAP_WATERANIM)
352 color = graphics.darkGreen;
357 graphics.drawRect(x * 5, y * 5, 5, 5, color, panel);
362 graphics.blit(background, 0, 0, graphics.screen, false);
363 SDL_FreeSurface(background);
367 RadarBlip *blip = new RadarBlip();
368 blip->set(160 + ((centerX - x1) * 5), 120 + ((centerY - y1) * 5), 0);
371 addBlips(&blipList, x1, y1, 1);
372 addBlips(&blipList, x1, y1, 2);
373 addBlips(&blipList, x1, y1, 3);
375 Sprite *enemySignal = graphics.getSprite("EnemySignal", true);
376 Sprite *miaSignal = graphics.getSprite("MIASignal", true);
377 Sprite *bobSignal = graphics.getSprite("BobSignal", true);
378 Sprite *itemSignal = graphics.getSprite("ItemSignal", true);
380 graphics.setFontColor(0xff, 0xff, 0xff, 0x00, 0x00, 0x00);
381 graphics.setFontSize(3);
382 graphics.drawString(_(game.stageName), 320, 30, TXT_CENTERED, graphics.screen);
384 graphics.setFontSize(0);
386 graphics.drawRect(160, 414, 7, 7, graphics.yellow, graphics.white, graphics.screen);
387 graphics.drawString(_("MIAs"), 175, 410, TXT_LEFT, graphics.screen);
389 graphics.drawRect(290, 414, 7, 7, graphics.blue, graphics.white, graphics.screen);
390 graphics.drawString(_("Items"), 305, 410, TXT_LEFT, graphics.screen);
392 graphics.drawRect(415, 414, 7, 7, graphics.red, graphics.white, graphics.screen);
393 graphics.drawString(_("Enemies"), 430, 410, TXT_LEFT, graphics.screen);
395 graphics.setFontSize(1);
396 snprintf(string, sizeof string, "%s - %.2d:%.2d:%.2d", _("Mission Time"), game.currentMissionHours, game.currentMissionMinutes, game.currentMissionSeconds);
397 graphics.drawString(string, 320, 60, TXT_CENTERED, graphics.screen);
398 graphics.drawString(_("Press Button to Continue..."), 320, 450, TXT_CENTERED, graphics.screen);
407 graphics.updateScreen();
408 graphics.animateSprites();
410 graphics.drawRect(160, 120, 320, 240, graphics.black, graphics.white, graphics.screen);
411 graphics.blit(panel, 160, 120, graphics.screen, false);
413 if ((config.isControl(CONTROL::MAP)) || (config.isControl(CONTROL::PAUSE)) || (engine.keyState[SDLK_ESCAPE]))
418 blip = (RadarBlip*)blipList.getHead();
420 while (blip->next != NULL)
422 blip = (RadarBlip*)blip->next;
427 graphics.blit(bobSignal->getCurrentFrame(), blip->x, blip->y, graphics.screen, true);
430 graphics.blit(miaSignal->getCurrentFrame(), blip->x, blip->y, graphics.screen, true);
433 graphics.blit(itemSignal->getCurrentFrame(), blip->x, blip->y, graphics.screen, true);
436 graphics.blit(enemySignal->getCurrentFrame(), blip->x, blip->y, graphics.screen, true);
446 SDL_FillRect(graphics.screen, NULL, graphics.black);
447 graphics.updateScreen();
454 void evaluateMapAttribute(Entity *ent, int mapAttribute)
456 switch (mapAttribute)
461 case MAP_AIR_CEILING_1:
462 mapAttribute = MAP_AIR;
465 if (map.isCavesTileset)
467 mapAttribute = MAP_AIR;
470 case MAP_AIR_CEILING_2:
471 if (map.isGrasslandsTileset)
473 mapAttribute = MAP_AIR;
475 else if (map.isCavesTileset)
477 mapAttribute = MAP_WATER;
481 if (map.isCavesTileset)
483 mapAttribute = MAP_WATER;
488 switch (mapAttribute)
491 if ((ent->environment != ENV_AIR) && (!(ent->flags & ENT_INANIMATE)))
493 if (!(ent->flags & ENT_SWIMS))
497 ent->dy = PLAYER_JUMP_SPEED;
502 if ((ent == &player) && ((game.hasAquaLung) || (engine.cheatExtras)))
504 player.setSprites(graphics.getSprite("BobRight", true), graphics.getSprite("BobLeft", true), graphics.getSprite("BobSpin", true));
508 ent->environment = ENV_AIR;
512 audio.playSound(SND_WATEROUT, CH_TOUCH);
515 ent->checkEnvironment();
525 ent->falling = false;
527 if (ent->environment == ENV_AIR)
529 audio.playSound(SND_WATERIN, CH_TOUCH);
530 if ((mapAttribute == MAP_SLIME) || (mapAttribute == MAP_LAVA))
534 // On ice levels water is harmful (because it's very very cold!)
535 if ((map.isIceLevel) && (mapAttribute == MAP_WATER))
537 mapAttribute = MAP_LAVA;
541 if (mapAttribute == MAP_WATER)
543 ent->environment = ENV_WATER;
544 if ((ent == &player) && ((game.hasAquaLung) || (engine.cheatExtras)))
546 player.setSprites(graphics.getSprite("AquaBobRight", true), graphics.getSprite("AquaBobLeft", true), graphics.getSprite("AquaBobSpin", true));
549 else if (mapAttribute == MAP_SLIME)
551 ent->environment = ENV_SLIME;
553 else if (mapAttribute == MAP_LAVA)
555 ent->environment = ENV_LAVA;
561 void raiseWaterLevel()
563 if (map.waterLevel == map.requiredWaterLevel)
568 int y = (int)map.waterLevel;
570 if ((int)map.waterLevel != map.requiredWaterLevel)
572 for (int x = 0 ; x < MAPWIDTH ; x++)
574 if ((map.data[x][y] == MAP_AIR) || (map.isLiquid(x, y)))
576 map.data[x][y] = MAP_WATER;
579 if ((map.data[x][y] >= MAP_DECORATION) && (map.data[x][y] <= MAP_WATERANIM))
581 map.data[x][y] = MAP_WATER;
584 if (map.data[x][y] >= MAP_TOPLAYER)
586 map.data[x][y] = MAP_WATER;
589 if (map.data[x][y - 1] >= MAP_TOPLAYER)
591 map.data[x][y] = MAP_WATER;
594 if ((map.data[x][y - 1] == MAP_AIR) || (map.isLiquid(x, y - 1)))
596 map.data[x][y - 1] = MAP_WATERANIM;
599 if ((map.data[x][y - 1] >= MAP_DECORATION) && (map.data[x][y - 1] <= MAP_WATERANIM))
601 map.data[x][y - 1] = MAP_WATERANIM;
605 map.waterLevel -= 0.1;
607 int x = (int)(player.x + player.dx) >> BRICKSHIFT;
608 int y = (int)(player.y + player.height - 1) >> BRICKSHIFT;
610 int mapAttribute = map.data[x][y];
612 if ((mapAttribute == MAP_WATER) && (player.environment == MAP_AIR))
614 evaluateMapAttribute(&player, mapAttribute);
621 map.windChangeTime--;
623 if (map.windChangeTime <= 0)
627 if (Math::rrand(0, 1) == 0)
628 map.windPower = Math::rrand(-3, 3);
631 map.windChangeTime = Math::rrand(60, 600);
637 void parseMapDataLine(const char *line, int y)
644 sscanf(line, "%d", &tileIndex);
646 map.data[x][y] = tileIndex;
663 bool loadMapData(const char *filename)
667 if (!engine.loadData(filename))
668 graphics.showErrorAndExit("The requested map '%s' was not found.", filename);
670 char *token = strtok((char*)engine.dataBuffer, "\n");
671 parseMapDataLine(token, 0);
677 token = strtok(NULL, "\n");
679 parseMapDataLine(token, y);