Advertisement
Guest User

Map.h

a guest
Mar 18th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.24 KB | None | 0 0
  1. #pragma once
  2. #include <utility>
  3. #include <vector>
  4. #include <string>
  5. #include <HAPISprites_lib.h>
  6. #include <HAPISprites_UI.h>
  7. #include "global.h"
  8.  
  9. class Entity;
  10.  
  11. enum eTileType
  12. {
  13.     eWater,
  14.     eGrass,
  15.     eSand
  16. };
  17.  
  18. struct Tile
  19. {
  20.     enum eTileType m_type;
  21.     Entity* m_entityOnTile;
  22.     std::unique_ptr<HAPISPACE::Sprite> m_sprite;
  23.     const std::pair<int, int> m_tileCoordinate;
  24.  
  25.     Tile(eTileType type, std::string spriteName, std::string directory, std::pair<int, int> coord) :
  26.         m_type(type), m_tileCoordinate(coord)
  27.     {
  28.         //HAPI's Sprite constructor takes two strings: the name of the file to load (append .xml)
  29.         //and the path to that file relative to the program
  30.         m_sprite = HAPI_Sprites.LoadSprite(spriteName, directory);
  31.     }
  32.     Tile(const Tile &other) : m_tileCoordinate(std::pair<int, int>(other.m_tileCoordinate.first, other.m_tileCoordinate.second))
  33.     {
  34.         m_type = other.m_type;
  35.         m_entityOnTile = other.m_entityOnTile;
  36.         m_sprite = HAPI_Sprites.MakeSprite(other.m_sprite->GetSpritesheet());
  37.     }
  38. };
  39.  
  40. class Map
  41. {
  42. private:
  43.     float m_windStrength;
  44.     eDirection m_windDirection;
  45.     float m_drawScale;
  46.     std::pair<int, int> m_drawOffset;
  47.  
  48.     std::pair<int, int> m_mapDimensions;
  49.     std::vector<Tile> m_data;
  50.  
  51.     std::pair<int, int> offsetToCube(std::pair<int, int> offset);
  52.     std::pair<int, int> cubeToOffset(std::pair<int, int> cube);
  53.     int cubeDistance(std::pair<int, int> a, std::pair<int, int> b);
  54.     bool inCone(std::pair<int, int> orgHex, std::pair<int, int> testHex, eDirection dir);
  55. public:
  56.     //Returns a pointer to a given tile, returns nullptr if there is no tile there
  57.     Tile *getTile(std::pair<int, int> coordinate);
  58.     //An n = 1 version of getTileRadius for use in pathfinding
  59.     std::vector<Tile*> getAdjacentTiles(std::pair<int, int> coord);
  60.     //TODO:Returns tiles in a radius around a given tile, skipping the tile itself
  61.     std::vector<Tile*>* getTileRadius(std::pair<int, int> coord, int range);
  62.     //TODO: Returns tiles in a cone emanating from a given tile, skipping the tile itself
  63.     std::vector<Tile*>* getTileCone(std::pair<int, int> coord, int range, eDirection direction);
  64.  
  65.     std::pair<int, int> getTileScreenPos(std::pair<int, int> coord);
  66.  
  67.     //Moves an entitys position on the map, returns false if the position is already taken
  68.     bool moveEntity(std::pair<int, int> originalPos, std::pair<int, int> newPos);
  69.     //Places a new entity on the map (no check for duplicates yet so try to avoid creating multiples)
  70.     void insertEntity(Entity* newEntity, std::pair<int, int> coord);
  71.  
  72.     void drawMap();
  73.     std::pair<int, int> getDrawOffset() const { return m_drawOffset; }
  74.     void setDrawOffset(std::pair<int, int> newOffset) { m_drawOffset = newOffset; }
  75.  
  76.     float getDrawScale() const { return m_drawScale; }
  77.     void setDrawScale(float scale) { if (scale > 0.0) m_drawScale = scale; }
  78.  
  79.     float getWindStrength() const { return m_windStrength; }
  80.     void setWindStrength(float strength) { if (strength > 0.0) m_windStrength = strength; }
  81.  
  82.     eDirection getWindDirection() const { return m_windDirection; }
  83.     void setWindDirection(eDirection direction) { m_windDirection = direction; }
  84.    
  85.     //TODO: remove later
  86.     std::vector<Tile>* getMap() { return &m_data; }
  87.  
  88.     //TODO: Get constructor working. Need tiled parser or load from xml set up
  89.     Map(int width, int height);
  90.     ~Map();
  91. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement