summaryrefslogtreecommitdiff
path: root/src/bossTopman.cpp
blob: 95aeefb18e1e12a3623868d12a2d6ee0baeb0edd (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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
#include <common.h>
#include <game.h>
#include <g3dhax.h>
#include <sfx.h>
#include <stage.h>
#include "boss.h"

class daDreidel : public daBoss {
public:
	int onCreate();
	int onDelete();
	int onExecute();
	int onDraw();

	mHeapAllocator_c allocator;
	nw4r::g3d::ResFile resFile;

	m3d::mdl_c bodyModel;

	m3d::anmChr_c chrAnimation;

	char isDown;
	float XSpeed;
	u32 cmgr_returnValue;
	bool isBouncing;
	char isInSpace;
	char fromBehind;
	char isInvulnerable;
	int isInvulnerableCountdown;
	int isTurningCountdown;
	char charging;
	int flashing;

	float dying;

	static daDreidel *build();

	void bindAnimChr_and_setUpdateRate(const char* name, int unk, float unk2, float rate);
	void updateModelMatrices();
	bool calculateTileCollisions();

	void spriteCollision(ActivePhysics *apThis, ActivePhysics *apOther);
	void playerCollision(ActivePhysics *apThis, ActivePhysics *apOther);
	void yoshiCollision(ActivePhysics *apThis, ActivePhysics *apOther);

	void collisionCat3_StarPower(ActivePhysics *apThis, ActivePhysics *apOther);
	void collisionCat14_YoshiFire(ActivePhysics *apThis, ActivePhysics *apOther);
	void collisionCatD_GroundPound(ActivePhysics *apThis, ActivePhysics *apOther);
	void collisionCat7_GroundPound(ActivePhysics *apThis, ActivePhysics *apOther);
	void collisionCat7_GroundPoundYoshi(ActivePhysics *apThis, ActivePhysics *apOther);
	void collisionCat9_RollingObject(ActivePhysics *apThis, ActivePhysics *apOther);
	void collisionCat1_Fireball_E_Explosion(ActivePhysics *apThis, ActivePhysics *apOther);
	bool collisionCat2_IceBall_15_YoshiIce(ActivePhysics *apThis, ActivePhysics *apOther);
	void collisionCat13_Hammer(ActivePhysics *apThis, ActivePhysics *apOther);
	void collisionCatA_PenguinMario(ActivePhysics *apThis, ActivePhysics *apOther);

	void addScoreWhenHit(void *other);

	USING_STATES(daDreidel);
	DECLARE_STATE(Walk);
	DECLARE_STATE(Turn);
	DECLARE_STATE(KnockBack);

	DECLARE_STATE(ChargePrep);
	DECLARE_STATE(Charge);
	DECLARE_STATE(ChargeRecover);
	DECLARE_STATE(Damage);

	DECLARE_STATE(Grow);
	DECLARE_STATE(Outro);

};

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

///////////////////////
// Externs and States
///////////////////////
	extern "C" void *EN_LandbarrelPlayerCollision(dEn_c* t, ActivePhysics *apThis, ActivePhysics *apOther);
	// CalculateDistanceFromActorsNextPosToFurthestPlayer???
	extern "C" int SmoothRotation(short* rot, u16 amt, int unk2);


	CREATE_STATE(daDreidel, Walk);
	CREATE_STATE(daDreidel, Turn);
	CREATE_STATE(daDreidel, KnockBack);

	CREATE_STATE(daDreidel, ChargePrep);
	CREATE_STATE(daDreidel, Charge);
	CREATE_STATE(daDreidel, ChargeRecover);
	CREATE_STATE(daDreidel, Damage);

	CREATE_STATE(daDreidel, Grow);
	CREATE_STATE(daDreidel, Outro);

	// 	begoman_attack2"	// wobble back and forth tilted forwards
	// 	begoman_attack3"	// Leaned forward, antennae extended
	// 	begoman_damage"		// Bounces back slightly
	// 	begoman_damage2"	// Stops spinning and wobbles to the ground like a top
	// 	begoman_stand"		// Stands still, waiting
	// 	begoman_wait"		// Dizzily Wobbles
	// 	begoman_wait2"		// spins around just slightly
	// 	begoman_attack"		// Rocks backwards, and then attacks to an upright position, pulsing out his antennae


////////////////////////
// Collision Functions
////////////////////////
	// void topCollisionCallback(ActivePhysics *apThis, ActivePhysics *apOther);

	// void topCollisionCallback(ActivePhysics *apThis, ActivePhysics *apOther) {
	// 	OSReport("Collided with %d", apOther->owner->name);
	// 	if (apOther->owner->name != 041) { 
	// 		dEn_c::collisionCallback(apThis, apOther); 
	// 	}
	// 	else {
	// 		daDreidel *actor = (daDreidel*)apThis->owner;
	// 		actor->damage += 1;
	// 		actor->doStateChange(&daDreidel::StateID_Damage);

	// 		if (actor->damage > 2) { actor->doStateChange(&daDreidel::StateID_Outro); }
	// 	}
	// }
	void daDreidel::addScoreWhenHit(void *other) { };

	void daDreidel::spriteCollision(ActivePhysics *apThis, ActivePhysics *apOther) {
		if (apOther->owner->name == 390) { //time to get hurt
			if (this->isInvulnerable) {
				return;
			}
			this->damage += 1;
			doStateChange(&StateID_Damage);

			if (this->damage = 3) { doStateChange(&StateID_Outro); }
		}
		else { dEn_c::spriteCollision(apThis, apOther); }
	}

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


		char hitType;
		hitType = usedForDeterminingStatePress_or_playerCollision(this, apThis, apOther, 0);

		if(hitType == 1) {	// regular jump
			this->_vf220(apOther->owner);
			this->counter_504[apOther->owner->which_player] = 0;
		} 
		else if(hitType == 3) {	// spinning jump or whatever?
			this->_vf220(apOther->owner);
			this->counter_504[apOther->owner->which_player] = 0;
		} 
		else if(hitType == 0) {

			if (this->charging == 1) {

				char MarioPos;

				if (this->pos.x < apOther->owner->pos.x) { MarioPos = 0; } // Mario is to the right
				else 									 { MarioPos = 1; } // Mario is to the left
				

				if (this->direction != MarioPos) {	// Mario is stnading behind the boss
					EN_LandbarrelPlayerCollision(this, apThis, apOther);
					if (MarioPos == 1)  { this->direction = 1; }
					else 				{ this->direction = 0; }

					doStateChange(&StateID_KnockBack);
				}

				else { // Mario is standing in front of the boss
					this->_vf220(apOther->owner);
					EN_LandbarrelPlayerCollision(this, apThis, apOther);
				}
			}

			else if (this->isInvulnerable == 0) { 

				if (this->pos.x > apOther->owner->pos.x) {
					this->direction = 1;
				}
				else {
					this->direction = 0;
				}
			
				this->counter_504[apOther->owner->which_player] = 0;
				EN_LandbarrelPlayerCollision(this, apThis, apOther);
				doStateChange(&StateID_KnockBack);
			}
			else {
				this->counter_504[apOther->owner->which_player] = 0;
				EN_LandbarrelPlayerCollision(this, apThis, apOther);
			}
		} 

		deathInfo.isDead = 0;
		this->flags_4FC |= (1<<(31-7));
	}

	void daDreidel::yoshiCollision(ActivePhysics *apThis, ActivePhysics *apOther) {
		this->playerCollision(apThis, apOther);
	}

	void daDreidel::collisionCatD_GroundPound(ActivePhysics *apThis, ActivePhysics *apOther) { DamagePlayer(this, apThis, apOther); }
	void daDreidel::collisionCat7_GroundPound(ActivePhysics *apThis, ActivePhysics *apOther) { DamagePlayer(this, apThis, apOther); }
	void daDreidel::collisionCat7_GroundPoundYoshi(ActivePhysics *apThis, ActivePhysics *apOther) { DamagePlayer(this, apThis, apOther); }

	void daDreidel::collisionCat9_RollingObject(ActivePhysics *apThis, ActivePhysics *apOther) { 
		if (this->isInvulnerable == 0) { 
			doStateChange(&StateID_KnockBack);
		}
	}
	void daDreidel::collisionCatA_PenguinMario(ActivePhysics *apThis, ActivePhysics *apOther){ 
		if (this->isInvulnerable == 0) { 
			doStateChange(&StateID_KnockBack);
		}
	}


	void daDreidel::collisionCat3_StarPower(ActivePhysics *apThis, ActivePhysics *apOther){	}
	void daDreidel::collisionCat13_Hammer(ActivePhysics *apThis, ActivePhysics *apOther) { }
	void daDreidel::collisionCat14_YoshiFire(ActivePhysics *apThis, ActivePhysics *apOther){ }
	void daDreidel::collisionCat1_Fireball_E_Explosion(ActivePhysics *apThis, ActivePhysics *apOther) { }
	bool daDreidel::collisionCat2_IceBall_15_YoshiIce(ActivePhysics *apThis, ActivePhysics *apOther) { return true; }


bool daDreidel::calculateTileCollisions() {
	// Returns true if sprite should turn, false if not.

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

	cmgr_returnValue = collMgr.isOnTopOfTile();
	collMgr.calculateBelowCollisionWithSmokeEffect();

	if (isBouncing) {
		stuffRelatingToCollisions(0.1875f, 1.0f, 0.5f);
		if (speed.y != 0.0f)
			isBouncing = false;
	}

	float xDelta = pos.x - last_pos.x;
	if (xDelta >= 0.0f)
		direction = 0;
	else
		direction = 1;

	if (collMgr.isOnTopOfTile()) {
		// Walking into a tile branch

		if (cmgr_returnValue == 0)
			isBouncing = true;

		if (speed.x != 0.0f) {
			//playWmEnIronEffect();
		}

		speed.y = 0.0f;

		// u32 blah = collMgr.s_80070760();
		// u8 one = (blah & 0xFF);
		// static const float incs[5] = {0.00390625f, 0.0078125f, 0.015625f, 0.0234375f, 0.03125f};
		// x_speed_inc = incs[one];
		max_speed.x = (direction == 1) ? -1.0f : 1.0f;
	} else {
		x_speed_inc = 0.0f;
	}

	// Bouncing checks
	if (_34A & 4) {
		Vec v = (Vec){0.0f, 1.0f, 0.0f};
		collMgr.pSpeed = &v;

		if (collMgr.calculateAboveCollision(collMgr.outputMaybe))
			speed.y = 0.0f;

		collMgr.pSpeed = &speed;

	} else {
		if (collMgr.calculateAboveCollision(collMgr.outputMaybe))
			speed.y = 0.0f;
	}

	collMgr.calculateAdjacentCollision(0);

	// Switch Direction
	if (collMgr.outputMaybe & (0x15 << direction)) {
		if (collMgr.isOnTopOfTile()) {
			isBouncing = true;
		}
		return true;
	}
	return false;
}

void daDreidel::bindAnimChr_and_setUpdateRate(const char* name, int unk, float unk2, float rate) {
	nw4r::g3d::ResAnmChr anmChr = this->resFile.GetResAnmChr(name);
	this->chrAnimation.bind(&this->bodyModel, anmChr, unk);
	this->bodyModel.bindAnim(&this->chrAnimation, unk2);
	this->chrAnimation.setUpdateRate(rate);
}

int daDreidel::onCreate() {
	
	// Model creation	
	allocator.link(-1, GameHeaps[0], 0, 0x20);

	this->resFile.data = getResource("topman", "g3d/begoman_spike.brres");
	nw4r::g3d::ResMdl mdl = this->resFile.GetResMdl("begoman");
	bodyModel.setup(mdl, &allocator, 0x224, 1, 0);
	SetupTextures_Map(&bodyModel, 0);


	// Animations start here
	nw4r::g3d::ResAnmChr anmChr = this->resFile.GetResAnmChr("begoman_wait");
	this->chrAnimation.setup(mdl, anmChr, &this->allocator, 0);

	allocator.unlink();

	// Stuff I do understand
	this->scale = (Vec){0.2, 0.2, 0.2};

	// this->pos.y = this->pos.y + 30.0; // X is vertical axis
	this->rot.x = 0; // X is vertical axis
	this->rot.y = 0xD800; // Y is horizontal axis
	this->rot.z = 0; // Z is ... an axis >.>
	this->direction = 1; // Heading left.
	
	this->speed.x = 0.0;
	this->speed.y = 0.0;
	this->max_speed.x = 1.1;
	this->x_speed_inc = 0.0;
	this->XSpeed = 1.1;

	this->isInSpace = this->settings & 0xF;
	this->fromBehind = 0;
	this->flashing = 0; 


	ActivePhysics::Info HitMeBaby;

	HitMeBaby.xDistToCenter = 0.0;
	HitMeBaby.yDistToCenter = 24.0;

	HitMeBaby.xDistToEdge = 28.0;
	HitMeBaby.yDistToEdge = 24.0;		

	HitMeBaby.category1 = 0x3;
	HitMeBaby.category2 = 0x0;
	HitMeBaby.bitfield1 = 0x4F;
	HitMeBaby.bitfield2 = 0xffbafffe;
	HitMeBaby.unkShort1C = 0;
	HitMeBaby.callback = &dEn_c::collisionCallback;

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


	// Tile collider

	// These fucking rects do something for the tile rect
	spriteSomeRectX = 28.0f;
	spriteSomeRectY = 32.0f;
	_320 = 0.0f;
	_324 = 16.0f;

	// These structs tell stupid collider what to collide with - these are from koopa troopa
	static const lineSensor_s below(12<<12, 4<<12, 0<<12);
	static const pointSensor_s above(0<<12, 12<<12);
	static const lineSensor_s adjacent(6<<12, 9<<12, 6<<12);

	collMgr.init(this, &below, &above, &adjacent);
	collMgr.calculateBelowCollisionWithSmokeEffect();

	cmgr_returnValue = collMgr.isOnTopOfTile();

	if (collMgr.isOnTopOfTile())
		isBouncing = false;
	else
		isBouncing = true;


	// State Changers
	bindAnimChr_and_setUpdateRate("begoman_wait2", 1, 0.0, 1.0); 
	doStateChange(&StateID_Grow);

	this->onExecute();
	return true;
}

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

int daDreidel::onExecute() {
	acState.execute();
	updateModelMatrices();
	
	return true;
}

int daDreidel::onDraw() {

	if (this->isInvulnerable == 1) {
		this->flashing++;
	}

	if (this->flashing < 5) {
		bodyModel.scheduleForDrawing();
	}

	bodyModel._vf1C();

	if (this->flashing > 8) { this->flashing = 0; }

	return true;
}

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

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



///////////////
// Grow State
///////////////
	void daDreidel::beginState_Grow() { 
		bindAnimChr_and_setUpdateRate("begoman_wait2", 1, 0.0, 0.75); 

		this->timer = 0;

		SetupKameck(this, Kameck);
	}

	void daDreidel::executeState_Grow() { 
		
		if(this->chrAnimation.isAnimationDone()) {
			this->chrAnimation.setCurrentFrame(0.0);
		}

		this->timer += 1;
		
		bool ret;
		ret = GrowBoss(this, Kameck, 0.2, 0.4, 0, this->timer);

		if (ret) { 	
			PlaySound(this, SE_EMY_MECHAKOOPA_BOUND);
			doStateChange(&StateID_Walk); 
		}
	}
	void daDreidel::endState_Grow() { 
		this->chrAnimation.setUpdateRate(1.0);
		CleanupKameck(this, Kameck);
	}


///////////////
// Walk State
///////////////
	void daDreidel::beginState_Walk() {
		this->max_speed.x = (this->direction) ? -this->XSpeed : this->XSpeed;
		this->speed.x = (direction) ? -1.2f : 1.2f;

		this->max_speed.y = (this->isInSpace) ? -2.0 : -4.0;
		this->speed.y = 	(this->isInSpace) ? -2.0 : -4.0;
		this->y_speed_inc = (this->isInSpace) ? -0.09375 : -0.1875;

		this->isTurningCountdown = 0;
	}
	void daDreidel::executeState_Walk() { 

		if (this->isInvulnerableCountdown > 0) {
			this->isInvulnerableCountdown--;
		}
		else {
			this->isInvulnerable = 0;
			this->flashing = 0;
		}

		PlaySound(this, SE_BOSS_JR_CROWN_JR_RIDE); // 5
	
		bool ret = calculateTileCollisions();
		if (ret) {
			doStateChange(&StateID_Turn);
		}

		u8 dir = dSprite_c__getXDirectionOfFurthestPlayerRelativeToVEC3(this, this->pos);
		if (dir != this->direction) {
			this->isTurningCountdown++;
		}

		if (this->isTurningCountdown > 60) { doStateChange(&StateID_Turn); }

		if(this->chrAnimation.isAnimationDone()) {
			this->chrAnimation.setCurrentFrame(0.0);
		}
	}
	void daDreidel::endState_Walk() { this->timer += 1; }


///////////////
// Turn State
///////////////
	void daDreidel::beginState_Turn() {
		this->direction ^= 1;
		this->speed.x = 0.0;
	}
	void daDreidel::executeState_Turn() { 

		if(this->chrAnimation.isAnimationDone()) {
			this->chrAnimation.setCurrentFrame(0.0);
		}

		u16 amt = (this->direction == 0) ? 0x2800 : 0xD800;
		int done = SmoothRotation(&this->rot.y, amt, 0x800);

		if(done) {
			if (this->damage > 1) 	{ doStateChange(&StateID_ChargePrep); }
			else 					{ doStateChange(&StateID_Walk); }
		}
	}
	void daDreidel::endState_Turn() { this->rot.y = (this->direction) ? 0xD800 : 0x2800; }


///////////////
// Knockback State
///////////////
	void daDreidel::beginState_KnockBack() {
		bindAnimChr_and_setUpdateRate("begoman_damage", 1, 0.0, 0.65); 

		this->max_speed.x = (this->direction) ? 6.5f : -6.5f;
		this->speed.x = (this->direction) ? 6.5f : -6.5f;
	}
	void daDreidel::executeState_KnockBack() { 

		bool ret = calculateTileCollisions();
		if (ret) {
			this->max_speed.x = -this->max_speed.x;
			this->speed.x = -this->speed.x;
		}
		this->speed.x = this->speed.x / 1.08;

		bodyModel._vf1C();
		if(this->chrAnimation.isAnimationDone()) {
			if (this->damage > 1) 	{ doStateChange(&StateID_ChargePrep); }
			else 					{ doStateChange(&StateID_Walk); }
		}

	}
	void daDreidel::endState_KnockBack() { 
		if (this->rot.y == 0x2800) {
			// CreateEffect(&this->pos, &(S16Vec){0,0,0}, &(Vec){1.0, 1.0, 1.0}, 175);
			this->direction = 0; 
		}
		else {
			// CreateEffect(&this->pos, &(S16Vec){0,0,0}, &(Vec){1.0, 1.0, 1.0}, 192);
			this->direction = 1; 
		}
		// this->direction ^= 1;
		bindAnimChr_and_setUpdateRate("begoman_wait2", 1, 0.0, 1.0); 
	}


///////////////
// ChargePrep State
///////////////
	void daDreidel::beginState_ChargePrep() {
		bindAnimChr_and_setUpdateRate("begoman_attack", 1, 0.0, 0.9); 
	}
	void daDreidel::executeState_ChargePrep() { 
		if(this->chrAnimation.isAnimationDone()) {
			doStateChange(&StateID_Charge);
		}
	}
	void daDreidel::endState_ChargePrep() { }


///////////////
// Charge State
///////////////
	void daDreidel::beginState_Charge() {
		bindAnimChr_and_setUpdateRate("begoman_attack3", 1, 0.0, 1.0); 
		this->timer = 0;
		this->isTurningCountdown = 0;

		this->max_speed.x = (this->direction) ? -this->XSpeed : this->XSpeed;
		this->speed.x = (direction) ? -2.6f : 2.6f;

		this->max_speed.y = (this->isInSpace) ? -2.0 : -4.0;
		this->speed.y = 	(this->isInSpace) ? -2.0 : -4.0;
		this->y_speed_inc = (this->isInSpace) ? -0.09375 : -0.1875;

		this->charging = 1;
	}
	void daDreidel::executeState_Charge() { 

		if (this->isInvulnerableCountdown > 0) {
			this->isInvulnerableCountdown--;
		}
		else {
			this->isInvulnerable = 0;
			this->flashing = 0;
		}

		if(this->chrAnimation.isAnimationDone()) {
			this->chrAnimation.setCurrentFrame(0.0);
		}

		bool ret = calculateTileCollisions();
		if (ret) {
			doStateChange(&StateID_ChargeRecover);
		}

		u8 dir = dSprite_c__getXDirectionOfFurthestPlayerRelativeToVEC3(this, this->pos);
		if (dir != this->direction) {
			this->isTurningCountdown++;
			this->speed.x = this->speed.x / 1.04;
		}

		if (this->isTurningCountdown > 90) { doStateChange(&StateID_Turn); }
	}
	void daDreidel::endState_Charge() { 
		this->charging = 0; 

		this->counter_504[0] = 0;
		this->counter_504[1] = 0;
		this->counter_504[2] = 0;
		this->counter_504[3] = 0;
	}


///////////////
// ChargeRecover State
///////////////
	void daDreidel::beginState_ChargeRecover() {
		bindAnimChr_and_setUpdateRate("begoman_stand", 1, 0.0, 0.5); 
	}
	void daDreidel::executeState_ChargeRecover() { 
		if(this->chrAnimation.isAnimationDone()) {
			doStateChange(&StateID_Turn);
		}
	}
	void daDreidel::endState_ChargeRecover() { }


///////////////
// Damage State
///////////////
	void daDreidel::beginState_Damage() {
		this->isInvulnerable = 1;
		bindAnimChr_and_setUpdateRate("begoman_wait", 1, 0.0, 0.75); 
		this->timer = 0;

		PlaySound(this, SE_PLY_TOUCH_BIRI);
		PlaySound(this, SE_BOSS_JR_ELEC_SPARK);
		PlaySound(this, SE_EMY_BIRIKYU_SPARK);

		Vec front = {this->pos.x-4.0, this->pos.y+8.0, 5500.0};
		Vec back = {this->pos.x-4.0, this->pos.y+8.0, -5500.0};

		SpawnEffect("Wm_ob_cmnspark", 0, &front, 0, &(Vec){2.5, 2.5, 1.5});
		SpawnEffect("Wm_mr_wirehit_line", 0, &front, 0, &(Vec){1.5, 1.5, 1.5});
		SpawnEffect("Wm_mr_kick_grain", 0, &front, 0, &(Vec){1.5, 1.5, 1.5});
		SpawnEffect("Wm_mr_wirehit_glow", 0, &back, 0, &(Vec){2.5, 2.5, 2.5});
	}
	void daDreidel::executeState_Damage() { 

		if(this->chrAnimation.isAnimationDone()) {
			this->timer += 1;
			if (this->timer == 1) {

				u8 dir = dSprite_c__getXDirectionOfFurthestPlayerRelativeToVEC3(this, this->pos);
				if (dir != this->direction) {
					doStateChange(&StateID_Turn);
				}
				else {
					if (this->damage > 1) 	{ doStateChange(&StateID_ChargePrep); }
					else 					{ doStateChange(&StateID_Walk); }
				}
			}
			else {
			}
			this->chrAnimation.setCurrentFrame(0.0);
		}
	}
	void daDreidel::endState_Damage() { 
		bindAnimChr_and_setUpdateRate("begoman_wait2", 1, 0.0, 1.0); 
		this->isInvulnerableCountdown = 90; 
	}


///////////////
// Outro State
///////////////
	void daDreidel::beginState_Outro() { 
		OutroSetup(this);
	}
	void daDreidel::executeState_Outro() {

		if (this->dying == 1) { 
			if (this->timer > 180) { ExitStage(WORLD_MAP, 0, BEAT_LEVEL, MARIO_WIPE); }
			if (this->timer == 60) { PlayerVictoryCries(this); }	
			
			this->timer += 1;
			return; 
		}	

		bool ret;
		ret = ShrinkBoss(this, &this->pos, 0.5, this->timer);

		if (ret == true) 	{ 
			BossExplode(this, &this->pos); 
			this->dying = 1;
			this->timer = 0;	
		}
		else 		{ PlaySound(this, SE_EMY_BUBBLE_EXTINCT); }
	
		this->timer += 1;
	}
	void daDreidel::endState_Outro() { }