HSubGameScene.h
6.33 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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
//
// HSubGameScene.h
// SteveAndMaggieGame
//
// Created by Katarzyna Kalinowska-Górska on 07/05/2019.
//
#ifndef HSubGameScene_h
#define HSubGameScene_h
#include "HalloweenParentScene.h"
#include "HGameLifeIndicatorView.h"
#include "HSettingsLayer.h"
class HSubGameScene : public HalloweenParentScene
{
public:
class GameCreator {
public:
virtual HSubGameScene* createGameScene(std::string layoutFilePath) = 0;
};
struct SoundConfig {
std::string soundsFolder;
std::map<std::string, float> soundDurations;
float soundPadding;
};
struct SoundInfo {
SoundInfo(std::string fp, float sd){
filePath = fp;
soundDuration = sd;
};
std::string filePath;
float soundDuration;
};
struct CommonConfig {
SoundConfig soundConfig;
std::vector<std::string> itemPicturePaths;
int maxItemsAtATime;
int screenPadding;
float maxSecondsInactivity;
int lives;
};
virtual void onEnter() override;
virtual void onExit() override;
// virtual void onEnterTransitionDidFinish() override;
virtual bool initWithConfiguration(std::string layoutFilePath, CommonConfig commonConfig);
virtual ~HSubGameScene();
virtual void pauseGame() = 0;
virtual void resumeGame() = 0;
virtual void presentGameResumeLayer();
virtual bool cleanupVideoPLayerIfNeeded();
// virtual void resumeVideoPlayerIfNeeded();
// void pauseVideo();
// void resumeVideo();
protected:
enum class PlayState
{
INIT,
PRE_PLAYING,
PLAYING,
PLAYING_VIDEO,
FINISHED_PLAYING_VIDEO,
CHANGING_LEVEL,
LOST,
WON
};
enum class ItemType : int {
NONE = 0,
ONE = 1,
TWO = 2,
THREE = 3,
FOUR = 4
};
class Item {
public:
cocos2d::Sprite* sprite;
cocos2d::Rect rect;
ItemType type;
bool operator==(const Item& item2) {
if(sprite == nullptr || item2.sprite == nullptr){
return false;
}
return sprite->getTag() == item2.sprite->getTag();
}
virtual ~Item(){
if(sprite != nullptr){
sprite->removeFromParent();
}
}
};
// state variables
class GameState {
public:
PlayState playState;
bool settingsMenuShown;
bool tosAcceptMenuShown;
std::map<int, Item*> items;
int currentLevel;
int currentItemTypeIndex;
std::vector<ItemType> itemTypeOrder; //the order of the types to catch (shuffled randomly at the beginning of each level)
bool itemVanishingMode;
float timeCount;
float lossTimeCount;
bool lossHalfTime;
int wrongItemCount;
virtual ~GameState(){}
};
GameState* gameState;
CommonConfig commonConfig;
HGameLifeIndicatorView* lifeIndicatorView;
HSettingsLayer* settingsMenu;
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN) && !defined(CC_PLATFORM_OS_TVOS)
cocos2d::ui::VideoPlayer* videoPlayer;
void videoPlayerCallback(cocos2d::Ref* sender, cocos2d::ui::VideoPlayer::EventType eventType);
#endif
virtual void prepareSettingsMenu();
virtual void moveSettingsButtonToFront(int localZOrder);
virtual void showSettingsMenu(bool animated = true);
virtual void hideSettingsMenu(bool animated = true);
virtual void hideSettingsMenuWithLevelReset();
virtual void addLivesIndicatorView();
virtual GameState* createGameState();
virtual void removeGameState();
virtual void clearGameState();
virtual void clearAllItems();
virtual bool generateItemTypeAndId(ItemType& itemType, int& itemId, std::string& itemPicturePath, ItemType preferredType = ItemType::NONE);
virtual bool touchHandlerForWidget(std::string objectName, cocos2d::ui::Widget::TouchEventType touchEventType) override;
virtual bool onPrevLevelButtonClicked();
virtual bool onReplayButtonClicked();
virtual bool onNextLevelButtonClicked();
virtual SoundInfo intro1Sound();
virtual SoundInfo intro2Sound();
virtual SoundInfo hooraySound();
virtual SoundInfo oopsSound();
virtual SoundInfo pureOopsSound();
virtual SoundInfo noSound();
virtual SoundInfo pickLevelSound();
virtual SoundInfo gameFinishedSound();
virtual SoundInfo gameLostSound();
virtual SoundInfo typeRequestSound(ItemType itemType);
virtual SoundInfo typeConfirmSound(ItemType itemType);
virtual SoundInfo typeWrongSound(ItemType itemType);
virtual SoundInfo wrongItemEffectSound();
virtual SoundInfo rightItemEffectSound();
float soundDuration(const std::string soundFilepath);
void preloadAllLoadedSoundEffects();
virtual void prepareVideoPlayerIfNeeded();
virtual void removeVideoPlayer();
virtual void playVideo(std::string videoFilePath);
virtual void videoPLayerFinishedPlayback();
virtual void startGame(bool playIntro = true) = 0;
virtual void gameWon();
virtual void gameLost();
virtual void resetGame();
virtual void showTOSAcceptPopup(std::function<void()> onAccept);
virtual void showHLevelPickerLayer(std::function<void()> onLayerDismissed);
virtual void addTouchBlockingLayer(cocos2d::Node* layer);
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
cocos2d::EventListenerKeyboard* _keyboardListener;
void addBackButtonListener(){
_keyboardListener = cocos2d::EventListenerKeyboard::create();
_keyboardListener->onKeyReleased = [&](cocos2d::EventKeyboard::KeyCode keyCode, cocos2d::Event* event){
if(keyCode == cocos2d::EventKeyboard::KeyCode::KEY_BACK){
if(!gameState->settingsMenuShown && !gameState->tosAcceptMenuShown){
pauseGame();
HMiscUtils::showAppCloseConfirmDialog([&](){
resumeGame();
});
}
}
};
cocos2d::Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(_keyboardListener, this);
}
#endif
};
#endif /* HSubGameScene_h */