// // IMapCharacterController.h // WattsenglishFoodApp // // Created by Katarzyna Kalinowska-Górska on 22/03/2020. // #ifndef IMapCharacterController_h #define IMapCharacterController_h #include "IMapAdventureObject.h" #include "IMapController.h" #include "IMapImageObject.h" #include "IMapControlInterface.h" class IMapCharacter; class IMapCharacterController : public IMapControlInterface { public: void attachToCharacter(IMapCharacter* p_mapCharacter); void detachFromCharacter(); inline IMapCharacter* getCharacter() { return m_mapCharacter; } virtual void disableCharacter(); virtual void enableCharacter(); inline bool isCharacterDisabled() { return m_characterDisabled; } virtual void disableCharacterMovement(); virtual void enableCharacterMovement(); inline void setMapController(IMapController* p_mapController){m_mapController = p_mapController; } virtual void moveCharacterToTile(AniMapUtils::TileData toTile, std::function callback); virtual void moveCharacterByOneTile(int p_toCol, int p_toRow); virtual void stopMovingCharacter(); virtual void setDefaultCharacterPosture(); AniMapUtils::TileData getCurrentCharacterTile(); //note: here we might want to add a function deciding about the priority/order of handling adv objects virtual void interactWithAdventureObject(IMapAdventureObject* p_advObject) = 0; virtual void approachAdventureObject(IMapAdventureObject* p_advObject, AniMapUtils::TileData tile); virtual void adjustCharacterDepth(); // reveals tiles around the character void instantTilesReveal(bool allTheWayUp = false); // if multiple adventure objects are pressed, provide an algorithm to choose which has the priority virtual IMapAdventureObject* pickAdventureObject(std::vector p_advObjects){ if(p_advObjects.size() > 0){ return p_advObjects[0]; } return nullptr; } virtual void interactWithAdventureObjects(std::vector p_advObjects){ for(auto advObject : p_advObjects){ interactWithAdventureObject(advObject); } } virtual void interactWithAdventureObjects(); virtual ~IMapCharacterController(); //TODO maybe create a MapLifecycleInterface? virtual void onEnter(); virtual void update(float dt); protected: // basic stuff IMapCharacter* m_mapCharacter; IMapController* m_mapController; bool m_characterDisabled {false}; bool m_characterMovementDisabled {false}; cocos2d::Vec2 m_tileRevealRange {800, 600}; // move-related stuff float m_currentCharacterSpeedMultiplier { 1.0f }; std::vector m_currentlyScheduledPath { }; cocos2d::Point m_currentMoveDestination { -1, -1 }; AniMapUtils::TileData m_moveDestinationTile { -1, -1 } ; int m_moveDestinationTileIndexOnPath { -1 }; std::function m_currentOnDestinationTileReachedCallback; int m_tilePathAddCounter { 0 }; //TODO move all this to the default/basic subclass cocos2d::Point m_currentScreenTouchPoint {-1, -1}; long long _singleTouchDetectedTime {-1}; bool _singleTouchMoveLock {false}; long long m_lastUserActivityTime {-1}; IMapAdventureObject* m_approachedAdventureObject {nullptr}; AniMapUtils::TileData currentDestination(){ return *(m_currentlyScheduledPath.end()-1); } virtual void moveCharacterStartOnPath(std::vector p_path); virtual void moveCharacterToTouchedTile(const cocos2d::Point& touchLocation, const cocos2d::Point& mapPosition); virtual void updateLastUserActivityTime(); // update phases virtual void updatePhaseMoveCharacter(float p_dt, bool& doneMovingHorizontally, bool& doneMovingVertically); virtual void updatePhaseCheckCharacterStopped(float p_dt); virtual void onTileChange(const AniMapUtils::TileData& previousTile, const AniMapUtils::TileData& newTile) = 0; }; #endif /* IMapCharacterController_h */