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
|
#include <common.h>
#include <game.h>
const char *FlipBlockFileList[] = {"block_rotate", 0};
class daEnFlipBlock_c : public daEnBlockMain_c {
public:
Physics::Info physicsInfo;
int onCreate();
int onDelete();
int onExecute();
int onDraw();
void calledWhenUpMoveExecutes();
void calledWhenDownMoveExecutes();
void blockWasHit(bool isDown);
mHeapAllocator_c allocator;
nw4r::g3d::ResFile resFile;
m3d::mdl_c model;
int flipsRemaining;
USING_STATES(daEnFlipBlock_c);
DECLARE_STATE(Wait);
DECLARE_STATE(Flipping);
static daEnFlipBlock_c *build();
};
CREATE_STATE(daEnFlipBlock_c, Wait);
CREATE_STATE(daEnFlipBlock_c, Flipping);
int daEnFlipBlock_c::onCreate() {
allocator.link(-1, GameHeaps[0], 0, 0x20);
resFile.data = getResource("block_rotate", "g3d/block_rotate.brres");
model.setup(resFile.GetResMdl("block_rotate"), &allocator, 0, 1, 0);
SetupTextures_MapObj(&model, 0);
allocator.unlink();
blockInit(pos.y);
physicsInfo.x1 = -8;
physicsInfo.y1 = 8;
physicsInfo.x2 = 8;
physicsInfo.y2 = -8;
physicsInfo.otherCallback1 = &daEnBlockMain_c::OPhysicsCallback1;
physicsInfo.otherCallback2 = &daEnBlockMain_c::OPhysicsCallback2;
physicsInfo.otherCallback3 = &daEnBlockMain_c::OPhysicsCallback3;
physics.setup(this, &physicsInfo, 3, currentLayerID);
physics.flagsMaybe = 0x260;
physics.callback1 = &daEnBlockMain_c::PhysicsCallback1;
physics.callback2 = &daEnBlockMain_c::PhysicsCallback2;
physics.callback3 = &daEnBlockMain_c::PhysicsCallback3;
physics.addToList();
doStateChange(&daEnFlipBlock_c::StateID_Wait);
return true;
}
int daEnFlipBlock_c::onDelete() {
physics.removeFromList();
return true;
}
int daEnFlipBlock_c::onExecute() {
acState.execute();
physics.update();
blockUpdate();
// now check zone bounds based on state
if (acState.getCurrentState()->isEqual(&StateID_Wait)) {
checkZoneBoundaries(0);
}
return true;
}
int daEnFlipBlock_c::onDraw() {
matrix.translation(pos.x, pos.y, pos.z);
matrix.applyRotationYXZ(&rot.x, &rot.y, &rot.z);
model.setDrawMatrix(matrix);
model.setScale(&scale);
model.calcWorld(false);
model.scheduleForDrawing();
return true;
}
daEnFlipBlock_c *daEnFlipBlock_c::build() {
void *buffer = AllocFromGameHeap1(sizeof(daEnFlipBlock_c));
daEnFlipBlock_c *c = new(buffer) daEnFlipBlock_c;
return c;
}
void daEnFlipBlock_c::blockWasHit(bool isDown) {
pos.y = initialY;
doStateChange(&StateID_Flipping);
}
void daEnFlipBlock_c::calledWhenUpMoveExecutes() {
if (initialY >= pos.y)
blockWasHit(false);
}
void daEnFlipBlock_c::calledWhenDownMoveExecutes() {
if (initialY <= pos.y)
blockWasHit(true);
}
void daEnFlipBlock_c::beginState_Wait() {
}
void daEnFlipBlock_c::endState_Wait() {
}
void daEnFlipBlock_c::executeState_Wait() {
int result = blockResult();
if (result == 0)
return;
if (result == 1) {
doStateChange(&daEnBlockMain_c::StateID_UpMove);
anotherFlag = 2;
isGroundPound = false;
} else {
doStateChange(&daEnBlockMain_c::StateID_DownMove);
anotherFlag = 1;
isGroundPound = true;
}
}
void daEnFlipBlock_c::beginState_Flipping() {
flipsRemaining = 7;
physics.removeFromList();
}
void daEnFlipBlock_c::executeState_Flipping() {
if (isGroundPound)
rot.x += 0x800;
else
rot.x -= 0x800;
if (rot.x == 0) {
flipsRemaining--;
if (flipsRemaining <= 0) {
doStateChange(&StateID_Wait);
}
}
}
void daEnFlipBlock_c::endState_Flipping() {
physics.setup(this, &physicsInfo, 3, currentLayerID);
physics.addToList();
}
|