Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
status_star_shimmer.c
Go to the documentation of this file.
1#include "common.h"
2#include "include_asset.h"
3
4INCLUDE_IMG("ui/status/shimmer_particle.png", ui_status_shimmer_particle_png);
5
7 .vp = {
8 .vscale = { 640, 480, 511, 0 },
9 .vtrans = { 640, 480, 511, 0 }
10 }
11};
12
13#include "A2B70.vtx.inc.c" // Vtx_StatusShimmer_Particle
14
15#include "A2BC0.gfx.inc.c" // Gfx_StatusShimmer_SetupTex
16#include "A2C88.gfx.inc.c" // Gfx_StatusShimmer_DrawParticle
17
18#define NUM_PARTICLES 56
19
21 40, 90, 81, 72, 65, 59, 53, 47, 43, 38, 34, 31, 28, 25, 22, 20, 18, 16, 15, 13, 12, 10, 9, 8, 7, 7, 6, 5, 5, 4
22};
23
25 { 247, 105 }, { 239, 87 }, { 17, 87 }, { 9, 105 }, { 0, 122 }, { 230, 69 }, { 26, 69 }, { 221, 52 }, { 35, 52 },
26 { 202, 49 }, { 186, 255 }, { 200, 241 }, { 0, 200 }, { 56, 241 }, { 70, 255 }, { 54, 49 }, { 196, 222 },
27 { 239, 191 }, { 17, 191 }, { 60, 222 }, { 85, 13 }, { 74, 46 }, { 99, 27 }, { 93, 43 }, { 12, 33 }, { 12, 22 },
28 { 24, 22 }, { 24, 33 }, { 12, 10 }, { 24, 10 }, { 24, 45 }, { 232, 33 }, { 232, 22 }, { 232, 45 }, { 113, 40 },
29 { 193, 203 }, { 190, 183 }, { 182, 46 }, { 163, 43 }, { 35, 182 }, { 52, 173 }, { 12, 45 }, { 244, 22 },
30 { 244, 33 }, { 232, 10 }, { 244, 10 }, { 244, 45 }, { 204, 173 }, { 221, 182 }, { 186, 164 }, { 171, 13 },
31 { 157, 27 }, { 143, 40 }, { 63, 203 }, { 66, 183 }, { 70, 164 }
32};
33
34typedef struct ShimmerParticle {
35 /* 0x00 */ u8 alive;
36 /* 0x01 */ s8 timeLeft;
37 /* 0x02 */ u8 lifetime;
38 /* 0x03 */ Color_RGBA8 rgba;
39 /* 0x07 */ s8 animTime;
40 /* 0x08 */ Vec2f pos;
41 /* 0x10 */ Vec2f vel;
42 /* 0x18 */ f32 scale;
43} ShimmerParticle; // size = 0x1C
44
45typedef struct ShimmerEmitter {
46 /* 0x00 */ ShimmerParticle particles[1 + NUM_PARTICLES]; // one dummy master + 56 actually visible ones
48
50
51void star_power_shimmer_start(s32 emitterIdx, f32 x, f32 y, f32 scale) {
52 ShimmerEmitter* emitter = &ShimmerEmitters[emitterIdx];
53 ShimmerParticle* particle = &emitter->particles[0];
54 s32 numParticles = ARRAY_COUNT(emitter->particles);
55 s32 j;
56
57 if (emitterIdx < ARRAY_COUNT(ShimmerEmitters)) {
58 particle->alive = TRUE;
59 particle->pos.x = x;
60 particle->pos.y = y;
61 particle->scale = scale;
62 particle->timeLeft = 40;
63 particle->lifetime = 0;
64 particle = &emitter->particles[1];
65
66 for (j = 1; j < numParticles; j++, particle++) {
67 particle->animTime = (s32) (-((f32) j) * 0.0f) - 1;
68 }
69 }
70}
71
73 s32 i;
74
75 for (i = 0; i < ARRAY_COUNT(ShimmerEmitters); i++) {
76 ShimmerEmitters[i].particles[0].alive = FALSE;
77 }
78}
79
81 ShimmerEmitter* emitter;
82 ShimmerParticle* particle;
83 s32 emitterTimeLeft;
84 f32 emitterX;
85 f32 emitterY;
86 s32 i, j;
87
88 for (i = 0; i < ARRAY_COUNT(ShimmerEmitters); i++, emitter++) {
89 emitter = &ShimmerEmitters[i];
90
91 if (!emitter->particles[0].alive) {
92 continue;
93 }
94
95 emitter->particles[0].timeLeft--;
96 emitter->particles[0].lifetime++;
97
98 if (emitter->particles[0].timeLeft < 0) {
99 emitter->particles[0].alive = FALSE;
100 continue;
101 }
102
103 emitterTimeLeft = emitter->particles[0].timeLeft;
104 emitterX = emitter->particles[0].pos.x;
105 emitterY = emitter->particles[0].pos.y;
106
107 particle = &emitter->particles[1];
108 for (j = 1; j < ARRAY_COUNT(emitter->particles); j++, particle++) {
109 particle->animTime++;
110 if (particle->animTime >= ARRAY_COUNT(AnimatedScale)) {
111 if (emitterTimeLeft < 30) {
112 particle->animTime = -31;
113 } else {
114 particle->animTime = 0;
115 }
116 }
117
118 if (particle->animTime < 0) {
119 continue;
120 }
121
122 if (particle->animTime == 0) {
123 f32 initialVelX = InitialVelocities[j - 1].x;
124 f32 initialVelY = InitialVelocities[j - 1].y;
125 s8 t = 127;
126
127 particle->vel.x = initialVelX * 0.1;
128 particle->vel.y = -initialVelY * 0.1;
129 particle->pos.x = emitterX;
130 particle->pos.y = emitterY;
131 particle->scale = 1.0f;
132 particle->rgba.r = rand_int(t);
133 particle->rgba.g = rand_int(t - particle->rgba.r);
134 particle->rgba.b = rand_int(t - particle->rgba.g - particle->rgba.r);
135 particle->rgba.a = 255;
136 particle->rgba.r += 128;
137 particle->rgba.g += 128;
138 particle->rgba.b += 128;
139 }
140
141 particle->pos.x += particle->vel.x;
142 particle->pos.y += particle->vel.y;
143 particle->vel.x *= 0.92;
144 particle->vel.y *= 0.92;
145 particle->scale = (f32) AnimatedScale[particle->animTime] * 0.04;
146 }
147 }
148}
149
150// draws small diamond shaped shimmer particles over the star power bar
152 Matrix4f viewMtx, transformMtx;
153 ShimmerEmitter* emitter;
154 ShimmerParticle* particle;
155 f32 emitterScale;
156 s32 i, j;
157
158 gDPPipeSync(gMainGfxPos++);
159 gSPSegment(gMainGfxPos++, 0x00, 0x00000000);
160 gDPSetScissor(gMainGfxPos++, G_SC_NON_INTERLACE, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
161 gSPViewport(gMainGfxPos++, &ShimmerViewport);
162
163 guOrthoF(viewMtx, 0.0f, SCREEN_WIDTH, SCREEN_HEIGHT, 0.0f, -100.0f, 100.0f, 1.0f);
165
166 gSPMatrix(gMainGfxPos++, &gDisplayContext->matrixStack[gMatrixListPos++], G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION);
167 gSPDisplayList(gMainGfxPos++, D_80109710); // setup texture
168 gDPSetEnvColor(gMainGfxPos++, 127, 127, 127, 127);
169
170 for (i = 0; i < ARRAY_COUNT(ShimmerEmitters); i++, emitter++) {
171 emitter = &ShimmerEmitters[i];
172
173 if (emitter->particles[0].alive) {
174 emitterScale = emitter->particles[0].scale;
175
176 particle = &emitter->particles[1];
177 for (j = 1; j < ARRAY_COUNT(emitter->particles); j++, particle++) {
178 if (particle->animTime >= 0) {
179 guPositionF(transformMtx, 0.0f, 0.0f, gGameStatusPtr->frameCounter * 10, particle->scale * emitterScale,
180 particle->pos.x, particle->pos.y, 0.0f);
182
184 G_MTX_PUSH | G_MTX_MUL | G_MTX_MODELVIEW);
185 gDPSetPrimColor(gMainGfxPos++, 0, 80 - particle->animTime, particle->rgba.r, particle->rgba.g, particle->rgba.b, particle->rgba.a);
186 gSPDisplayList(gMainGfxPos++, D_801097D8); // draw particle
187 gSPPopMatrix(gMainGfxPos++, G_MTX_MODELVIEW);
188 }
189 }
190 }
191 }
192}
Mtx matrixStack[0x200]
f32 Matrix4f[4][4]
#define guOrthoF
#define guMtxF2L
#define rand_int
#define guPositionF
#define INCLUDE_IMG(FILENAME, SYMBOLNAME)
#define SCREEN_WIDTH
Definition macros.h:109
#define BSS
Definition macros.h:7
#define ARRAY_COUNT(arr)
Definition macros.h:40
#define SCREEN_HEIGHT
Definition macros.h:110
u8 AnimatedScale[]
Vec2b InitialVelocities[56]
void star_power_shimmer_update(void)
#define NUM_PARTICLES
Vp ShimmerViewport
BSS ShimmerEmitter ShimmerEmitters[1]
void star_power_shimmer_init(void)
ShimmerParticle particles[1+56]
void star_power_shimmer_draw(void)
void star_power_shimmer_start(s32 emitterIdx, f32 x, f32 y, f32 scale)
GameStatus * gGameStatusPtr
Definition main_loop.c:32
Gfx * gMainGfxPos
Definition cam_main.c:15
u16 gMatrixListPos
Definition main_loop.c:45
DisplayContext * gDisplayContext
Definition cam_main.c:16