summaryrefslogtreecommitdiff
path: root/src/bossFuzzyBear.cpp
blob: b13955c0540302649afcf4ef05ee850eafe3b195 (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
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
#include <common.h>
#include <game.h>
#include <g3dhax.h>
#include <sfx.h>
#include <stage.h>
#include "effects.h"
#include "player.h"


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

	mHeapAllocator_c allocator;
	m3d::mdl_c bodyModel;
	nw4r::g3d::ResFile resFile;
	m3d::anmChr_c animationChr;

	int timer;
	char BigBossFuzzyBear;
	float Baseline;
	float AreaWidthLeft;
	float AreaWidthRight;
	float LaunchSpeedShort;
	float LaunchSpeedHigh;
	char dying;
	float storeSpeed;
	Vec initialPos;
	char RolyBounces;
	Vec RolyPos;
	char falldown;
	char damage;
	char roly;
	char isInvulnerable;
	
	dEn_c *Kameck;

	static daFuzzyBear_c *build();

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

	void playerCollision(ActivePhysics *apThis, ActivePhysics *apOther);
//	void yoshiCollision(ActivePhysics *apThis, ActivePhysics *apOther);
	void collisionCat1_Fireball_E_Explosion(ActivePhysics *apThis, ActivePhysics *apOther);
	bool collisionCat2_IceBall_15_YoshiIce(ActivePhysics *apThis, ActivePhysics *apOther);
	void collisionCatD_GroundPound(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);

	USING_STATES(daFuzzyBear_c);
	DECLARE_STATE(Grow);
	DECLARE_STATE(Bounce);
	DECLARE_STATE(Needles);
	DECLARE_STATE(Spray);
	DECLARE_STATE(RolyPoly);
	DECLARE_STATE(Wait);
	DECLARE_STATE(Outro);
};

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


extern "C" void *PlaySound(daFuzzyBear_c *, int soundID);
extern "C" void *StopSound(int soundID);

extern "C" u32 GenerateRandomNumber(int max);
extern "C" dStageActor_c *CreateActor(u16 classID, int settings, Vec pos, char rot, char layer);
extern "C" u8 dSprite_c__getXDirectionOfFurthestPlayerRelativeToVEC3(daFuzzyBear_c *, Vec pos);
extern "C" dStageActor_c *GetSpecificPlayerActor(int num);

extern "C" void *StopBGMMusic();
extern "C" void *StartBGMMusic();

extern "C" void *MakeMarioEnterDemoMode();
extern "C" void *MakeMarioExitDemoMode();
extern "C" void *UpdateGameMgr();


CREATE_STATE(daFuzzyBear_c, Grow);
CREATE_STATE(daFuzzyBear_c, Bounce);
CREATE_STATE(daFuzzyBear_c, Needles);
CREATE_STATE(daFuzzyBear_c, Spray);
CREATE_STATE(daFuzzyBear_c, RolyPoly);
CREATE_STATE(daFuzzyBear_c, Wait);
CREATE_STATE(daFuzzyBear_c, Outro);



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

	this->_vf220(apOther->owner);
	OSReport("I hit Mario."); 
}
void daFuzzyBear_c::collisionCat1_Fireball_E_Explosion(ActivePhysics *apThis, ActivePhysics *apOther) { 

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

	OSReport("Hit Fireball");
	this->timer = 0;
	PlaySound(this, SE_BOSS_KOOPA_FIRE_DISAPP);
	
	CreateEffect(&apOther->owner->pos, &(S16Vec){0,0,0}, &(Vec){1.0, 1.0, 1.0}, 102);
	this->damage++;
	if (this->damage > 14) { doStateChange(&StateID_Outro); }
}
bool daFuzzyBear_c::collisionCat2_IceBall_15_YoshiIce(ActivePhysics *apThis, ActivePhysics *apOther) { OSReport("Hit Iceball"); return false; }
void daFuzzyBear_c::collisionCatD_GroundPound(ActivePhysics *apThis, ActivePhysics *apOther) { OSReport("Groundpound\n"); }
void daFuzzyBear_c::collisionCat9_RollingObject(ActivePhysics *apThis, ActivePhysics *apOther) { 
	OSReport("Hit Rolling Object"); 

	dActor_c *block = apOther->owner;
	dEn_c *blah = (dEn_c*)block;

	blah->speed.x = -blah->speed.x;
	blah->pos.x += blah->speed.x;

	if (blah->speed.y < 0) {
		blah->speed.y = -blah->speed.y; }
	
	blah->doSpriteMovement();
	blah->doSpriteMovement();
	
	if (this->isInvulnerable == 1) { 
		
		if (blah->direction == 0) { blah->direction = 1; }
		else					  { blah->direction = 0; }
		
		return; 
	}
	
	if (blah->direction == 0) { blah->direction = 1; this->roly = 0; }
	else					  { blah->direction = 0; this->roly = 1; }
	
	this->pos.x += blah->speed.x;
		
	this->timer = 0; 
	this->damage = this->damage + 5;
	
	
	PlaySound(this, SE_EMY_BLOW_PAKKUN_DOWN);
	CreateEffect(&blah->pos, &(S16Vec){0,0,0}, &(Vec){1.0, 1.0, 1.0}, 161);
	
	if (this->damage > 14) { doStateChange(&StateID_Outro); } 
	else { doStateChange(&StateID_RolyPoly); }
}
void daFuzzyBear_c::collisionCat13_Hammer(ActivePhysics *apThis, ActivePhysics *apOther) { 

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

	PlaySound(this, SE_EMY_BIG_PAKKUN_DAMAGE_1);
	OSReport("Hit Hammer");
	this->timer = 0; 
	this->damage += 5;
	
	CreateEffect(&apOther->owner->pos, &(S16Vec){0,0,0}, &(Vec){1.0, 1.0, 1.0}, 162);
	
	if (this->damage > 14) { doStateChange(&StateID_Outro); } 
	else { doStateChange(&StateID_RolyPoly); }
}
void daFuzzyBear_c::collisionCat14_YoshiFire(ActivePhysics *apThis, ActivePhysics *apOther) { OSReport("Hit Yoshi Fire"); }




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


void daFuzzyBear_c::setupBodyModel() {
	allocator.link(-1, GameHeaps[0], 0, 0x20);

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

	bool ret;
	nw4r::g3d::ResAnmChr anmChr = this->resFile.GetResAnmChr("run");
	ret = this->animationChr.setup(mdl, anmChr, &this->allocator, 0);

	allocator.unlink();
}


int daFuzzyBear_c::onCreate() {

	OSReport("Creating the Fuzzy Bear Model");
	setupBodyModel();


	this->BigBossFuzzyBear = this->settings >> 28;


	OSReport("Setting Fuzzy Bear's Size to 1.0");
	this->scale = (Vec){1.0, 1.0, 1.0};

	OSReport("Creating Fuzzy Bear's Physics Struct");

	ActivePhysics::Info HitMeBaby;
	HitMeBaby.xDistToCenter = 0.0;
	HitMeBaby.yDistToCenter = 0.0;

	if (BigBossFuzzyBear == 0) {
		HitMeBaby.xDistToEdge = 32.0;
		HitMeBaby.yDistToEdge = 32.0; }
	else {
		HitMeBaby.xDistToEdge = 38.0;
		HitMeBaby.yDistToEdge = 38.0; }

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


	OSReport("Making the Physics Class and adding to the list");
	this->aPhysics.initWithStruct(this, &HitMeBaby);
	this->aPhysics.addToList();

	OSReport("Setting up Fuzzy Bear's Box of Goodies");
	
	this->pos.y = this->pos.y + 6;
	this->rot.x = 0; // X is vertical axis
	this->rot.y = 0; // Y is horizontal axis
	this->rot.z = 0; // Z is ... an axis >.>
	this->direction = 0; // Heading left.
	
	this->speed.x = 0;
	this->LaunchSpeedShort = ((this->settings >> 20) && 0xF) * 10.0;
	this->LaunchSpeedHigh = ((this->settings >> 24) && 0xF) * 10.0;
	
	this->AreaWidthRight = this->settings && 0xFF;
	this->AreaWidthLeft = (this->settings >> 8) && 0xFF;
	
	this->initialPos = this->pos;
	this->storeSpeed = 0;
	this->falldown = 0;
	this->roly = 0;
	this->damage = 0;
	this->isInvulnerable = 0;
	this->dying = 0;


	bindAnimChr_and_setUpdateRate("run", 1, 0.0, 1.0);
		
	OSReport("Setting Fuzzy Bear's State");
	doStateChange(&StateID_Grow);

	OSReport("Going to Execute Fuzzy Bear");
	this->onExecute();
	return true;
}

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

int daFuzzyBear_c::onExecute() {
	// OSReport("Fuzzy Bear was Executed.");
	acState.execute();
	updateModelMatrices();

	if(this->animationChr.isAnimationDone())
		this->animationChr.setCurrentFrame(0.0);

	if (this->aPhysics.result1 == 1) {
		char PlayerID = NearestPlayer(this);
		dStageActor_c *Player = GetSpecificPlayerActor(PlayerID);
		
		this->_vf220(Player);
	}
	
	return true;
}


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


void daFuzzyBear_c::updateModelMatrices() {
	// This won't work with wrap because I'm lazy.
	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);
}


// Grow State

void daFuzzyBear_c::beginState_Grow() { 
	OSReport("Growing when Kameck Tells me to.\n");
	this->timer = 0;

	OSReport("Stopping the Music.\n");
	StopBGMMusic();

	OSReport("Setting the boss flag. %p\n", dStage32C_c::instance);
	OSReport("Boss flag is; %d\n", dStage32C_c::instance->freezeMarioBossFlag);
	dStage32C_c::instance->freezeMarioBossFlag = 1;

	MakeMarioEnterDemoMode();

	OSReport("WLClass Flags are; %d and %d\n", WLClass::instance->_4, WLClass::instance->_8);

	WLClass::instance->_4 = 4;
	WLClass::instance->_8 = 0;

	OSReport("Creating the Vecs.\n");
	Vec pos = (Vec){this->pos.x - 124.0, this->pos.y + 104.0, 3564.0};
	S16Vec rot = (S16Vec){0, 0, 0};


	OSReport("Creating Kameck.\n");
	Kameck = (daKameckDemo*)createChild(KAMECK_FOR_CASTLE_DEMO, (dStageActor_c*)this, 0, &pos, &rot, 0);

	OSReport("Setting Kameck's State.\n");
	Kameck->doStateChange(&daKameckDemo::StateID_DemoWait);

	OSReport("Executing the Kamek.\n");
}

void daFuzzyBear_c::executeState_Grow() { 


	if (this->timer == 130) { Kameck->doStateChange(&daKameckDemo::StateID_DemoSt); }
	if (this->timer == 400) { Kameck->doStateChange(&daKameckDemo::StateID_DemoSt2); }
	
	this->timer = this->timer + 1;
	
	float scaleSpeed, yPosScaling;

	if (this->timer == 150) { PlaySound(this, SE_BOSS_IGGY_WANWAN_TO_L); }
	
	if ((this->timer > 150) && (this->timer < 230)) {

		if (BigBossFuzzyBear == 1) {
			scaleSpeed = 0.025;
		 	yPosScaling = 25; }
		else {
			scaleSpeed = 0.01875;
			yPosScaling = 18; }
	
		float modifier;

		modifier = 1.0 + ((this->timer - 150) * scaleSpeed);
		
		this->scale = (Vec){modifier, modifier, modifier};
		this->pos.y = this->pos.y + (yPosScaling/80);
		
	}

	if (this->timer == 360) { 

		Vec tempPos = (Vec){this->pos.x - 40.0, this->pos.y + 120.0, 3564.0};
		CreateEffect(&tempPos, &(S16Vec){0,0,0}, &(Vec){1.0, 1.0, 1.0}, 175);  // 400 & 401 // 564 // 583 // 754 // 958
		CreateEffect(&tempPos, &(S16Vec){0,0,0}, &(Vec){1.0, 1.0, 1.0}, 400);  // 400 & 401 // 564 // 583 // 754 // 958
		CreateEffect(&tempPos, &(S16Vec){0,0,0}, &(Vec){1.0, 1.0, 1.0}, 401);  // 400 & 401 // 564 // 583 // 754 // 958
		CreateEffect(&tempPos, &(S16Vec){0,0,0}, &(Vec){1.0, 1.0, 1.0}, 564);  // 400 & 401 // 564 // 583 // 754 // 958
		CreateEffect(&tempPos, &(S16Vec){0,0,0}, &(Vec){1.0, 1.0, 1.0}, 583);  // 400 & 401 // 564 // 583 // 754 // 958
		CreateEffect(&tempPos, &(S16Vec){0,0,0}, &(Vec){1.0, 1.0, 1.0}, 754);  // 400 & 401 // 564 // 583 // 754 // 958
		CreateEffect(&tempPos, &(S16Vec){0,0,0}, &(Vec){1.0, 1.0, 1.0}, 958);  // 400 & 401 // 564 // 583 // 754 // 958

	}
	
	if (this->timer > 420) { doStateChange(&StateID_Bounce); }
	
}
void daFuzzyBear_c::endState_Grow() { 
	this->Baseline = this->pos.y;

	OSReport("Ending boss flag.\n");
	dStage32C_c::instance->freezeMarioBossFlag = 0;
	WLClass::instance->_8 = 1;

	MakeMarioExitDemoMode();

	OSReport("Ending BGMusic.\n");
	StartBGMMusic();

	OSReport("Deleting the Kamek.\n");

	Kameck->Delete(1);
	OSReport("OK. All grown up now."); 
}





// Bounce State

void daFuzzyBear_c::beginState_Bounce() { 

	OSReport("Begin Bouncing"); 
	if (this->direction = 0) { this->speed.x = 1.5; }
	else 					 { this->speed.x = -1.5 ; }
	
	if (this->storeSpeed != 0) { this->speed.x = this->storeSpeed; }
	
	this->timer = 20;
}
void daFuzzyBear_c::executeState_Bounce() { 

	float wallDistance, scaleDown, scaleUp, scaleBase;

	if (BigBossFuzzyBear == 0) {
		wallDistance = 32.0;
		scaleDown = 24.0;
		scaleUp = 10.0;
		scaleBase = 2.5;
	}
	else {
		wallDistance = 38.0;
		scaleDown = 32.0;
		scaleUp = 12.0;
		scaleBase = 3.0;
	}


	if (this->falldown == 1) { this->speed.x = 0; this->timer = 0; }	

	
	// Check for walls
	
	if (this->pos.x <= this->initialPos.x - ((17 * 16.0) + wallDistance))  { // Hit left wall, head right.
		this->speed.x = -this->speed.x;
		this->direction = 1;
		this->pos.x = this->pos.x + 1.0; }
		
	if (this->pos.x >= this->initialPos.x + ((7.5 * 16.0) - wallDistance))  { // Hit right wall, head left.
		this->speed.x = -this->speed.x;
		this->direction = 0;
		this->pos.x = this->pos.x - 1.0; }
	
	
	// Check if we're on the ground.
	
	if (this->pos.y < this->Baseline) {

		this->falldown = 0;
		
		this->timer = this->timer + 1;
		if (this->speed.x != 0) {
			this->storeSpeed = this->speed.x; }
		this->speed.x = 0;
		this->speed.y = 0;
		
		
		if (this->timer < 10) {
			float modifier;
			modifier = scaleBase - (this->timer * 0.1);
			
			this->scale.y = modifier;
			this->pos.y = this->pos.y + (scaleDown/10.0);
			if (this->pos.y > this->Baseline) { this->pos.y = this->Baseline - 1.0; }
		}
		else if (this->timer == 10) { 
			Vec tempPos = (Vec){this->pos.x, this->pos.y - wallDistance, 5500.0};
			CreateEffect(&tempPos, &(S16Vec){0,0,0}, &(Vec){1.0, 1.0, 1.0}, 66); 
		}
		else {
			float modifier;
			modifier = (scaleBase - 1.0) + ((this->timer - 10) * 0.1);
			
			this->scale.y = modifier;
			this->pos.y = this->pos.y + (scaleUp/10.0);
			if (this->pos.y > this->Baseline) { this->pos.y = this->Baseline - 1.0; }
			PlaySound(this, SE_PLY_JUMPDAI);
		}
			
		if (this->timer > 20) { 
			
			int randChoice;
			
			randChoice = GenerateRandomNumber(5);
			if (randChoice == 0) { doStateChange(&StateID_Wait); }

			randChoice = GenerateRandomNumber(4);
			if (randChoice == 0) { this->speed.y = 8.0; }
			else { this->speed.y = 6.0; }
		
			this->timer = 0;
			this->pos.y = this->Baseline + 1;
			OSReport("Takeoff Initiated");
			
			this->speed.x = this->storeSpeed;
		 }
	}
	
	else { this->speed.y = this->speed.y - 0.1; } // Gravity 

		
	this->HandleXSpeed();
	this->HandleYSpeed();

	this->UpdateObjectPosBasedOnSpeedValuesReal();

}

void daFuzzyBear_c::endState_Bounce() { OSReport("No more bouncing."); }





// Needles State - shoots out some black icicles

void daFuzzyBear_c::beginState_Needles() {
	this->timer = 0;
	this->speed.y = 0;	
	this->speed.x = 0;
	OSReport("Fuzzy Needle State Begin"); 
}
void daFuzzyBear_c::executeState_Needles() { 
	float origScale;

	this->speed.y = 0;	
	this->speed.x = 0;

	if (BigBossFuzzyBear == 0) {
		origScale = 2.5;
	}
	else {
		origScale = 3.0;
	}

	this->timer = this->timer + 1;
	OSReport("Needle Timer: %d", this->timer); 

	if (this->timer <= 120) {
		this->scale.y = (sin(this->timer * 3.14 / 5.0) / 2.0) + origScale; // 3 shakes per second, exactly 24 shakes overall
		this->scale.x = (sin(this->timer * 3.14 / 5.0) / 2.0) + origScale; // 3 shakes per second, exactly 24 shakes overall
	
		if (this->timer == 30) {
			dStageActor_c *spawner = CreateActor(339, 0, this->pos, 0, 0);
			spawner->speed.x = -6.0;
			spawner->speed.y = 0.0;
			spawner->scale = (Vec){1.0, 1.0, 1.0};
		}

		if (this->timer == 45) {
			dStageActor_c *spawner = CreateActor(339, 0, this->pos, 0, 0);
			spawner->speed.x = 6.0;
			spawner->speed.y = 6.0;
			spawner->scale = (Vec){1.0, 1.0, 1.0};
		}

		if (this->timer == 60) {
			dStageActor_c *spawner = CreateActor(339, 0, this->pos, 0, 0);
			spawner->speed.x = 0.0;
			spawner->speed.y = 6.0;
			spawner->scale = (Vec){1.0, 1.0, 1.0};
		}

		if (this->timer == 75) {
			dStageActor_c *spawner = CreateActor(339, 0, this->pos, 0, 0);
			spawner->speed.x = -6.0;
			spawner->speed.y = 6.0;
			spawner->scale = (Vec){1.0, 1.0, 1.0};
		}

		if (this->timer == 90) {
			dStageActor_c *spawner = CreateActor(339, 0, this->pos, 0, 0);
			spawner->speed.x = -6.0;
			spawner->speed.y = 0.0;
			spawner->scale = (Vec){1.0, 1.0, 1.0};
		}
	}
	else { doStateChange(&StateID_Bounce); }

	this->HandleXSpeed();
	this->HandleYSpeed();

	this->UpdateObjectPosBasedOnSpeedValuesReal();

}
void daFuzzyBear_c::endState_Needles() { OSReport("Fuzzy Needle State End"); }


// Spray State - jumps in the air and shakes out some small fuzzies

void daFuzzyBear_c::beginState_Spray() { 
	this->timer = 0; 
	this->speed.y = 7.0;
	this->speed.x = 0.0;
	OSReport("Fuzzy Spray State Begin"); 
}
void daFuzzyBear_c::executeState_Spray() { 
		
	this->speed.x = 0.0;

	OSReport("Fuzzy Spray State Execute");
	if (this->speed.y < 1.0) {
		this->speed.y = 0;
		
		if (this->timer < 120) {
			
			this->rot.y = sin(this->timer * 3.14 / 5) * 4000; // 3 shakes per second, exactly 24 shakes overall

			int randChoice;
			randChoice = GenerateRandomNumber(18); // 1.3 Fuzzies per second, 6 fuzzies overall
		
			if (randChoice == 0) { 
				int randChoiceX, randChoiceY;
				randChoiceX = GenerateRandomNumber(92);
				randChoiceY = GenerateRandomNumber(48);
				
				float xa, ya;
				xa = randChoiceX - 48.0;
				ya = randChoiceY - 24.0;
				
				CreateActor(144, 0, (Vec){this->pos.x + xa, this->pos.y + ya, this->pos.z}, 0, 0);
			} 
		}

		else { doStateChange(&StateID_Bounce); }

		this->timer = this->timer + 1;
		
	}
	
	else { this->speed.y = this->speed.y - 0.1; } // Gravity 


	this->HandleXSpeed();
	this->HandleYSpeed();

	this->UpdateObjectPosBasedOnSpeedValuesReal();

}
void daFuzzyBear_c::endState_Spray() { 
	this->rot.y = 0;
	this->timer = 20;
	this->falldown = 1;	
	OSReport("Fuzzy Spray State End");
}


// Roly Poly State - Rolls from left to right, bounces off both walls, and returns to original position.

void daFuzzyBear_c::beginState_RolyPoly() { 
	
	this->isInvulnerable = 1;
	
	if (this->roly == 0) { this->speed.x = 12.0; }
	else 				 { this->speed.x = -12.0; }
	
	this->speed.y = 0;
	this->RolyBounces = 0;
	this->RolyPos = this->pos;
	OSReport("Fuzzy Roly State Begin");

	if (BigBossFuzzyBear == 0) {
		this->scale = (Vec){2.5, 2.5, 2.5};
	}
	else {
		this->scale = (Vec){3.0, 3.0, 3.0};
	}

	this->timer = 0;
}
void daFuzzyBear_c::executeState_RolyPoly() { 
	OSReport("Fuzzy Roly State Execute");
	float wallDistance, scaleDown, scaleUp;

	PlaySound(this, SE_OBJ_TEKKYU_G_CRASH);
	
	if (this->pos.y > this->Baseline) { this->pos.y -= 2.0; }
	else { 
		this->pos.y = this->Baseline - 1.0;
		
		Vec tempPos = (Vec){this->pos.x, this->pos.y - 34.0, 5500.0};
		
		if (this->timer & 0x1) { CreateEffect(&tempPos, &(S16Vec){0,0,0}, &(Vec){0.4, 0.4, 0.4}, 242); }
	 }
	
	if (this->direction == 0) { // is even
		this->pos.x = this->pos.x - 4.0; }
	else { // is odd
		this->pos.x = this->pos.x + 4.0; }

	if (BigBossFuzzyBear == 0) {
		wallDistance = 38.0;
	}
	else {
		wallDistance = 50.0;
	}
	
	this->timer += 1;

	if (this->pos.x <= this->initialPos.x - ((17 * 16.0) + wallDistance))  { // Hit left wall, head right.
		this->speed.x = -this->speed.x;
		this->direction = 1;
		this->pos.x = this->pos.x + 1.0; 
		this->RolyBounces = this->RolyBounces + 1;
		}
		
	if (this->pos.x >= this->initialPos.x + ((7.5 * 16.0) - wallDistance))  { // Hit right wall, head left.
		this->speed.x = -this->speed.x;
		this->direction = 0;
		this->pos.x = this->pos.x - 1.0; 
		this->RolyBounces = this->RolyBounces + 1;
		}

	
	if (this->direction == 1) { this->rot.z = this->rot.z - 0x400; } 
	else 					  { this->rot.z = this->rot.z + 0x400; } 
		
	if (this->RolyBounces == 2) {
		if ((this->pos.x > this->RolyPos.x -20.0) && (this->pos.x < this->RolyPos.x + 20.0)) {
			this->speed.x = 0;
			if (this->rot.z == 0) { doStateChange(&StateID_Bounce); } } 
	}



//	this->HandleXSpeed();
//	this->HandleYSpeed();

//	this->doSpriteMovement();
//	this->UpdateObjectPosBasedOnSpeedValuesReal();
	
 }
void daFuzzyBear_c::endState_RolyPoly() { 
	this->rot.z = 0; 
	OSReport("Fuzzy Roly State End"); 
	this->isInvulnerable = 0;
	this->timer = 0;
}







void daFuzzyBear_c::beginState_Wait() { this->timer = 0;}
void daFuzzyBear_c::executeState_Wait() { 
	
	this->timer = this->timer + 1;

	if (this->timer > 60) {	
		int randChoice;
		
		if (BigBossFuzzyBear == 1) { doStateChange(&StateID_Spray); }
		else 					   { doStateChange(&StateID_Bounce); }
	}	
} 
void daFuzzyBear_c::endState_Wait() { }



void daFuzzyBear_c::beginState_Outro() { 

	MakeMarioEnterDemoMode();

	WLClass::instance->_4 = 5;
	WLClass::instance->_8 = 0;

	this->removeMyActivePhysics();
	this->timer = 0;
	StopBGMMusic();

	dStage32C_c::instance->freezeMarioBossFlag = 1;

}
void daFuzzyBear_c::executeState_Outro() {

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

			if (GetSpecificPlayerActor(0) != 0) {
				PlaySound(this, SE_VOC_MA_CLEAR_BOSS);
				// Send PlBase into DemoGoal State here, kthxbai
			}
			
			if (GetSpecificPlayerActor(1) != 0) {
				PlaySound(this, SE_VOC_LU_CLEAR_BOSS);
				// Send PlBase into DemoGoal State here, kthxbai
			}

			if (GetSpecificPlayerActor(2) != 0) {
				PlaySound(this, SE_VOC_KO_CLEAR_BOSS);
				// Send PlBase into DemoGoal State here, kthxbai
			}

			if (GetSpecificPlayerActor(3) != 0) {
				PlaySound(this, SE_VOC_KO2_CLEAR_BOSS);
				// Send PlBase into DemoGoal State here, kthxbai
			}
		}	
		
		this->timer += 1;
		return; 
	}	

	if (this->scale.x > 0.1) {

		PlaySound(this, SE_BOSS_CMN_DAMAGE_LAST);

		// Adjust this to equal the scale of your boss / 80.
		this->scale.x -= 0.015;
		this->scale.y -= 0.015;
		this->scale.z -= 0.015;

		if (this->timer == 30) {  
			CreateEffect(&this->pos, &(S16Vec){0,0,0}, &(Vec){2.0, 2.0, 2.0}, 756); 
			CreateEffect(&this->pos, &(S16Vec){0,0,0}, &(Vec){2.0, 2.0, 2.0}, 801); 
			CreateEffect(&this->pos, &(S16Vec){0,0,0}, &(Vec){2.0, 2.0, 2.0}, 957); 
			this->timer = 0;
		}

		this->timer += 1;
	}
	else {
		this->scale.x = 0.0;
		this->scale.y = 0.0;
		this->scale.z = 0.0;
		
		CreateEffect(&this->pos, &(S16Vec){0,0,0}, &(Vec){2.0, 2.0, 2.0}, 588);
		this->dying = 1;
		this->timer = 0;

		PlaySound(this, STRM_BGM_SHIRO_BOSS_CLEAR);
		MakeMarioEnterDemoMode();
	}
}
void daFuzzyBear_c::endState_Outro() { }