summaryrefslogtreecommitdiff
path: root/src/challengeStar.cpp
blob: f754188d715a651190864e68a5ed203407e3c57e (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
#include <common.h>
#include <game.h>
#include <g3dhax.h>
#include <sfx.h>


extern "C" bool SpawnEffect(const char*, int, Vec*, S16Vec*, Vec*);

extern int GlobalStarsCollected;


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

	mHeapAllocator_c allocator;
	m3d::mdl_c bodyModel;

	mEf::es2 effect;

	u64 eventFlag;
	s32 timer;
	bool collected;

	static dChallengeStar *build();

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

	bool collisionCat3_StarPower(ActivePhysics *apThis, ActivePhysics *apOther);
	bool collisionCat7_GroundPound(ActivePhysics *apThis, ActivePhysics *apOther);
	bool collisionCat7_GroundPoundYoshi(ActivePhysics *apThis, ActivePhysics *apOther);
	bool collisionCatA_PenguinMario(ActivePhysics *apThis, ActivePhysics *apOther);
	bool collisionCat9_RollingObject(ActivePhysics *apThis, ActivePhysics *apOther);

};


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

	if (collected) {
		this->Delete(1);
		return; }


	PlaySoundAsync(this, SE_OBJ_BROOM_KEY_SHOW);
	SpawnEffect("Wm_ob_greencoinkira_a", 0, &this->pos, &(S16Vec){0,0,0}, &(Vec){0.8, 0.8, 0.8});
	
	GlobalStarsCollected--;
	if (GlobalStarsCollected == 0) {
		dFlagMgr_c::instance->flags |= this->eventFlag;
	}
	
	collected = true;

	this->Delete(1);
}

void dChallengeStar::yoshiCollision(ActivePhysics *apThis, ActivePhysics *apOther) { this->playerCollision(apThis, apOther); }
bool dChallengeStar::collisionCat3_StarPower(ActivePhysics *apThis, ActivePhysics *apOther) {
	this->playerCollision(apThis, apOther);
	return true;
}
bool dChallengeStar::collisionCat9_RollingObject(ActivePhysics *apThis, ActivePhysics *apOther) {
	this->playerCollision(apThis, apOther);
	return true;
}
bool dChallengeStar::collisionCat7_GroundPound(ActivePhysics *apThis, ActivePhysics *apOther) {
	this->playerCollision(apThis, apOther);
	return true;
}
bool dChallengeStar::collisionCat7_GroundPoundYoshi(ActivePhysics *apThis, ActivePhysics *apOther) {
	this->playerCollision(apThis, apOther);
	return true;
}
bool dChallengeStar::collisionCatA_PenguinMario(ActivePhysics *apThis, ActivePhysics *apOther) {
	this->playerCollision(apThis, apOther);
	return true;
}


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


int dChallengeStar::onCreate() {
	
	collected = false;
	char die = this->settings & 0xF;
	if (GetSpecificPlayerActor(die) == 0) { this->Delete(1); return 2; }

	GlobalStarsCollected++;

	allocator.link(-1, GameHeaps[0], 0, 0x20);

	nw4r::g3d::ResFile rf(getResource("I_star", "g3d/silver_star.brres"));
	bodyModel.setup(rf.GetResMdl("I_star"), &allocator, 0x224, 1, 0);
	SetupTextures_Map(&bodyModel, 0);

	allocator.unlink();
	
	ActivePhysics::Info HitMeBaby;
	HitMeBaby.xDistToCenter = 0.0;
	HitMeBaby.yDistToCenter = 3.0;
	HitMeBaby.xDistToEdge = 6.0;
	HitMeBaby.yDistToEdge = 6.0;
	HitMeBaby.category1 = 0x5;
	HitMeBaby.category2 = 0x0;
	HitMeBaby.bitfield1 = 0x4F;
	HitMeBaby.bitfield2 = 0x200;
	HitMeBaby.unkShort1C = 0;
	HitMeBaby.callback = &dEn_c::collisionCallback;

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

	char eventNum	= (this->settings >> 24)	& 0xFF;
	this->eventFlag = (u64)1 << (eventNum - 1);

	this->scale.x = 0.70;
	this->scale.y = 0.70;
	this->scale.z = 0.70;

	this->pos.x += 8.0;
	this->pos.y -= 14.0;
	this->pos.z = 3300.0;
	
	this->onExecute();
	return true;
}


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

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


void dChallengeStar::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 dChallengeStar::onExecute() {
	updateModelMatrices();

	effect.spawn("Wm_ob_keyget02_kira", 0, &this->pos, &(S16Vec){0,0,0}, &(Vec){0.8, 0.8, 0.8});
	this->rot.y += 0x200;
	return true;
}