MapAdventureObjectRotatingEnd.h 3.48 KB
//
//  MapAdventureObjectRotatingEnd.h
//  WattsenglishFoodApp
//
//  Created by Katarzyna Kalinowska-Górska on 21/03/2020.
//

#ifndef MapAdventureObjectRotatingEnd_h
#define MapAdventureObjectRotatingEnd_h

#include "IMapAdventureObject.h"
#include "AniMapUtils.h"
#include "AniJSONParseUtilsMap.h"

class MapAdventureObjectRotatingEnd : public IMapAdventureObject {
    
public:
    // init
    MapAdventureObjectRotatingEnd(const rapidjson::Value& p_mapObjectData, IMapImageObject* p_mapImageObject, IMapImageObject* p_hintMapImageObject);
    
    // virtuals
    virtual std::vector<AniMapUtils::TileData> getEntryTiles()  const override;
    virtual std::vector<AniMapUtils::TileData> getOccupiedTiles() const override;
    
    // other getters
    inline bool isReady(){ return m_isReady; }
    virtual std::vector<AniMapUtils::TileData> getBlockedTiles() const override { return m_isReady ? std::vector<AniMapUtils::TileData>() : m_tempBlockedTiles; };
    
    // actions
    // this function rotates the map image object in such a way that grabbed point of the sprite lands on the touch point
    // when the rotation value reaches m_readyRotation+-eps, the object sets m_isReady to true and cannot be rotated any more
    virtual void rotate(/*cocos2d::Point p_grabbedPoint,*/ cocos2d::Point p_touchPointOnMap);
    virtual float evalNewRotation(cocos2d::Point p_touchPointOnMap); // calculate the rotation to which the object would rotate if rotate() was called with the same argument
//    virtual float evalDeltaRotation(cocos2d::Point p_touchPointOnMap); // calculate the delta rotation by which the object would rotate if rotate() was called with the same argument
    virtual bool evalReady(cocos2d::Point p_touchPointOnMap); // calculate whether the object would become ready if rotate() was called with the same argument
    bool evalReady(float p_newRotationDegrees);
    virtual void resetRotation();
    virtual void startBlinking();
    virtual void stopBlinking();
    virtual inline IMapImageObject* getMapImageObject(){ return m_mapImageObjects.begin()->second; }
    virtual inline IMapImageObject* getHintMapImageObject(){ return m_hintMapImageObject; }
    
    virtual void reset() override;
    
protected:
    // props
    bool m_wasAlwaysReady { false};
    bool m_isReady { false };
    bool m_mergesWithMapWhenReady {false};
    cocos2d::Point m_rotationPivotPoint;
    float m_originalRotation;
    float m_readyRotationDegrees;
    bool m_onlyAllowRightDirection {true};
    std::vector<AniMapUtils::TileData> m_entryTilesLying; // the tiles where the player stands at the beginning - near the lying ladder
    std::vector<AniMapUtils::TileData> m_entryTilesReady; // the tiles where the player stands at the beginning when the ladder is ready. both sides.
    std::vector<AniMapUtils::TileData> m_occupiedTilesLying; // all the tiles that we can press to approach and start interacting with the ladder when it's still lying
    std::vector<AniMapUtils::TileData> m_occupiedTilesReady; // all the tiles that we can press to approach and start interacting with the ladder when it's already up
    std::vector<AniMapUtils::TileData> m_tempBlockedTiles; // tiles that are blocked in !m_isReady state
    std::string m_originalPictureFilePath {""};
    std::string m_blinkPictureFilePath {""};
    virtual void performOnRotationComplete() = 0;
    IMapImageObject* m_hintMapImageObject {nullptr};
    
    virtual float ensureValidRotation(float rotation, float prevRotation);
};


#endif /* MapAdventureObjectRotatingEnd_h */