Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
Padlock.c
Go to the documentation of this file.
1#include "common.h"
2#include "entity.h"
3#include "effects.h"
4#include "ld_addrs.h"
5#include "sprite/player.h"
6
7extern Gfx Entity_Padlock_Render[];
19
20void entity_Padlock_setupGfx(s32 entityIndex) {
21 Entity* entity = get_entity_by_index(entityIndex);
22 PadlockData* data = entity->dataBuf.padlock;
23 Matrix4f sp18;
24 Matrix4f sp58;
25 Matrix4f sp98;
26 Matrix4f spD8;
27
28 guMtxIdentF(sp58);
29 guMtxL2F(sp98, data->shackleMtx);
30 guMtxCatF(sp58, sp98, sp98);
31 sp98[3][0] += data->shacklePos;
32 guRotateF(spD8, entity->rot.x, -1.0f, 0.0f, 0.0f);
33 guMtxCatF(spD8, sp98, sp98);
34 guRotateF(spD8, entity->rot.z, 0.0f, 0.0f, 1.0f);
35 guRotateF(sp18, entity->rot.x, 1.0f, 0.0f, 0.0f);
36 guMtxCatF(spD8, sp18, sp18);
37 guRotateF(spD8, entity->rot.y, 0.0f, 1.0f, 0.0f);
38 guMtxCatF(sp18, spD8, spD8);
39 guMtxCatF(sp98, spD8, sp98);
40 guScaleF(sp18, entity->scale.x, entity->scale.y, entity->scale.z);
41 guMtxCatF(sp98, sp18, sp18);
42 guTranslateF(sp58, entity->pos.x, entity->pos.y, entity->pos.z);
43 guMtxCatF(sp18, sp58, sp58);
45
46 gSPMatrix(gMainGfxPos++, &gDisplayContext->matrixStack[gMatrixListPos++], G_MTX_PUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
47 gSPDisplayList(gMainGfxPos++, data->shackleGfx);
48 gSPPopMatrix(gMainGfxPos++, G_MTX_MODELVIEW);
49}
50
52 PlayerStatus* playerStatus = &gPlayerStatus;
53 PadlockData* data = entity->dataBuf.padlock;
54 f32 deltaX, deltaZ;
55
56 if (playerStatus->colliderHeight < fabs(playerStatus->pos.y - entity->pos.y)) {
58 } else {
59 entity->flags &= ~ENTITY_FLAG_DISABLE_COLLISION;
60 }
61
63 if (data->pushSpeed == 0.0f) {
65 }
66
67 data->pushSpeed += 0.5;
68
69 if (data->pushSpeed >= 2.5) {
70 data->pushSpeed = 2.5f;
71 }
72
73 deltaX = data->pushSpeed * sin_rad(DEG_TO_RAD(180.0f - entity->rot.y));
74 deltaZ = data->pushSpeed * cos_rad(DEG_TO_RAD(180.0f - entity->rot.y));
75
76 playerStatus->pos.x += deltaX;
77 playerStatus->pos.z -= deltaZ;
78 } else {
79 data->pushSpeed = 0.0f;
80 }
81}
82
84 PadlockData* data = entity->dataBuf.padlock;
85
86 switch (data->state) {
87 case 0:
89 if (entity->flags & ENTITY_FLAG_USED) {
90 data->state++;
92 }
93 break;
94 case 1:
95 data->shacklePos += 5.0f;
96 if (data->shacklePos >= 20.0f) {
97 data->shacklePos = 20.0f;
98 data->state++;
99 entity->rot.z += 12.0;
100 data->fallSpeed = -2.0f;
101 data->rotSpeed = 0.2f;
102 }
103 break;
104 case 2:
105 data->rotSpeed += 0.2;
106 entity->rot.x += data->rotSpeed;
107
108 data->fallSpeed -= 1.0;
109 entity->pos.y += data->fallSpeed;
110
111 if (entity->pos.y <= entity->shadowPosY) {
112 entity->pos.y = entity->shadowPosY;
113 data->fallSpeed = 5.0f;
114 data->rotSpeed = 3.0f;
115 data->state++;
116 fx_sparkles(FX_SPARKLES_0, entity->pos.x, entity->pos.y + 25.0f, entity->pos.z, 10.0f);
118 }
119 break;
120 case 3:
121 data->rotSpeed += 0.2;
122 entity->rot.x += data->rotSpeed;
123
124 data->fallSpeed -= 2.0;
125 entity->pos.y += data->fallSpeed;
126
127 if (entity->pos.y <= entity->shadowPosY) {
128 entity->pos.y = entity->shadowPosY;
129 data->timer = 2;
130 data->fallSpeed = 10.0f;
131 data->rotSpeed = 0.2f;
132 data->state++;
134 }
135 break;
136 case 4:
137 if (--data->timer <= 0) {
138 data->state++;
139 }
140 break;
141 case 5:
142 data->rotSpeed *= 2.0f;
143 if (data->rotSpeed > 30.0f) {
144 data->rotSpeed = 30.0f;
145 }
146 entity->rot.x += data->rotSpeed;
147 if (entity->rot.x >= 90.0) {
148 entity->rot.x = 90.0f;
149 data->rotSpeed = -20.0f;
150 data->state++;
152 }
153 break;
154 case 6:
155 data->rotSpeed += 10.0f;
156 if (data->rotSpeed > 30.0f) {
157 data->rotSpeed = 30.0f;
158 }
159 entity->rot.x += data->rotSpeed;
160 if (entity->rot.x >= 90.0) {
161 entity->rot.x = 90.0f;
162 data->timer = 5;
163 data->state++;
165 }
166 break;
167 case 7:
168 if (--data->timer <= 0) {
169 data->state++;
170 entity_start_script(entity);
171 data->timer = 5;
172 }
173 break;
174 case 8:
175 if (--data->timer <= 0) {
176 data->state++;
179 }
180 break;
181 }
182
183 if (data->state == 2 || data->state == 3 || data->state == 4 || data->state == 5 || data->state == 6 || data->state == 7 || data->state == 8) {
184 data->blinkCounter++;
185 if (data->blinkCounter & 1) {
186 entity->flags |= ENTITY_FLAG_HIDDEN;
187 } else {
188 entity->flags &= ~ENTITY_FLAG_HIDDEN;
189 }
190 }
191}
192
194 PadlockData* data;
195
197 data = entity->dataBuf.padlock;
198 data->shackleMtx = ENTITY_ADDR(entity, Mtx*, &Entity_Padlock_mtxShackle);
200}
201
210
219
228
234
239
242 .typeDataSize = sizeof(PadlockData),
243 .renderCommandList = Entity_Padlock_RenderScript,
244 .modelAnimationNodes = 0,
245 .fpInit = entity_Padlock_init,
246 .updateEntityScript = Entity_Padlock_Script,
247 .fpHandleCollision = NULL,
248 { .dma = ENTITY_ROM(Padlock) },
249 .entityType = ENTITY_TYPE_PADLOCK,
250 .aabbSize = { 30, 175, 10 }
251};
252
255 .typeDataSize = sizeof(PadlockData),
256 .renderCommandList = Entity_PadlockRedFrame_RenderScript,
257 .modelAnimationNodes = 0,
259 .updateEntityScript = Entity_Padlock_Script,
260 .fpHandleCollision = NULL,
261 { .dma = ENTITY_ROM(PadlockRedFrame) },
262 .entityType = ENTITY_TYPE_PADLOCK_RED_FRAME,
263 .aabbSize = { 30, 175, 10 }
264};
265
268 .typeDataSize = sizeof(PadlockData),
269 .renderCommandList = Entity_PadlockRedFace_RenderScript,
270 .modelAnimationNodes = 0,
272 .updateEntityScript = Entity_Padlock_Script,
273 .fpHandleCollision = NULL,
274 { .dma = ENTITY_ROM(PadlockRedFace) },
275 .entityType = ENTITY_TYPE_PADLOCK_RED_FACE,
276 .aabbSize = { 30, 175, 10 }
277 };
278
281 .typeDataSize = sizeof(PadlockData),
282 .renderCommandList = Entity_PadlockBlueFace_RenderScript,
283 .modelAnimationNodes = 0,
285 .updateEntityScript = Entity_Padlock_Script,
286 .fpHandleCollision = NULL,
287 { .dma = ENTITY_ROM(PadlockBlueFace) },
288 .entityType = ENTITY_TYPE_PADLOCK_BLUE_FACE,
289 .aabbSize = { 30, 175, 10 }
290};
struct PadlockData * padlock
Mtx matrixStack[0x200]
f32 Matrix4f[4][4]
Gfx Entity_Padlock_RenderShackle[]
Definition Padlock.c:77
EntityScript Entity_Padlock_Script
Definition Padlock.c:229
void entity_PadlockBlueFace_init(Entity *entity)
Definition Padlock.c:220
EntityBlueprint Entity_PadlockBlueFace
Definition Padlock.c:279
void entity_Padlock_push_player(Entity *entity)
Definition Padlock.c:51
EntityBlueprint Entity_Padlock
Definition Padlock.c:240
Gfx Entity_PadlockBlueFace_Render[]
EntityBlueprint Entity_PadlockRedFace
Definition Padlock.c:266
EntityModelScript Entity_PadlockRedFrame_RenderScript
Definition Padlock.c:236
void entity_Padlock_setupGfx(s32 entityIndex)
Definition Padlock.c:20
EntityModelScript Entity_Padlock_RenderScript
Definition Padlock.c:235
void entity_Padlock_init(Entity *entity)
Definition Padlock.c:193
void entity_PadlockRedFace_init(Entity *entity)
Definition Padlock.c:211
Gfx Entity_PadlockBlueFace_RenderShackle[]
Gfx Entity_PadlockRedFace_RenderShackle[]
EntityModelScript Entity_PadlockRedFace_RenderScript
Definition Padlock.c:237
Gfx Entity_PadlockRedFace_Render[]
EntityBlueprint Entity_PadlockRedFrame
Definition Padlock.c:253
Gfx Entity_PadlockRedFrame_Render[]
Gfx Entity_PadlockRedFrame_RenderShackle[]
Mtx Entity_PadlockRedFrame_mtxShackle
void entity_PadlockRedFrame_init(Entity *entity)
Definition Padlock.c:202
Mtx Entity_PadlockRedFace_mtxShackle
Mtx Entity_PadlockBlueFace_mtxShackle
void entity_Padlock_idle(Entity *entity)
Definition Padlock.c:83
Gfx Entity_Padlock_Render[]
Definition Padlock.c:167
EntityModelScript Entity_PadlockBlueFace_RenderScript
Definition Padlock.c:238
Mtx Entity_Padlock_mtxShackle
Definition Padlock.c:54
#define guRotateF
#define guMtxF2L
#define guTranslateF
#define guMtxCatF
#define guScaleF
@ FX_SPARKLES_0
Definition effects.h:234
s32 EntityModelScript[]
Definition entity.h:7
f32 pushSpeed
Definition entity.h:254
#define STANDARD_ENTITY_MODEL_SCRIPT(gfx, renderMode)
Definition entity.h:56
Gfx * shackleGfx
Definition entity.h:263
#define ENTITY_ADDR(entity, type, data)
Definition entity.h:64
#define es_SetCallback(func, time)
Definition entity.h:38
#define es_SetFlags(flags)
Definition entity.h:43
#define ENTITY_ROM(name)
Definition entity.h:65
u8 blinkCounter
Definition entity.h:258
f32 fallSpeed
Definition entity.h:256
s32 EntityScript[]
Definition entity.h:6
#define es_End
Definition entity.h:35
f32 rotSpeed
Definition entity.h:257
Mtx * shackleMtx
Definition entity.h:262
f32 shacklePos
Definition entity.h:255
@ ENTITY_TYPE_PADLOCK
Definition enums.h:2546
@ ENTITY_TYPE_PADLOCK_RED_FACE
Definition enums.h:2548
@ ENTITY_TYPE_PADLOCK_RED_FRAME
Definition enums.h:2547
@ ENTITY_TYPE_PADLOCK_BLUE_FACE
Definition enums.h:2549
@ ENTITY_COLLISION_PLAYER_TOUCH_FLOOR
Definition enums.h:2648
@ SOUND_USE_KEY
Definition enums.h:983
@ SOUND_LOCK_DROP
Definition enums.h:984
@ RENDER_MODE_SURFACE_OPA
Definition enums.h:3264
@ ENTITY_FLAG_HAS_SHADOW
Definition enums.h:2621
@ ENTITY_FLAG_400
Definition enums.h:2623
@ ENTITY_FLAG_SHOWS_INSPECT_PROMPT
Definition enums.h:2625
@ ENTITY_FLAG_HIDDEN
Definition enums.h:2613
@ ENTITY_FLAG_USED
Definition enums.h:2633
@ ENTITY_FLAG_PENDING_INSTANCE_DELETE
Definition enums.h:2642
@ ENTITY_FLAG_DISABLE_COLLISION
Definition enums.h:2618
Entity * get_entity_by_index(s32 index)
Definition entity.c:530
f64 fabs(f64 f)
s32 entity_start_script(Entity *entity)
Definition entity.c:560
f32 cos_rad(f32 x)
Definition 43F0.c:717
void suggest_player_anim_allow_backward(AnimID anim)
Definition 77480.c:894
void exec_entity_commandlist(Entity *entity)
Definition entity.c:313
f32 sin_rad(f32 x)
Definition 43F0.c:713
void sfx_play_sound(s32 soundID)
Definition sfx.c:517
#define DEG_TO_RAD(deg)
Definition macros.h:134
void(* renderSetupFunc)(s32)
EntityData dataBuf
Vec3f scale
u8 collisionFlags
Gfx * gMainGfxPos
Definition cam_main.c:15
u16 gMatrixListPos
Definition main_loop.c:45
PlayerStatus gPlayerStatus
Definition 77480.c:39
DisplayContext * gDisplayContext
Definition cam_main.c:16