/src/MenuMiniMap.cpp

http://github.com/clintbellanger/flare · C++ · 110 lines · 65 code · 17 blank · 28 comment · 26 complexity · 7268ea59365a40a331e8061da3879e4f MD5 · raw file

  1. /*
  2. Copyright 2011 Clint Bellanger
  3. This file is part of FLARE.
  4. FLARE is free software: you can redistribute it and/or modify it under the terms
  5. of the GNU General Public License as published by the Free Software Foundation,
  6. either version 3 of the License, or (at your option) any later version.
  7. FLARE is distributed in the hope that it will be useful, but WITHOUT ANY
  8. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  9. PARTICULAR PURPOSE. See the GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License along with
  11. FLARE. If not, see http://www.gnu.org/licenses/
  12. */
  13. /**
  14. * class MenuMiniMap
  15. */
  16. #include "MenuMiniMap.h"
  17. #include "SharedResources.h"
  18. MenuMiniMap::MenuMiniMap() {
  19. color_wall = SDL_MapRGB(screen->format, 128,128,128);
  20. color_obst = SDL_MapRGB(screen->format, 64,64,64);
  21. color_hero = SDL_MapRGB(screen->format, 255,255,255);
  22. map_center.x = VIEW_W - 64;
  23. map_center.y = 80;
  24. map_area.x = VIEW_W - 128;
  25. map_area.y = 16;
  26. map_area.w = map_area.h = 128;
  27. }
  28. /**
  29. * Render a top-down version of the map (90 deg angle)
  30. */
  31. void MenuMiniMap::render(MapCollision *collider, Point hero_pos, int map_w, int map_h) {
  32. Point hero_tile;
  33. Point map_tile;
  34. hero_tile.x = hero_pos.x / UNITS_PER_TILE;
  35. hero_tile.y = hero_pos.y / UNITS_PER_TILE;
  36. for (int i=0; i<127; i++) {
  37. for (int j=0; j<127; j++) {
  38. map_tile.x = hero_tile.x + i - 64;
  39. map_tile.y = hero_tile.y + j - 64;
  40. if (map_tile.x >= 0 && map_tile.x < map_w && map_tile.y >= 0 && map_tile.y < map_h) {
  41. if (collider->colmap[map_tile.x][map_tile.y] == 1) {
  42. drawPixel(screen, VIEW_W - 128 + i, 16+j, color_wall);
  43. }
  44. else if (collider->colmap[map_tile.x][map_tile.y] == 2) {
  45. drawPixel(screen, VIEW_W - 128 + i, 16+j, color_obst);
  46. }
  47. }
  48. }
  49. }
  50. drawPixel(screen,VIEW_W-64,80,color_hero); // hero
  51. drawPixel(screen,VIEW_W-64-1,80,color_hero); // hero
  52. drawPixel(screen,VIEW_W-64+1,80,color_hero); // hero
  53. drawPixel(screen,VIEW_W-64,80-1,color_hero); // hero
  54. drawPixel(screen,VIEW_W-64,80+1,color_hero); // hero
  55. }
  56. /**
  57. * Render an "isometric" version of the map (45 deg angle)
  58. */
  59. void MenuMiniMap::renderIso(MapCollision *collider, Point hero_pos, int map_w, int map_h) {
  60. int tile_type;
  61. Point screen_pos;
  62. Uint32 draw_color;
  63. Point hero_tile;
  64. hero_tile.x = hero_pos.x / UNITS_PER_TILE;
  65. hero_tile.y = hero_pos.y / UNITS_PER_TILE;
  66. for (int j=0; j<map_h; j++) {
  67. for (int i=0; i<map_w; i++) {
  68. tile_type = collider->colmap[i][j];
  69. // the hero, walls, and low obstacles show as different colors
  70. if (i == hero_tile.x && j == hero_tile.y) draw_color = color_hero;
  71. else if (tile_type == 1) draw_color = color_wall;
  72. else if (tile_type == 2) draw_color = color_obst;
  73. else continue; // not visible on mini-map
  74. // isometric transform
  75. screen_pos.x = (i - hero_tile.x) - (j - hero_tile.y) + map_center.x;
  76. screen_pos.y = (i - hero_tile.x) + (j - hero_tile.y) + map_center.y;
  77. // each tile is 2 pixels wide to mimic isometric view
  78. if (isWithin(map_area, screen_pos)) {
  79. drawPixel(screen, screen_pos.x, screen_pos.y, draw_color);
  80. }
  81. screen_pos.x++;
  82. if (isWithin(map_area, screen_pos)) {
  83. drawPixel(screen, screen_pos.x, screen_pos.y, draw_color);
  84. }
  85. }
  86. }
  87. }
  88. MenuMiniMap::~MenuMiniMap() {
  89. }