2
0

Grid.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // ----------------------------------------------------------------
  2. // From Game Programming in C++ by Sanjay Madhav
  3. // Copyright (C) 2017 Sanjay Madhav. All rights reserved.
  4. //
  5. // Released under the BSD License
  6. // See LICENSE in root directory for full details.
  7. // ----------------------------------------------------------------
  8. #pragma once
  9. #include "Actor.h"
  10. #include <vector>
  11. class Grid : public Actor
  12. {
  13. public:
  14. Grid(class Game* game);
  15. // Handle a mouse click at the x/y screen locations
  16. void ProcessClick(int x, int y);
  17. // Use A* to find a path
  18. bool FindPath(class Tile* start, class Tile* goal);
  19. // Try to build a tower
  20. void BuildTower();
  21. // Get start/end tile
  22. class Tile* GetStartTile();
  23. class Tile* GetEndTile();
  24. void UpdateActor(float deltaTime) override;
  25. private:
  26. // Select a specific tile
  27. void SelectTile(size_t row, size_t col);
  28. // Update textures for tiles on path
  29. void UpdatePathTiles(class Tile* start);
  30. // Currently selected tile
  31. class Tile* mSelectedTile;
  32. // 2D vector of tiles in grid
  33. std::vector<std::vector<class Tile*>> mTiles;
  34. // Time until next enemy
  35. float mNextEnemy;
  36. // Rows/columns in grid
  37. const size_t NumRows = 7;
  38. const size_t NumCols = 16;
  39. // Start y position of top left corner
  40. const float StartY = 192.0f;
  41. // Width/height of each tile
  42. const float TileSize = 64.0f;
  43. // Time between enemies
  44. const float EnemyTime = 1.5f;
  45. };