summaryrefslogtreecommitdiff
path: root/src/bossWrenchThrow.cpp
blob: 1abc226719dd9601268fab0bb78f572f628c2293 (plain)
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
#include <common.h>
#include <game.h>
#include <g3dhax.h>
#include "player.h"
#include "effects.h"
#include <sfx.h>


class daWrench : public dEn_c {
	int onCreate();
	int onExecute();
	int onDelete();
	int onDraw();

	mHeapAllocator_c allocator;
	m3d::mdl_c bodyModel;

	int timer;
	char Kaboom;
	char direction;
	char front;
	float ymod;
	int lifespan;
	u32 cmgr_returnValue;

	static daWrench *build();

	void updateModelMatrices();
	void playerCollision(ActivePhysics *apThis, ActivePhysics *apOther);

	void collisionCat1_Fireball_E_Explosion(ActivePhysics *apThis, ActivePhysics *apOther);
	bool collisionCat2_IceBall_15_YoshiIce(ActivePhysics *apThis, ActivePhysics *apOther);
	void collisionCat9_RollingObject(ActivePhysics *apThis, ActivePhysics *apOther);
	void collisionCat13_Hammer(ActivePhysics *apThis, ActivePhysics *apOther);
	void collisionCat14_YoshiFire(ActivePhysics *apThis, ActivePhysics *apOther);
	void collisionCat7_WMWaggleWater(ActivePhysics *apThis, ActivePhysics *apOther);


	USING_STATES(daWrench);
	DECLARE_STATE(Straight);
	DECLARE_STATE(Kaboom);

};

CREATE_STATE(daWrench, Straight);
CREATE_STATE(daWrench, Kaboom);


extern "C" void *PlaySound(dEn_c *, int soundID);
extern "C" void *PlaySoundAsync(dEn_c *, int soundID);
extern "C" void *PlayWrenchSound(dEn_c *);
extern "C" dStageActor_c *GetSpecificPlayerActor(int number);
extern "C" u32 GenerateRandomNumber(int max);


void daWrench::playerCollision(ActivePhysics *apThis, ActivePhysics *apOther) { 

	this->dEn_c::playerCollision(apThis, apOther);
	this->_vf220(apOther->owner);

	this->isDead = 0;
	this->flags_4FC |= (1<<(31-7));
	if(apOther->owner->which_player < 4) {
		this->counter_504[apOther->owner->which_player] = 0;
	}
}

void daWrench::collisionCat1_Fireball_E_Explosion(ActivePhysics *apThis, ActivePhysics *apOther) { }
bool daWrench::collisionCat2_IceBall_15_YoshiIce(ActivePhysics *apThis, ActivePhysics *apOther) { 
	return false; 
}
void daWrench::collisionCat9_RollingObject(ActivePhysics *apThis, ActivePhysics *apOther) {}
void daWrench::collisionCat13_Hammer(ActivePhysics *apThis, ActivePhysics *apOther) {
	CreateEffect(&this->pos, &(S16Vec){0,0,0}, &(Vec){0.5, 0.5, 0.5}, 48); 

	PlaySoundAsync(this, SE_BOSS_JR_FLOOR_BREAK);
	this->Delete(1);
}
void daWrench::collisionCat14_YoshiFire(ActivePhysics *apThis, ActivePhysics *apOther) {}
void daWrench::collisionCat7_WMWaggleWater(ActivePhysics *apThis, ActivePhysics *apOther) { 
	this->_vf220(apOther->owner);

	CreateEffect(&this->pos, &(S16Vec){0,0,0}, &(Vec){0.5, 0.5, 0.5}, 48); 

	PlaySoundAsync(this, SE_BOSS_JR_FLOOR_BREAK);
	this->Delete(1);
}



daWrench *daWrench::build() {
	void *buffer = AllocFromGameHeap1(sizeof(daWrench));
	return new(buffer) daWrench;
}


int daWrench::onCreate() {
	
	allocator.link(-1, GameHeaps[0], 0, 0x20);

	nw4r::g3d::ResFile rf(getResource("choropoo", "g3d/choropoo.brres"));
	bodyModel.setup(rf.GetResMdl("spanner"), &allocator, 0x224, 1, 0);
	SetupTextures_Enemy(&bodyModel, 0);

	allocator.unlink();
	
	
	this->direction = this->settings & 0xF;
	this->Kaboom = (this->settings >> 4) & 0xF;
	this->front = (this->settings >> 8) & 0xF;
	
	ActivePhysics::Info HitMeBaby;
	
	if (this->Kaboom == 0) {
		HitMeBaby.xDistToCenter = 0.0;
		HitMeBaby.yDistToCenter = 0.0;
		HitMeBaby.xDistToEdge = 5.0;
		HitMeBaby.yDistToEdge = 5.0;
	
		this->scale.x = 1.25;
		this->scale.y = 1.25;
		this->scale.z = 1.25;
	}
	
	else {
		HitMeBaby.xDistToCenter = 0.0;
		HitMeBaby.yDistToCenter = 0.0;
		HitMeBaby.xDistToEdge = 8.0;
		HitMeBaby.yDistToEdge = 8.0;
	
		this->scale.x = 2.0;
		this->scale.y = 2.0;
		this->scale.z = 2.0;
	}
	
	HitMeBaby.category1 = 0x3;
	HitMeBaby.category2 = 0x0;
	HitMeBaby.bitfield1 = 0x47;
	HitMeBaby.bitfield2 = 0xFFFFFFFF;
	HitMeBaby.unkShort1C = 0;
	HitMeBaby.callback = &dEn_c::collisionCallback;

	this->aPhysics.initWithStruct(this, &HitMeBaby);
	this->aPhysics.addToList();


	spriteSomeRectX = 5.0f;
	spriteSomeRectY = 5.0f;
	_320 = 0.0f;
	_324 = 5.0f;

	// These structs tell stupid collider what to collide with - these are from koopa troopa
	static const u8 one[16] = {0,0,0,1, 0,0,0xC0,0, 0,0,0x40,0, 0,0,0,0};
	static const u8 two[12] = {0,0,0,0, 0,0,0,0, 0,0,0xC0,0};
	static const u8 three[16] = {0,0,0,1, 0,0,0x60,0, 0,0,0x90,0, 0,0,0x60,0};

	collMgr.Init(this, one, two, three);
	collMgr.execute();

	cmgr_returnValue = collMgr.CollidedWithTile();


	if (this->direction == 0) 	   { // Ground Facing Left
		this->pos.x -= 0.0; // -32 to +32
		this->pos.y += 36.0;
		this->rot.z = 0x2000;
	}
	else if (this->direction == 1) { // Ground Facing Right
		this->pos.x += 0.0; // +32 to -32
		this->pos.y += 36.0;
		this->rot.z = 0xE000;
	}
	if (this->front == 1) { this->pos.z = -1804.0; }
	else 				  { this->pos.z =  3300.0; }

	
	if (this->Kaboom) {
		doStateChange(&StateID_Kaboom); }
	else {
		doStateChange(&StateID_Straight); }
	
	this->onExecute();
	return true;
}


int daWrench::onDelete() {
	return true;
}

int daWrench::onDraw() {
	bodyModel.scheduleForDrawing();
	return true;
}


void daWrench::updateModelMatrices() {
	matrix.translation(pos.x, pos.y, pos.z);
	matrix.applyRotationYXZ(&rot.x, &rot.y, &rot.z);

	bodyModel.setDrawMatrix(matrix);
	bodyModel.setScale(&scale);
	bodyModel.calcWorld(false);
}


int daWrench::onExecute() {
	acState.execute();
	updateModelMatrices();

	return true;
}


void daWrench::beginState_Kaboom() { 
	float rand = (float)GenerateRandomNumber(10) * 0.4;

	if (this->direction == 0) { // directions 1 spins clockwise, fly rightwards
		speed.x = 1.0 + rand; 
	}
	else {						// directions 0 spins anti-clockwise, fly leftwards
		speed.x = -1.0 - rand; 
	}

	speed.y = 6.0;
}
void daWrench::executeState_Kaboom() { 

	speed.y = speed.y - 0.01875;

	HandleXSpeed();
	HandleYSpeed();
	doSpriteMovement();

	cmgr_returnValue = collMgr.CollidedWithTile();
	collMgr.execute();

	if (collMgr.CollidedWithTile()) {
		// hit the ground
		PlaySoundAsync(this, SE_BOSS_JR_BOMB_BURST);

			CreateEffect(&this->pos, &(S16Vec){0,0,0}, &(Vec){0.75, 0.75, 0.75}, 9);
			CreateEffect(&this->pos, &(S16Vec){0,0,0}, &(Vec){1.25, 1.25, 1.25}, 167);
		this->Delete(1);
	}
	if (collMgr.bitfield_for_checks & (0x15 << direction)) {
		// hit the wall
		PlaySoundAsync(this, SE_BOSS_JR_BOMB_BURST);
 
		if (this->direction == 0) { // directions 1 spins clockwise, fly rightwards
			CreateEffect(&this->pos, &(S16Vec){0,0x4000,0}, &(Vec){0.75, 0.75, 0.75}, 9);
			CreateEffect(&this->pos, &(S16Vec){0,0x4000,0}, &(Vec){1.25, 1.25, 1.25}, 167);
		}
		else {						// directions 0 spins anti-clockwise, fly leftwards
			CreateEffect(&this->pos, &(S16Vec){0,0xE000,0}, &(Vec){0.75, 0.75, 0.75}, 9);
			CreateEffect(&this->pos, &(S16Vec){0,0xE000,0}, &(Vec){1.25, 1.25, 1.25}, 167);
		}

		this->Delete(1);
	}

	if (this->direction == 1) { // directions 1 spins clockwise, fly rightwards
		this->rot.z -= 0x1000; }
	else {						// directions 0 spins anti-clockwise, fly leftwards
		this->rot.z += 0x1000; }	
	
	PlayWrenchSound(this);

}
void daWrench::endState_Kaboom() { }



void daWrench::beginState_Straight() { 
	float rand = (float)GenerateRandomNumber(10) * 0.4;

	if (this->direction == 0) { // directions 1 spins clockwise, fly rightwards
		speed.x = 1.0 + rand; 
	}
	else {						// directions 0 spins anti-clockwise, fly leftwards
		speed.x = -1.0 - rand; 
	}

	speed.y = 6.0;
}
void daWrench::executeState_Straight() { 

	speed.y = speed.y - 0.01875;

	HandleXSpeed();
	HandleYSpeed();
	doSpriteMovement();

	cmgr_returnValue = collMgr.CollidedWithTile();
	collMgr.execute();

	if (collMgr.CollidedWithTile()) {
		// hit the ground
		PlaySoundAsync(this, SE_BOSS_JR_FLOOR_BREAK);

		CreateEffect(&this->pos, &(S16Vec){0,0,0}, &(Vec){0.75, 0.75, 0.75}, 9);
		this->Delete(1);
	}
	if (collMgr.bitfield_for_checks & (0x15 << direction)) {
		// hit the wall
		PlaySoundAsync(this, SE_BOSS_JR_FLOOR_BREAK);

		CreateEffect(&this->pos, &(S16Vec){0,0,0}, &(Vec){0.75, 0.75, 0.75}, 9);
		this->Delete(1);
	}

	if (this->direction == 1) { // directions 1 spins clockwise, fly rightwards
		this->rot.z -= 0x1000; }
	else {						// directions 0 spins anti-clockwise, fly leftwards
		this->rot.z += 0x1000; }	
	
	PlayWrenchSound(this);

}
void daWrench::endState_Straight() { }