Blame view

ios/Runner/Wowgame/Classes/game_animal/IMapController.h 5.3 KB
5daad4bc   xiaoyu   游戏源码添加编译(现存问题:游戏内...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
  //
  //  AniMapLayer.h
  //  SteveMaggieCpp
  //
  //  Created by Katarzyna Kalinowska-Górska on 17.05.2017.
  //
  //
  
  #ifndef IMapController_h
  #define IMapController_h
  
  #include "cocos2d.h"
  #include "IMapImageObject.h"
  #include "IMapAdventureObject.h"
  #include "IMapAdventureObjectMapper.h"
  #include "AniMapUtils.h"
  #include "IMapControlInterface.h"
  
  class IMapController : public IMapControlInterface {
      
  public:
      IMapController(cocos2d::TMXTiledMap* p_map, IMapAdventureObjectMapper* p_adventureObjectMapper){
          m_map = p_map;
          m_adventureObjectMapper = p_adventureObjectMapper;
      }
      
      inline cocos2d::TMXTiledMap* getMap(){ return m_map; }
      virtual cocos2d::TMXLayer* getTileLayer() = 0;
      virtual cocos2d::TMXLayer* getTileObjectLayer() = 0;
  //    virtual void addBlockedTile(AniMapUtils::TileData p_tile) = 0;
      virtual void addBlockedTiles(std::vector<AniMapUtils::TileData> p_tiles, bool recalculateGraph) = 0;
  //    virtual void removeBlockedTile(AniMapUtils::TileData p_tile) = 0;
      virtual void removeBlockedTiles(std::vector<AniMapUtils::TileData> p_tiles, bool recalculateGraph) = 0;
      inline AniMapUtils::TileData getTileForTouchPoint(cocos2d::Point p_screenTouchPoint){
          auto mapPoint = AniMapUtils::getInstance().translateScreenPositionToMapPosition(p_screenTouchPoint, getCameraPosition());
          return AniMapUtils::getInstance().translateXYPointToColRow(mapPoint, m_map->getTileSize().width, m_map->getTileSize().height, m_map->getMapSize().width, m_map->getMapSize().height);
      }
  
      virtual void revealTile(cocos2d::Vec2 tileCoord) = 0;
      virtual void revealTilesInRadius(cocos2d::Point p_center, float p_radiusX, float p_radiusY) = 0;
      
      // map image objects
      virtual int getBackgroundDepth() = 0;
      virtual int getMaxObjectDepth() = 0;
      virtual IMapImageObject* getMapImageObject(std::string p_objectName) = 0;
      virtual std::vector<IMapImageObject*> getMapImageObjects() = 0;
      virtual std::vector<IMapImageObject*> getMapImageObjectsBoundByRect(cocos2d::Rect p_rect) = 0;
      
      // map adventure objects
      virtual void parseAdventureObjects(const std::string& p_mapAdventureObjectsFile, IMapAdventureObjectDelegate* p_objectsDelegate) = 0;
      virtual std::vector<IMapAdventureObject*> getAdventureObjectsAtTile(const AniMapUtils::TileData& p_tileData, bool activeObjectsOnly = true) = 0;
      std::vector<IMapAdventureObject*> getAdventureObjectsAtMapPoint(cocos2d::Point p_mapPoint, bool activeObjectsOnly = true){
          auto rowCol = AniMapUtils::getInstance().translateXYPointToColRow(p_mapPoint, m_map->getTileSize().width, m_map->getTileSize().height, m_map->getMapSize().width, m_map->getMapSize().height);
          return getAdventureObjectsAtTile(rowCol);
      }
      std::vector<IMapAdventureObject*> getAdventureObjectsAtTouchPoint(cocos2d::Point p_screenTouchPoint, bool activeObjectsOnly = true){
              return getAdventureObjectsAtMapPoint(AniMapUtils::getInstance().translateScreenPositionToMapPosition(p_screenTouchPoint, getCameraPosition()), activeObjectsOnly);
      }
      virtual void clearAdventureObjects(bool clearAssociatedImageObjects = true) = 0;
      virtual void clearAdventureObject(IMapAdventureObject* p_adventureObject, bool clearAssociatedImageObjects = true) = 0;
      virtual void remapAdventureObject(IMapAdventureObject* p_adventureObject) = 0;
      
      // TODO TIHS IS TEMP> PARSING SHOULD E SOMEWHERE IN A MAP PARSER EVERYTHING SHOULD BE ARRANGED IN A SMART WAY
      //TODO ADVENTURE OBJECTS HSOULD BE HERE AS WELL
      virtual void insertMapImageObject(std::string objectName, IMapImageObject* object) = 0;
      
      // camera
      constexpr static float DefaultCameraVelocity {800};
      inline void setCameraVelocity(float p_cameraVelocity){ m_cameraVelocity = p_cameraVelocity;}
      inline cocos2d::Point getCameraPosition(){ return m_map->getParent()->getPosition(); };
      virtual cocos2d::Vec2 moveCamera(float deltaX, float deltaY, bool animated = false) = 0;
      virtual bool setCameraCenter(cocos2d::Point position, bool instantEffect = false) = 0;
      virtual bool centerCameraOnNode(cocos2d::Node* p_node, bool instantEffect = false) = 0;
      virtual bool isInZoomMode() = 0;
      virtual void cancelZoomMode() = 0;
      inline void setCameraDestination(cocos2d::Point p_cameraDestination){
          m_cameraDestination = p_cameraDestination;
      }
      inline void moveCameraDestination(cocos2d::Point p_delta){
          m_cameraDestination += p_delta;
      }
      virtual void setCameraCut(cocos2d::Rect cameraCut){
          m_cameraCut = cameraCut;
      };
      virtual void cancelCameraCut(){
          m_cameraCut = cocos2d::Rect::ZERO;
      }
      
      
      // update
      virtual void update(float dt) = 0;
      
      virtual void reset() = 0;
      
      virtual ~IMapController(){};
  //
  //// IMapControlInterface
  //    
  //    virtual void handleCommandSingleXYPress(const IMapControlSingleXYEventData& eventData) = 0;
  //    virtual void handleCommandSingleXYMove(const IMapControlSingleXYEventData& eventData) = 0;
  //    virtual void handleCommandSingleXYRelease(const IMapControlSingleXYEventData& eventData) = 0;
      
  protected:
      cocos2d::TMXTiledMap* m_map;
      cocos2d::Rect m_cameraCut { cocos2d::Rect::ZERO };
      IMapAdventureObjectMapper* m_adventureObjectMapper;
      cocos2d::Point m_cameraDestination;
      float m_cameraVelocity {DefaultCameraVelocity};
  };
  
  #endif /* IMapController_h */