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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248 |
#include "gfCGeneratedHogSubSceneComponent.h"
#include "fsIDisplay.h"
#include <fsAppCore/fsIInputManager.h>
#include <fsAppCore/src/components/fsISubSceneComponent.h>
#include <fsRenderer/src/components/fsCSpriteComponent.h>
#include <fsRenderer/src/fsCBrushManager.h>
#include <fsRenderer/src/fsCSprite.h>
#include "test/gfCAutoTestManager.h"
#include "levelSequencer/map/gfCLevelSequencerMapLevelIconComponent.h"
#include "src/fsCGuiMessageDispatcher.h"
#include "src/fsCScreenFade.h"
#include "src/fsCEntityFactory.h"
#include "src/gfCHogEntityFactory.h"
#include "gfMaze/src/gfCSimpleMazeComponent.h"
const fsCUniqueId gfCGeneratedHogSubSceneComponent::mTypeId("gfCGeneratedHogSubSceneComponent");
fsBool gfCGeneratedHogSubSceneComponent::clickableEntsAvailableGetDo() const
{
auto clickableEnts = parentGet()->childEntitiesWithComponentsOfFamilyType<gfCLevelSequencerMapLevelIconComponent>();
if (!clickableEnts.empty())
{
return true;
}
return false;
}
void gfCGeneratedHogSubSceneComponent::gfGeneratedHogSubSceneMap::moveMe(fsVec2d newPos) {
mMe->posSet(fsVec2d(newPos.x * 20 - mOffset.x,
newPos.y * 20 + mOffset.y));
}
gfCGeneratedHogSubSceneComponent::gfGeneratedHogSubSceneMap::gfGeneratedHogSubSceneMap(gfCGeneratedHogSubSceneComponent *parent) :<--- Member variable 'gfGeneratedHogSubSceneMap::mMe' is not initialized in the constructor. [+]Member variable 'gfGeneratedHogSubSceneMap::mMe' is not initialized in the constructor. Member variables of native types, pointers, or references are left uninitialized when the class is instantiated. That may cause bugs or undefined behavior.
mParent(parent),
mOffset(-fsIDisplay::instanceGet()->visibleCanvasWidthGet() / 2 + parent->mMaze->getWidth() * 20 + 180,
fsIDisplay::instanceGet()->visibleCanvasHeightGet() / 2 - parent->mMaze->getHeight() * 20 -180)
{
}
void gfCGeneratedHogSubSceneComponent::gfGeneratedHogSubSceneMap::create()
{
auto wallTileBrush = fsCBrushManager::instanceGet()->get(
fsCResourceName("gui/miniGameGui/wordSearch/smallTiles/x.png", fsCResourceName::eRES_LOCATION_ASSETS), false);
for (int i = 0; i < mParent->mMaze->getHeight(); i++) {
for (int j = 0; j < mParent->mMaze->getWidth(); j++) {
auto tile = mParent->mMaze->getCell(j, i);
if (tile == '#' || tile == 'S' || tile == 'F') {
auto mapTile = fsCAppCoreMain::instanceGet()->entityFactoryGet()->entityConstruct(
"mapTile");
mParent->parentGet()->childAdd(mapTile);
mapTile->scaleSet(fsVec2d(0.5, 0.5));
mapTile->posSet(fsVec2d(j*20 - mOffset.x, i*20 + mOffset.y));
if (fsISpriteComponent* const sprComp = mapTile->spriteComponentGet()) {
if (tile == '#')
{
sprComp->brushSet(wallTileBrush);
}
else if (tile == 'S')
{
sprComp->brushSet(fsCBrushManager::instanceGet()->get(
fsCResourceName("gui/miniGameGui/wordSearch/smallTiles/s.png", fsCResourceName::eRES_LOCATION_ASSETS), false));
sprComp->colourSet(fsSColour(0.0,1.0,1.0,1.0));
}
else if (tile == 'F')
{
sprComp->brushSet(fsCBrushManager::instanceGet()->get(
fsCResourceName("gui/miniGameGui/wordSearch/smallTiles/f.png", fsCResourceName::eRES_LOCATION_ASSETS), false));
sprComp->colourSet(fsSColour(0.0,1.0,1.0,1.0));
}
}
}
}
}
mMe = fsCAppCoreMain::instanceGet()->entityFactoryGet()->
entityConstruct("gui/miniGameGui/wordSearch/smallTiles/x.png");
if (fsISpriteComponent* const sprComp = mMe->spriteComponentGet()) {
sprComp->brushSet(fsCBrushManager::instanceGet()->get(
fsCResourceName("gui/miniGameGui/wordSearch/smallTiles/o.png", fsCResourceName::eRES_LOCATION_ASSETS),false));
sprComp->colourSet(fsSColour(1.0,0.0,1.0,1.0));
}
mParent->parentGet()->childAdd(mMe);
mMe->scaleSet(fsVec2d(0.5, 0.5));
moveMe(fsVec2d(mParent->mCurrentCell.first,
mParent->mCurrentCell.second));
}
void gfCGeneratedHogSubSceneComponent::setWalls() {
std::vector<std::tuple<int, int, fsStr, fsStr> > walls = {
std::tuple<int, int, fsStr, fsStr>(0, -1, "MASK_TOP.png", "MASK_TOP2.png"),
std::tuple<int, int, fsStr, fsStr>(0, 1, "MASK_BOTTOM.png", "MASK_BOTTOM2.png"),
std::tuple<int, int, fsStr, fsStr>(-1, 0, "MASK_LEFT.png", "MASK_LEFT2.png"),
std::tuple<int, int, fsStr, fsStr>(1, 0, "MASK_RIGHT.png", "MASK_RIGHT2.png"),
};
if (auto* e = grandparentGet()->childFind("MASK_START.png")) e->visibleSet(false);
if (auto* e = grandparentGet()->childFind("MASK_FINISH.png")) e->visibleSet(false);
// Hide all wall variants
for (auto it = walls.begin(); it != walls.end(); ++it) {
if (auto wall = grandparentGet()->childFind(std::get<2>(*it))) {
wall->visibleSet(false);
}
if (auto wall2 = grandparentGet()->childFind(std::get<3>(*it))) {
wall2->visibleSet(false);
}
}
for (auto it = walls.begin(); it != walls.end(); ++it) {
auto test = std::pair<int,int>(mCurrentCell.first + std::get<0>(*it), mCurrentCell.second + std::get<1>(*it));
if (!mMaze->isValid(test.first, test.second) || mMaze->getCell(test.first, test.second) == ' ')
{
}
else if (mMaze->getCell(test.first, test.second) == 'S')
{
if (auto* e = grandparentGet()->childFind("MASK_START.png")) e->visibleSet(true);
}
else if (mMaze->getCell(test.first, test.second) == 'F')
{
if (auto* e = grandparentGet()->childFind("MASK_FINISH.png")) e->visibleSet(true);
}
else
{
// Randomly choose between wall and wall2
bool useWall2 = (rand() % 2) == 1;
fsStr wallTexture = useWall2 ? std::get<3>(*it) : std::get<2>(*it);
if (auto wall = grandparentGet()->childFind(wallTexture)) {
wall->visibleSet(true);
}
}
}
}
void gfCGeneratedHogSubSceneComponent::setColletables() {
std::vector<fsStr> entTypes = {"PCK"};
auto pickableEntities = fsCAppCoreMain::instanceGet()->
sceneRootGet()->childEntitiesTaggedWithGet(entTypes);
for (auto ent: pickableEntities) {
ent->visibleSet(rand() % 2 == 1);
}
}
void gfCGeneratedHogSubSceneComponent::sceneCreate() {
if (!grandparentGet()->childFind("MASK_START.png")) {
return;
}
setWalls();
setColletables();
}
void gfCGeneratedHogSubSceneComponent::listenersDeregisterDo()
{
gfCSubSceneComponent::listenersDeregisterDo();
fsCGuiMessageDispatcher::instanceGet()->listenerDeregister(fsCScreenFade::mFadeInCompleteMsg, this);
fsIInputManager::instanceGet()->listenerDeregister(fsIInputManager::mTypedCharMsg, this);
}
void gfCGeneratedHogSubSceneComponent::listenersRegisterDo()
{
gfCSubSceneComponent::listenersRegisterDo();
fsCGuiMessageDispatcher::instanceGet()->listenerRegister(fsCScreenFade::mFadeInCompleteMsg, this);
fsIInputManager::instanceGet()->listenerRegister(fsIInputManager::mTypedCharMsg, this);
}
fsBool gfCGeneratedHogSubSceneComponent::messageProcessDo(const fsCUniqueId& pMessageType,
const fsIMessageDispatcher::sMessageParameters& pParam)
{
if (pMessageType == fsCScreenFade::mFadeInCompleteMsg) {
sceneCreate();
mMap->create();
}
else if (pMessageType == fsIInputManager::mTypedCharMsg) {
auto key = static_cast<const fsIInputManager::sKeyboardMsgParam&>(pParam).mKey;
std::vector<std::tuple<int, int, int> > moves = {
std::tuple<int, int, int>(fsIInputManager::eKEY_CODE_CURSOR_UP, 0, -1),
std::tuple<int, int, int>(fsIInputManager::eKEY_CODE_CURSOR_DOWN, 0, 1),
std::tuple<int, int, int>(fsIInputManager::eKEY_CODE_CURSOR_LEFT, -1, 0),
std::tuple<int, int, int>(fsIInputManager::eKEY_CODE_CURSOR_RIGHT, 1, 0),
};
for (auto it = moves.begin(); it != moves.end(); ++it)
{
if (key == std::get<0>(*it))
{
if (mMaze->getCell(mCurrentCell.first + std::get<1>(*it), mCurrentCell.second + std::get<2>(*it)) == ' ')
{
mCurrentCell.first += std::get<1>(*it);
mCurrentCell.second += std::get<2>(*it);
sceneCreate();
mMap->moveMe(fsVec2d(mCurrentCell.first,
mCurrentCell.second));
}
}
}
}
return gfCSubSceneComponent::messageProcessDo(pMessageType, pParam);
}
fsIComponent* gfCGeneratedHogSubSceneComponent::create(fsCEntity* pParent)
{
auto* const subSceneComp = new gfCGeneratedHogSubSceneComponent(pParent);
const fsS32 inputType = fsIInputManager::instanceGet()->pointerTypeGet();
if (fsIInputManager::ePOINTER_TYPE_MULTI_TOUCH == inputType
|| fsIInputManager::ePOINTER_TYPE_SINGLE_TOUCH == inputType
|| gfCAutoTestManager::instanceGet()->active())
{
// Because a single hit point under your finger on a touch device just doesn't work,
// so we use another sprite to mark out the tip of your finger
subSceneComp->touchHitSpriteLoad();
}
return subSceneComp;
}
gfCGeneratedHogSubSceneComponent::gfCGeneratedHogSubSceneComponent(fsCEntity* const pParent) :
gfCSubSceneComponent(pParent)
{
mMaze = std::make_unique<gfCSimpleMazeComponent>(7 + rand() % 7,7 + rand() % 7);<--- Variable 'mMaze' is assigned in constructor body. Consider performing initialization in initialization list. [+]When an object of a class is created, the constructors of all member variables are called consecutively in the order the variables are declared, even if you don't explicitly write them to the initialization list. You could avoid assigning 'mMaze' a value by passing the value to the constructor in the initialization list.
mMap = std::make_unique<gfGeneratedHogSubSceneMap>(this);
mCurrentCell = mMaze->findCell('S');
mCurrentCell.second += 1;
mMaze->print();
}
gfCGeneratedHogSubSceneComponent::~gfCGeneratedHogSubSceneComponent()
{
}
|