IMapCharacter.h
7.56 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
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
//
// 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 */