IMapCharacter.h 7.56 KB
//
//  MapCharacter.h
//  SteveMaggieCpp
//
//  Created by Katarzyna Kalinowska-Górska on 16.05.2017.
//
//

#ifndef MapCharacter_h
#define MapCharacter_h

#include "AniPlainSprite.h"
#include "IMapCharacterController.h"
#include "AniScalingUtils.h"

// todo: finish this class and add graphics source etc.
class IMapCharacterSoundSource;

//TODO climbing stuff goes in steve character, so does sliding and all these states...

class IMapCharacter : public AniPlainSprite
{
public:
    typedef enum {
        IDLE,
        WALKING,
//        CLIMBING,
        JUMPING,
        LAUGHING_STANDING,
        LAUGHING_SITTING,
        LAUGHING_LYING,
        DANCING,
        SLIDING,
        FALLING,
        BORED,
        POUT
    } State;
    
    // init
    virtual bool init(IMapCharacterSoundSource* p_soundSource);
    
    // cleanup
    virtual ~IMapCharacter();
    
        // animation tags
    
        static const unsigned int WALK_ANIMATION_TAG = 10;
        static const unsigned int CLIMB_ANIMATION_TAG = 11;
        static const unsigned int JUMP_ANIMATION_TAG = 12;
        static const unsigned int LAUGH_STANDING_ANIMATION_TAG = 13;
        static const unsigned int LAUGH_SITTING_ANIMATION_TAG = 14;
        static const unsigned int LAUGH_LYING_ANIMATION_TAG = 15;
        static const unsigned int FALL_ANIMATION_TAG = 16;
        static const unsigned int DANCE_ANIMATION_TAG = 17;
        static const unsigned int BORED_ANIMATION_TAG = 18;
        static const unsigned int SLIDE_ANIMATION_TAG = 19;
    
        // overrides
    
        virtual void onEnter() override;
    
    
// character controller
    inline void setController(IMapCharacterController* p_characterController){ m_characterController = p_characterController; }
    inline void clearController() { m_characterController = nullptr; }
    inline IMapCharacterController* getController(){ return m_characterController; }
    
    State getCharacterState() { return m_state; }
//    void setCharacterState(State p_state) { m_state = p_state; }
    
    bool isInFingerMoveState() { return m_state == WALKING; }//|| m_state == CLIMBING; }
    
    bool isClimbing() { return m_climbing; }
    bool isLaughing() { return m_state == LAUGHING_STANDING || m_state == LAUGHING_SITTING || m_state == LAUGHING_LYING; }
        virtual bool isBusy();
    
        virtual int getTimeToGetBored(){return m_secondsToGetBored;}
    virtual void setTimeToGetBored(int p_secondsToGetBored){ m_secondsToGetBored = p_secondsToGetBored; }
    
        // setters
        virtual void playClimbSound();
    
        // movement and actions

        virtual void stopAllAnimations();
    virtual void adjustDefaultImage();
    
    virtual void faceLeft();
    virtual void faceRight();
    virtual void setWalking(bool p_walking, bool adjustIdlePicture = true);
    virtual void setClimbing(bool p_climbing, int direction = 0);
//    virtual void setClimbing(bool p_climbing, bool adjustIdlePicture = true);
    virtual void startSliding();
    virtual void stopSliding(bool adjustIdlePicture = true);
        virtual void jump(float startVelocity, std::function<void()> fallingFinishedCallback = [](){});
        virtual void fallTo(cocos2d::Point position, float delay = 0, std::function<void()> fallingFinishedCallback = [](){});
        virtual void fastForwardFall();
        virtual void startLaughing();
        virtual void continueLaughing(float dt = 0);
        virtual void playScheduledLaughSound(float dt = 0);
        virtual void stopLaughing(bool adjustIdlePicture = true);
        virtual void startDancing();
        virtual void stopDancing(bool adjustIdlePicture = true);
        virtual void poke();
//        virtual void smile(float p_smileDuration = 4.f);
        virtual void setBored();
    virtual void setNotBored(bool playLetsPlay = false, bool adjustIdlePicture = true);
        virtual void runScheduledBoredAnimation(float dt = 0);
    
    virtual void callFunctionByName(std::string methodName, const rapidjson::Value* arguments, ActionParseDelegate* parseDelegate, std::function<void()> callback = [](){}) override {};
    
        virtual void temporarilyChangeClothes(float time) = 0;
    
    inline float getDeltaMove() { return m_deltaMove*AniScalingUtils::scaleAspectFitToDesignIpadProSize(); }
    
protected:
    
    State m_state { IDLE};
    bool m_climbing { false};
    int m_climbDirection { 0 };
    
    IMapCharacterSoundSource* m_soundSource {nullptr};
    
//    float LAUGH_TIME_TO_SIT = 0.6;
    float LAUGH_TIME_TO_TUMBLE = 1.0f;
    float LAUGH_MUCH_INTERVAL = 3;
    float BORED_ANIMATION_INTERVAL = 20;
    int BORED_ANIMATION_TIMES = 10; //TODO rename all these
    float AngryAfterPokeTime = 1.2f;
    float m_deltaMove = 14;

    int m_secondsToGetBored { 20 };
    
    // temp fall data
    cocos2d::Point _fallEndPoint;
    std::string _fallKey;
    
    IMapCharacterController* m_characterController;
    
        // frame animation and images
    
        virtual void adjustImage(const std::string& imagePath);
        virtual void adjustFrameAnimation();
        virtual void configureFrameAnimation(const std::vector< std::string>& animationFrames, float delayPerUnit,  int animationTag);
    
        // getting resources specific to a subclass; to be overriden in subclasses
    
        virtual const std::string _getDefaultStandImage() = 0;
        virtual const std::string _getFallingImage() = 0;
        virtual const std::vector< std::string>& _getWalkImages() = 0;
        virtual const std::vector< std::string>& _getJumpImages() = 0;
        virtual const std::vector< std::string>& _getJumpSquatImages() = 0;
        virtual const std::vector< std::string>& _getClimbImages() = 0;
        virtual const std::vector< std::string>& _getLaughStandingImages() = 0;
        virtual const std::vector< std::string>& _getLaughSittingImages() = 0;
        virtual const std::vector< std::string>& _getLaughLyingImages() = 0;
        virtual const std::vector< std::string>& _getDanceImages() = 0;
        virtual const std::string _getPokedImage() = 0;
        virtual const std::string _getSlidingImage() = 0;
        virtual const std::vector< std::string>& _getBoredStandAnimationImages() = 0;
        virtual const std::string _getBoredStandImage() = 0;
    
        virtual const std::vector< std::string>& _getJumpSounds() = 0;
        virtual const std::vector< std::string>& _getClimbSounds() = 0;
//        virtual const std::vector< std::string>& _getSingSongSounds() = 0;
        virtual const std::vector< std::string>& _getLaughSounds() = 0;
//        virtual const std::vector< std::string>& _getSlidingSounds() = 0;
        virtual const std::vector< std::string>& _getLaughMuchSounds() = 0;
        virtual const std::vector< std::string>& _getPokedSounds() = 0;
//        virtual const std::vector< std::string>& _getLetsPlaySounds() = 0;
    
        virtual const float _getWalkDelayPerFrame() = 0;
        virtual const float _getClimbDelayPerFrame() = 0;
        virtual const float _getLaughStandingDelayPerFrame() = 0;
        virtual const float _getLaughSittingDelayPerFrame() = 0;
        virtual const float _getLaughLyingDelayPerFrame() = 0;
        virtual const float _getDanceDelayPerFrame() = 0;
        virtual const float _getBoredAnimationDelayPerFrame() = 0;
};

class IMapCharacterSoundSource {
public:
    virtual bool shouldPlayBoredSound(IMapCharacter* p_mapCharacter) = 0;
//    virtual bool shouldPlayLetsPlaySound(IMapCharacter* p_mapCharacter) = 0;
    
    virtual std::string soundFilePathBored(IMapCharacter* p_mapCharacter) = 0;
//    virtual std::string soundFilePathLetsPlay(IMapCharacter* p_mapCharacter) = 0;
};

#endif /* MapCharacter_h */