summaryrefslogtreecommitdiff
path: root/src/shyguy.cpp
blob: 633bce602f6a464fb610cb23fcbca0ecd5b4356f (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
#include <common.h>
#include <game.h>
#include <g3dhax.h>
#include <sfx.h>
#include <stage.h>
#include "effects.h"
#include "player.h"


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

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

	m3d::mdl_c bodyModel;

	m3d::anmChr_c animateWalk;
	
	static daShyGuy *build();

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

	USING_STATES(daShyGuy);
	DECLARE_STATE(Walk);
	DECLARE_STATE(Turn);
	DECLARE_STATE(Jump);
};

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


extern "C" void *PlaySound(daShyGuy *, 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(daShyGuy *, Vec pos);
extern "C" dStageActor_c *GetSpecificPlayerActor(int number);


// CREATE_STATE(daShyGuy, Grow);


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


int daShyGuy::onCreate() {

	// static const char *anmNames[197] = {"DUMMY_R", "IDLE_R", "NO_SKATE_MOVE_R", "SKATE_R", "R_SKATE_R", "L_SKATE_R", "DASH_LKICK_R", "DASH_RKICK_R", "R_DASH_LKICK_R", "R_DASH_RKICK_R", "L_DASH_LKICK_R", "L_DASH_RKICK_R", "BACK_SKATE_R", "R_BACK_SKATE_R", "L_BACK_SKATE_R", "R180_SKATE_TURN_R", "L180_SKATE_TURN_R", "R_BRAKE_1_R", "R_BRAKE_2_R", "R_BRAKE_3_R", "L_BRAKE_1_R", "L_BRAKE_2_R", "L_BRAKE_3_R", "BACK_BRAKE_1_R", "BACK_BRAKE_2_R", "BACK_BRAKE_3_R", "TACKLE_M_DASH_LKICK_R", "TACKLE_M_DASH_RKICK_R", "TACKLE_M_R_DASH_LKICK_R", "TACKLE_M_R_DASH_RKICK_R", "TACKLE_M_L_DASH_LKICK_R", "TACKLE_M_L_DASH_RKICK_R", "TACKLE_R", "TACKLE_END_R", "TACKLE_STEAL_R", "TACKLE_R_CLASH_R", "TACKLE_L_CLASH_R", "TACKLE_BACK_CLASH_R", "PACK_CATCH_FRONT_R", "PACK_CATCH_RIGHT_R", "PACK_CATCH_LEFT_R", "PACK_CATCH_BACK_R", "NORMAL_STEAL_R", "DIVING_STEAL_R", "DIVING_STEAL_CATCH_R", "DIVING_STEAL_MISS_R", "FACEOFF_SET_START_R", "FACEOFF_SET_IDLE_R", "FACEOFF_R", "FACEOFF_BATTLE_R", "FACEOFF_PUSH_R", "FACEOFF_WIN_R", "FACEOFF_MISS_R", "T_ATK01_START_R", "T_ATK01_END_R", "T_ATK02_START_R", "T_ATK02_END_R", "T_ATK03_START_R", "T_ATK03_LOOP_R", "T_ATK03_END_R", "FIGHTING_R", "OB_IDLE_R", "OB_NO_SKATE_MOVE_R", "OB_SKATE_R", "OB_R_SKATE_R", "OB_L_SKATE_R", "OB_DASH_LKICK_R", "OB_DASH_RKICK_R", "OB_R_DASH_LKICK_R", "OB_R_DASH_RKICK_R", "OB_L_DASH_LKICK_R", "OB_L_DASH_RKICK_R", "OB_BACK_SKATE_R", "OB_R_BACK_SKATE_R", "OB_L_BACK_SKATE_R", "OB_R180_SKATE_TURN_R", "OB_L180_SKATE_TURN_R", "OB_R_BRAKE_1_R", "OB_R_BRAKE_2_R", "OB_R_BRAKE_3_R", "OB_L_BRAKE_1_R", "OB_L_BRAKE_2_R", "OB_L_BRAKE_3_R", "OB_BACK_BRAKE_1_R", "OB_BACK_BRAKE_2_R", "OB_BACK_BRAKE_3_R", "OB_TACKLE_RS_CLASH_R", "OB_TACKLE_LS_CLASH_R", "OB_TACKLE_BACK_CLASH_R", "F_SHOOT_POSE_R", "F_SHOOT_CHARGE_R", "F_SHOOT_R", "F_SHOOT_FEINT_R", "C_SHOOT_POSE_R", "C_SHOOT_LOOP_R", "C_SHOOT_R", "C_SHOOT_FEINT_R", "GUARD_F_START_R", "GUARD_F_IDLE_R", "GUARD_F_THROUGH_R", "GUARD_F_THROUGH_POSE_R", "GUARD_F_THROUGH_MISS_R", "GUARD_B_START_R", "GUARD_B_IDLE_R", "GUARD_B_THROUGH_R", "GUARD_B_THROUGH_POSE_R", "GUARD_B_THROUGH_MISS_R", "OB_R_TRICK_MOVE_1_R", "OB_R_TRICK_MOVE_2_R", "OB_R_TRICK_MOVE_3_R", "OB_R_TRICK_MOVE_4_R", "OB_R_TRICK_MOVE_5_R", "OB_L_TRICK_MOVE_1_R", "OB_L_TRICK_MOVE_2_R", "OB_L_TRICK_MOVE_3_R", "OB_L_TRICK_MOVE_4_R", "OB_L_TRICK_MOVE_5_R", "L_DMG_F_1_R", "L_DMG_F_2_R", "L_DMG_F_3_R", "L_DMG_F_4_R", "M_DMG_F_1_R", "M_DMG_F_2_R", "M_DMG_F_3_R", "M_DMG_F_4_R", "R_HIT_DMG_F_1_R", "R_HIT_DMG_F_2_R", "WALL_HIT_DMG_F_3_R", "WALL_HIT_DMG_F_4_R", "L_HIT_DMG_F_1_R", "L_HIT_DMG_F_2_R", "WALL_HIT_DMG_B_3_R", "WALL_HIT_DMG_B_4_R", "WALL_DMG_F_R", "WALL_DMG_B_R", "FIRE_DMG_1_R", "FIRE_DMG_2_R", "FIRE_DMG_RUN_R", "SPIN_DMG_R", "SPIN_DMG_FRAFRA_R", "MEROMERO_DMG_R", "ONARA_DMG_R", "FRAFRA_DMG_1_R", "BIRIBIRI_DMG_R", "TURUTURU_DMG_R", "TURUTURU_DMG_LOOP_R", "TURUTURU_DMG_UP_R", "OTTOTTO_DMG_R", "TURURIN_DMG_ST_R", "TURURIN_DMG_LOOP_R", "TURURIN_DMG_ED_R", "EV_WIN_1_R", "EV_WIN_2_R", "EV_LOSE_1_R", "EV_LOSE_2_R", "SP_START_R", "SP_1_A_R", "SP_1_B_R", "SP_1_C_R", "SP_1_D_R", "SP_1_E_R", "SP_2_A_R", "SP_2_B_R", "SP_2_C_R", "SP_2_D_R", "SP_2_E_R", "SP_3_R", "SP_LOOP_R", "R_SLIDE_R", "L_SLIDE_R", "R_BLOCK_R", "R_BLOCK_UP_R", "R_BLOCK_BREAK_R", "L_BLOCK_R", "L_BLOCK_UP_R", "L_BLOCK_BREAK_R", "C_BLOCK_R", "C_BLOCK_UP_R", "C_BLOCK_BREAK_R", "H_SHOT_R", "SP_BLOCK_R", "SP_BLOCK_UP_R", "H_CUT_R", "DIVING_STEAL_R_CATCH_R", "DIVING_STEAL_L_CATCH_R", "DOWN_UP_R", "RESULT_R", "DM_IDLE_R", "DM_JUMP_R", "DM_VS_IN_R", "DM_VS_IDLE_R", "DM_CAP_IN_R", "DM_CAP_IDLE_R", "SL_EV_WIN_1_R", "SL_EV_WIN_2_R", "SL_EV_LOSE_1_R", "SL_EV_LOSE_2_R"};
	static const char *anmNames[32] = {"c18_DUMMY_R", "c18_IDLE_R", "c18_NORMAL_STEAL_R", "c18_DIVING_STEAL_R", "c18_DIVING_STEAL_MISS_R", "c18_OB_IDLE_R", "c18_L_DMG_F_1_R", "c18_L_DMG_F_3_R", "c18_L_DMG_F_4_R", "c18_EV_WIN_1_R", "c18_EV_WIN_2_R", "c18_EV_LOSE_1_R", "c18_EV_LOSE_2_R", "c18_R_SLIDE_R", "c18_L_SLIDE_R", "c18_R_BLOCK_R", "c18_R_BLOCK_UP_R", "c18_R_BLOCK_BREAK_R", "c18_L_BLOCK_R", "c18_L_BLOCK_UP_R", "c18_L_BLOCK_BREAK_R", "c18_C_BLOCK_R", "c18_C_BLOCK_UP_R", "c18_C_BLOCK_BREAK_R", "c18_H_SHOT_R", "c18_SP_BLOCK_R", "c18_SP_BLOCK_UP_R", "c18_H_CUT_R", "c18_DIVING_STEAL_R_CATCH_R", "c18_DIVING_STEAL_L_CATCH_R", "c18_DOWN_UP_R"};

	int anm = this->settings >> 24;

	OSReport("Creating the ShyGuy Model\n");
	allocator.link(-1, GameHeaps[0], 0, 0x20);

	if (anm == 0) {
		this->resFile.data = getResource("lemmy_ball", "g3d/ShyGuyRed.brres");
	}
	else if (anm == 1) {
		this->resFile.data = getResource("lemmy_ball", "g3d/ShyGuyBlue.brres");
	}
	else if (anm == 2) {
		this->resFile.data = getResource("lemmy_ball", "g3d/ShyGuyGreen.brres");
	}
	else if (anm == 3) {
		this->resFile.data = getResource("lemmy_ball", "g3d/ShyGuyCyan.brres");
	}
	nw4r::g3d::ResMdl mdl = this->resFile.GetResMdl("body_h");
	bodyModel.setup(mdl, &allocator, 0x224, 1, 0);
	SetupTextures_Enemy(&bodyModel, 0);

	// Animations start here
	bool ret;
	this->anmFile.data = getResource("lemmy_ball", "g3d/ShyGuyAnimations.brres");
	nw4r::g3d::ResAnmChr anmChr = this->anmFile.GetResAnmChr("c18_EV_WIN_2_R");
	OSReport("Checking ResAnmChr: %p\n", anmChr.data);
	ret = this->animateWalk.setup(mdl, anmChr, &this->allocator, 0);

	allocator.unlink();

	bindAnimChr_and_setUpdateRate("c18_EV_WIN_2_R", 1, 0.0, 1.0);

	OSReport("Setting ShyGuy's Size to 1.0\n");
	this->scale = (Vec){20.0, 20.0, 20.0};

	OSReport("Creating ShyGuy's Physics Struct\n");

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

	HitMeBaby.xDistToEdge = 14.0;
	HitMeBaby.yDistToEdge = 12.0;

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

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

	OSReport("Setting up ShyGuy's Box of Goodies\n");
	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 = 0; // Heading left.
	
	this->speed.x = 0;
			
	// OSReport("Setting ShyGuy's State");
	// doStateChange(&StateID_Walk);

	OSReport("Going to Execute ShyGuy\n");
	this->onExecute();
	return true;
}

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

int daShyGuy::onExecute() {
	// acState.execute();
	updateModelMatrices();

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

	this->pos.x = this->pos.x - 0.4;

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


int daShyGuy::onDraw() {
	bodyModel.scheduleForDrawing();
	bodyModel._vf1C();

	return true;
}

void daShyGuy::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);
}


void daShyGuy::beginState_Walk() { 
}
void daShyGuy::executeState_Walk() { 

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


}
void daShyGuy::endState_Walk() { 
}

void daShyGuy::beginState_Turn() { 
}
void daShyGuy::executeState_Turn() { 
}
void daShyGuy::endState_Turn() { 
}

void daShyGuy::beginState_Jump() { 
}
void daShyGuy::executeState_Jump() { 
}
void daShyGuy::endState_Jump() { 
}