Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
BoardedFloor.c
Go to the documentation of this file.
1#include "common.h"
2#include "ld_addrs.h"
3#include "entity.h"
4
5extern Gfx Entity_RenderNone[];
8
10
11void Entity_BoardedFloor_init_fragments(Entity* entity, Gfx** dlists, Mtx* matrices) {
13 Matrix4f mtxFragment;
14 Matrix4f mtxTrans;
15 s32 i;
16 s32 rotationSpeed;
17
18 data->fragmentsGfx = ENTITY_ADDR(entity, Gfx**, dlists);
20 entity->alpha = 255;
21 entity->pos.y = data->inititalY;
22 guTranslateF(mtxTrans, entity->pos.x, entity->pos.y, entity->pos.z);
23
24 for (i = 0; i < FRAGMENT_BUF_SIZE - 1; i++) {
25 guMtxL2F(mtxFragment, ENTITY_ADDR(entity, Mtx*, matrices++));
26 guMtxCatF(mtxTrans, mtxFragment, mtxFragment);
27 data->fragmentPosX[i] = mtxFragment[3][0];
28 data->fragmentPosY[i] = mtxFragment[3][1];
29 data->fragmentPosZ[i] = mtxFragment[3][2];
30 data->fragmentMoveAngle[i] = -rand_int(255);
31 data->fragmentLateralSpeed[i] = 20;
32
33 rotationSpeed = rand_int(5);
34 if (i % 2 != 0) {
35 data->fragmentRotSpeed[i] = rotationSpeed + 10;
36 } else {
37 data->fragmentRotSpeed[i] = -10 - rotationSpeed;
38 }
39
40 data->fragmentFallSpeed[i] = 10.0f;
41 data->fragmentRebounds[i] = 0;
42 data->fragmentRotX[i] = 0;
43 data->fragmentRotY[i] = 0;
44 }
45}
46
51
54 f32 rotSpeed, lateralSpeed, reboundSpeed;
55 f32 moveAngle, yawRad;
56 s32 i;
57 s32 numFragmentsDisappeared;
58 f32 hitX, hitY, hitZ, hitDepth;
59
60 numFragmentsDisappeared = 0;
61 rotSpeed = 0.0f;
62 reboundSpeed = 0.0f;
63 lateralSpeed = 0.0f;
64
65 for (i = 0; i < 12; i++) {
66 switch (data->fragmentRebounds[i]) {
67 case 0:
68 reboundSpeed = 2.0f;
69 rotSpeed = data->fragmentRotSpeed[i];
70 lateralSpeed = data->fragmentLateralSpeed[i] / 10.0f;
71 if (rotSpeed >= 0.0f) {
72 data->fragmentRotSpeed[i] = rotSpeed - 0.4;
73 } else {
74 data->fragmentRotSpeed[i] = rotSpeed + 0.5;
75 }
76 break;
77 case 1:
78 lateralSpeed = 1.0f;
79 reboundSpeed = 0.0f;
80 rotSpeed = data->fragmentRotSpeed[i] * 0.25f;
81 break;
82 case 2:
83 data->fragmentRotSpeed[i] += 1.0f;
84 if (data->fragmentRotSpeed[i] > 20.0f) {
85 data->fragmentRotSpeed[i] = 20.0f;
86 }
87
88 data->fragmentPosY[i] -= data->fragmentRotSpeed[i] / 70.0f;
89
90 data->fragmentMoveAngle[i] -= 5;
91 if (data->fragmentMoveAngle[i] <= 5) {
92 data->fragmentMoveAngle[i] = 0;
93 data->fragmentRebounds[i]++;
94 }
95 break;
96 case 3:
97 numFragmentsDisappeared++;
98 break;
99 }
100
101 if (data->fragmentRebounds[i] < 2) {
102 if (data->fragmentFallSpeed[i] >= 0.0f) {
103 data->fragmentFallSpeed[i] -= 0.8;
104 if (data->fragmentFallSpeed[i] < -10.2) {
105 data->fragmentFallSpeed[i] = -10.2f;
106 }
107 } else {
108 data->fragmentFallSpeed[i] -= 1.6;
109 if (data->fragmentFallSpeed[i] < -10.2) {
110 data->fragmentFallSpeed[i] = -10.2f;
111 }
112 }
113
114 data->fragmentPosY[i] += data->fragmentFallSpeed[i];
115 yawRad = data->fragmentMoveAngle[i] * 360.0f / 256;
116 moveAngle = DEG_TO_RAD(yawRad);
117 data->fragmentPosX[i] += lateralSpeed * sin_rad(moveAngle);
118 data->fragmentPosZ[i] += lateralSpeed * cos_rad(moveAngle);
119
120 hitX = data->fragmentPosX[i];
121 hitY = data->fragmentPosY[i];
122 hitZ = data->fragmentPosZ[i];
123 if (npc_test_move_taller_with_slipping(COLLISION_IGNORE_ENTITIES, &hitX, &hitY, &hitZ, lateralSpeed, yawRad, 8.0f, 8.0f)) {
124 data->fragmentPosX[i] = hitX;
125 data->fragmentPosY[i] = hitY;
126 data->fragmentPosZ[i] = hitZ;
127 data->fragmentMoveAngle[i] += 0x80; // inverse yaw
128
129 moveAngle = DEG_TO_RAD(data->fragmentMoveAngle[i] * 360.0f / 256);
130 lateralSpeed = 8.0f;
131 data->fragmentPosX[i] += lateralSpeed * sin_rad(moveAngle);
132 data->fragmentPosZ[i] += lateralSpeed * cos_rad(moveAngle);
133
134 }
135
136 hitX = data->fragmentPosX[i];
137 hitY = data->fragmentPosY[i];
138 hitZ = data->fragmentPosZ[i];
139 hitDepth = fabsf(data->fragmentFallSpeed[i]);
140 if (npc_raycast_down_sides(COLLISION_IGNORE_ENTITIES, &hitX, &hitY, &hitZ, &hitDepth) || hitY < data->inititalY - 200.0f) {
141 data->fragmentRebounds[i]++;
142 data->fragmentPosY[i] = hitY + fabsf(data->fragmentFallSpeed[i]);
143 data->fragmentFallSpeed[i] = reboundSpeed;
144 if (data->fragmentRebounds[i] == 2) {
145 data->fragmentMoveAngle[i] = 254;
146 data->fragmentRotSpeed[i] = 0.0f;
147 }
148 }
149
150 data->fragmentRotX[i] += rotSpeed;
151 data->fragmentRotY[i] -= rotSpeed;
152 }
153 }
154
155 if (numFragmentsDisappeared >= 12) {
157 }
158}
159
160void Entity_BoardedFloor_setupGfx(s32 entityIndex) {
161 s32 i;
162 Matrix4f mtxTransInv;
163 Matrix4f mtx;
164 Matrix4f mtxRotX;
165 Matrix4f mtxRotY;
166 f32 x_inv;
167 f32 y_inv;
168 f32 z_inv;
169 Gfx* gfxPos = gMainGfxPos;
170 Entity* entity = get_entity_by_index(entityIndex);
171 BoardedFloorData* data = entity->dataBuf.boardedFloor;
172 Gfx* fragmentDlist;
173 Gfx** gfx = data->fragmentsGfx;
174
175 x_inv = -entity->pos.x;
176 y_inv = -entity->pos.y;
177 z_inv = -entity->pos.z;
178
179 for (i = 0; i < 12; i++) {
180 if (data->fragmentRebounds[i] < 2) {
181 gDPSetRenderMode(gfxPos++, G_RM_AA_ZB_OPA_SURF, G_RM_AA_ZB_OPA_SURF2);
182 gDPSetCombineMode(gfxPos++, G_CC_MODULATEIA, G_CC_MODULATEIA);
183 } else {
184 gDPSetCombineMode(gfxPos++, PM_CC_11, PM_CC_12);
185 gDPSetPrimColor(gfxPos++, 0, 0, 0, 0, 0, data->fragmentMoveAngle[i]);
186 }
187
188 guTranslateF(mtxTransInv, x_inv, y_inv, z_inv);
189 guRotateF(mtxRotX, data->fragmentRotX[i] * 360.0f / 256, 1.0f, 0.0f, 0.0f);
190 guRotateF(mtxRotY, data->fragmentRotY[i] * 360.0f / 256, 0.0f, 1.0f, 0.0f);
191 guMtxCatF(mtxRotX, mtxRotY, mtxRotY);
192 guMtxCatF(mtxRotY, mtxTransInv, mtxTransInv);
193 guTranslateF(mtx, data->fragmentPosX[i], data->fragmentPosY[i], data->fragmentPosZ[i]);
194 guMtxCatF(mtxTransInv, mtx, mtx);
196
197 gSPMatrix(gfxPos++, &gDisplayContext->matrixStack[gMatrixListPos++], G_MTX_PUSH | G_MTX_MUL | G_MTX_MODELVIEW);
198 fragmentDlist = ENTITY_ADDR(entity, Gfx*, *gfx++);
199 gSPDisplayList(gfxPos++, fragmentDlist);
200 gSPPopMatrix(gfxPos++, G_MTX_MODELVIEW);
201 }
202
203 gMainGfxPos = gfxPos;
204}
205
207 PlayerStatus* playerStatus = &gPlayerStatus;
208
210 if (playerStatus->actionState == ACTION_STATE_SPIN_POUND
211 || playerStatus->actionState == ACTION_STATE_TORNADO_POUND) {
212 entity_start_script(entity);
214 }
215 }
216}
217
220
222 BoardedFloorData* data = entity->dataBuf.boardedFloor;
223 s32 i;
224
225 for (i = 0; i < 12; i++) {
226 data->fragmentPosY[i] += 1.0f;
227 }
228
230}
231
243
245 .flags = 0,
246 .typeDataSize = sizeof(BoardedFloorData),
247 .renderCommandList = Entity_BoardedFloor_RenderScript,
248 .modelAnimationNodes = 0,
249 .fpInit = Entity_BoardedFloor_init,
250 .updateEntityScript = Entity_BoardedFloor_Script,
251 .fpHandleCollision = NULL,
252 { .dma = ENTITY_ROM(BoardedFloor) },
253 .entityType = ENTITY_TYPE_BOARDED_FLOOR,
254 .aabbSize = { 60, 5, 60 }
255};
struct BoardedFloorData * boardedFloor
Mtx matrixStack[0x200]
f32 Matrix4f[4][4]
void Entity_BoardedFloor_init(Entity *entity)
void Entity_BoardedFloor_shatter(Entity *entity)
Mtx Entity_BoardedFloor_FragmentMatrices[]
void Entity_BoardedFloor_idle(Entity *entity)
EntityModelScript Entity_BoardedFloor_Script
Gfx * Entity_BoardedFloor_FragmentsRender[]
EntityModelScript Entity_BoardedFloor_RenderScriptShattered
EntityModelScript Entity_BoardedFloor_RenderScript
void Entity_BoardedFloor_setupGfx(s32)
EntityBlueprint Entity_BoardedFloor
void Entity_BoardedFloor_update_fragments(Entity *entity)
Gfx Entity_RenderNone[]
Definition Shadow.c:69
void Entity_BoardedFloor_init_fragments(Entity *entity, Gfx **dlists, Mtx *matrices)
#define guRotateF
#define npc_raycast_down_sides
#define guMtxF2L
#define guTranslateF
#define guMtxCatF
#define rand_int
f32 fragmentRotSpeed[13]
Definition entity.h:276
s32 EntityModelScript[]
Definition entity.h:7
#define es_Call(func)
Definition entity.h:37
#define FRAGMENT_BUF_SIZE
Definition entity.h:266
#define STANDARD_ENTITY_MODEL_SCRIPT(gfx, renderMode)
Definition entity.h:56
#define ENTITY_ADDR(entity, type, data)
Definition entity.h:64
u8 fragmentLateralSpeed[13]
Definition entity.h:275
#define es_SetCallback(func, time)
Definition entity.h:38
#define es_SetFlags(flags)
Definition entity.h:43
f32 fragmentPosZ[13]
Definition entity.h:279
u8 fragmentMoveAngle[13]
Definition entity.h:272
#define ENTITY_ROM(name)
Definition entity.h:65
Gfx ** fragmentsGfx
Definition entity.h:269
f32 fragmentPosX[13]
Definition entity.h:277
#define es_End
Definition entity.h:35
s8 fragmentRebounds[13]
Definition entity.h:271
f32 fragmentPosY[13]
Definition entity.h:278
#define es_PlaySound(soundId)
Definition entity.h:45
#define es_ClearFlags(flags)
Definition entity.h:44
u8 fragmentRotY[13]
Definition entity.h:274
u8 fragmentRotX[13]
Definition entity.h:273
f32 fragmentFallSpeed[13]
Definition entity.h:280
void entity_set_render_script(Entity *entity, EntityModelScript *cmdList)
Definition entity.c:761
@ COLLISION_IGNORE_ENTITIES
Definition enums.h:4698
@ ENTITY_TYPE_BOARDED_FLOOR
Definition enums.h:2580
@ ENTITY_COLLISION_PLAYER_TOUCH_FLOOR
Definition enums.h:2648
@ SOUND_BREAK_FLOOR
Definition enums.h:1438
@ RENDER_MODE_SURFACE_OPA
Definition enums.h:3264
@ RENDER_MODE_SURFACE_XLU_LAYER1
Definition enums.h:3282
@ ENTITY_FLAG_HIDDEN
Definition enums.h:2613
@ ENTITY_FLAG_PENDING_INSTANCE_DELETE
Definition enums.h:2642
@ ENTITY_FLAG_DISABLE_COLLISION
Definition enums.h:2618
@ ACTION_STATE_SPIN_POUND
Definition enums.h:2442
@ ACTION_STATE_TORNADO_POUND
Definition enums.h:2444
Entity * get_entity_by_index(s32 index)
Definition entity.c:530
f32 fabsf(f32 f)
s32 entity_start_script(Entity *entity)
Definition entity.c:560
f32 cos_rad(f32 x)
Definition 43F0.c:717
b32 npc_test_move_taller_with_slipping(s32, f32 *, f32 *, f32 *, f32, f32, f32, f32)
void exec_entity_commandlist(Entity *entity)
Definition entity.c:313
f32 sin_rad(f32 x)
Definition 43F0.c:713
#define PM_CC_11
Definition macros.h:294
#define DEG_TO_RAD(deg)
Definition macros.h:134
#define PM_CC_12
Definition macros.h:295
void(* renderSetupFunc)(s32)
EntityData dataBuf
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