IMapCharacterController.h
4.03 KB
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
//
//  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<void()> 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<IMapAdventureObject*> p_advObjects){
        if(p_advObjects.size() > 0){
            return p_advObjects[0];
        }
        return nullptr;
    }
    
    virtual void interactWithAdventureObjects(std::vector<IMapAdventureObject*> 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<AniMapUtils::TileData> m_currentlyScheduledPath { };
    cocos2d::Point m_currentMoveDestination { -1, -1 };
    AniMapUtils::TileData m_moveDestinationTile { -1, -1 } ;
    int m_moveDestinationTileIndexOnPath { -1 };
    std::function<void()> 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<AniMapUtils::TileData> 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 */
