Blame view

ios/Runner/Wowgame/Classes/game_animal/AniMapLayer.h 5.14 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
  //
  //  AniMapLayer.h
  //  SteveMaggieCpp
  //
  //  Created by Katarzyna Kalinowska-Górska on 17.05.2017.
  //
  //
  
  #ifndef AniMapLayer_h
  #define AniMapLayer_h
  
  #include "cocos2d.h"
  #include "IMapImageObject.h"
  #include "AniMapUtils.h"
  #include "AniScenarioObject.h"
  #include "IMapAdventureObjectMapper.h"
  #include "IMapController.h"
  #include "IMapControl.h"
  #include "IMapControlCoordinator.h"
  #include "IMapCharacterController.h"
  #include "IMapCharacter.h"
  
  class IMapLayerDataSource
  {
  public:
      // virtual initializers. All these will be deleted here in the map layer;
      virtual IMapControl* initAllocMapControl() = 0;
      virtual IMapControlCoordinator* initAllocMapControlCoordinator() = 0;
      virtual IMapAdventureObjectMapper* initAllocAdventureObjectMapper() = 0;
      virtual std::vector<IMapCharacter*> createAutoreleasedMapCharacters() = 0;
      // controller at [i] corresponds to a character at [i]
      virtual std::vector<IMapCharacterController*> initAllocMapCharacterControllers() = 0;
      virtual IMapController* initAllocMapController(cocos2d::TMXTiledMap* p_map, IMapAdventureObjectMapper* p_mapper) = 0;
  };
  
  class IMapLayerDelegate
  {
  public:
      virtual void onMapAdventureObjectEvent(IMapAdventureObject* p_object, IMapAdventureObjectEvent* event){};
      virtual void onCharacterFinishedIntroFalling(IMapCharacter* character) {};
  };
  
  class AniMapLayer : public cocos2d::LayerColor, public AniScenarioObject, public IMapAdventureObjectDelegate {
  
      public:
    
          // creating / destructing
          static AniMapLayer* create(const std::string& resFolder, const std::string& mapPath, const rapidjson::Value* objects = NULL);
          bool init(const std::string& resFolder, const std::string& mapPath, const rapidjson::Value* objects = NULL);
          virtual ~AniMapLayer();
      
          // overrides
      
          virtual void onEnter() override;
          virtual void onExit() override;
          virtual void update(float) override;
      
          // setup
      
      virtual void setup(IMapLayerDataSource* p_dataSource);
      
      virtual cocos2d::Layer* addLayer(cocos2d::TMXTiledMap* p_parentMap);
      virtual void addObjectLayers(cocos2d::TMXTiledMap* p_parentMap, const rapidjson::Value* objectsData);
      virtual void fillObjects(cocos2d::TMXTiledMap* p_parentMap, const rapidjson::Value* externalObjectsData);
      void addNewObject(IMapImageObject* m_mapImageObject); //adds to object layer
      
      virtual void reallocMapControl();
      virtual void installMapControl(IMapControl* p_newMapControl);
      
          // character- related
      
      virtual void setChooseRandomSpawnTile(bool chooseRandom);
      virtual void setSpawnTile(int col, int row);
      
          // tiles and movement-related
      
  //        virtual void setColumnImpassable(int column, bool recalculateMap = true);
  //        virtual void setTileImpassable(AniMapUtils::TileData tile, bool recalculateMap = true);
  //        virtual void setCutRightOnColumn(int column);
      
      
          // set delegate
      
          inline void setAniMapLayerDelegate(IMapLayerDelegate* p_delegate){ m_delegate = p_delegate; }
      
      IMapController* getMapController() const {
          return m_mapController;
      }
      
  // Adv object deelgate
      virtual void onMapAdventureObjectEvent(IMapAdventureObject* p_object, IMapAdventureObjectEvent* event) override;
      virtual void onOccupiedTilesDataChanged(IMapAdventureObject* p_object) override;
      virtual void onBlockedTilesDataChanged(IMapAdventureObject* p_object, std::vector<AniMapUtils::TileData> p_oldBlockedTiles, std::vector<AniMapUtils::TileData> p_newBlockedTiles) override;
      
      virtual void spawnCharacters();
      virtual void clearCharacters();
      bool fastForwardCharacterFall();
      
          // friends
      
          friend class DemoHandler;
      
  protected:
      IMapLayerDelegate* m_delegate {nullptr};
      IMapLayerDataSource* m_dataSource {nullptr};
      
      IMapControl* m_mapControl {nullptr};
  //    IMapControlCoordinator* m_mapControlCoordinator {nullptr};
      
  // constants
      const AniMapUtils::TileData DefaultSpawnTile = AniMapUtils::TileData(0,0);
      
  // map
      IMapAdventureObjectMapper* m_adventureObjectMapper;
      IMapController* m_mapController;
      void deleteMap();
      void setupDarkness(float p_alpha);
      
  // characters
      std::vector<IMapCharacter*> m_mapCharacters;
      std::vector<IMapCharacterController*> m_mapCharacterControllers;
      void attachCharacterControllers();
      void attachMapControllerToCharacterControllers(IMapController* p_mapController);
      IMapCharacter* m_playerCharacter;
      
          std::string _resFolder;
          std::vector<cocos2d::Layer*> _objectLayers;
          std::map<std::string, cocos2d::Node*> _allObjects;
          int _defaultCharacterDepth;
      bool _chooseRandomSpawnTile {false};
      AniMapUtils::TileData m_spawnTile {DefaultSpawnTile};
      
          std::map<std::string, IMapImageObject*> m_mapImageObjects; //temp
          
          float _backgroundScale;
          
      
          // deletion
      void deleteMapControlObjects();
          void deleteMapAdventureObjectMapper();
      void deleteMapCharacterControllers();
      
      #ifdef DEBUG_MAP_OBJECT_DRAG_AROUND
          cocos2d::Node* _draggedObject;
      #endif
  };
  
  #endif /* AniMapLayer_h */