Alchemy
Loading...
Searching...
No Matches

jupiter.c

Go to the documentation of this file.
1/// @file
2/// A Jupiter Djinni joining the party.
3/// Part of psynergy_effects.c, compiled only through it.
4
6
7/// A Jupiter Djinni joins the party: it bounces three times, spins, leaps out
8/// of sight and bursts into 24 light particles that circle and close in on
9/// the leader, who turns to the camera and plays animation 28.
11 struct EffectVector position;
12 struct MotionObject *djinni;
13 struct BattleFxScene *scene;
14 struct EffectSlot *slot;
15 s32 scale;
16 s32 remainingParticles;
17
18 djinni = (struct MotionObject *)Object_GetById(djinniId);
19 if (djinni == NULL)
20 return;
22 scene = gEffectWork;
25 Motion_SetVarCbAndRefresh(djinniId, 1);
27 Motion_SetVarCbAndRefresh(djinniId, 1);
29 Motion_SetVarCbAndRefresh(djinniId, 1);
30 WaitFrames(20);
31
32 // Spin, then leap high.
35 WaitFrames(40);
37 ObjectMotion_Launch(djinniId, 12, 22);
38
39 // 24 light particles from where the Djinni is on screen.
40 position.x = djinni->x;
41 position.y = djinni->y;
42 position.z = djinni->z;
43 Camera_WorldToScreen(&position);
46 slot = scene->slots;
47 remainingParticles = 23;
48 do {
49 EffectSlot_Initialize(slot, 284, position.x, position.z);
53 (Random16() * 7) >> 16);
54 scale = Random16() / 3 + 0x10000; // 1.0 to 1.33
55 slot->scaleY = scale;
56 slot->scaleX = scale;
57 remainingParticles--;
58 WaitFrames(1);
59 slot++;
60 } while (remainingParticles >= 0);
61
62 // The leader turns to face south (0x4000) and plays animation 28.
63 WaitFrames(60);
65 WaitFrames(20);
67 28);
68 WaitFrames(40);
70 WaitFrames(100);
73}
74
75/// A spinning object: its angle, and at 0x64 the frames its spin has been
76/// speeding up for (BattleFx_AdvanceAngleWithRamp), read signed.
80 u8 unk08[0x5c];
82};
83
84/// Per-frame update: makes an object pulse, switching its scale between the
85/// two values of gBattleFx_PulseScales every 4 frames.
87 u8 *object = (u8 *)fieldObject;
89 u32 index = ((u32)gFrameTick >> 2) & 1;
90 u32 scale = table[index];
91 ((struct MotionObject *)object)->scaleX = scale;
92 ((struct MotionObject *)object)->scaleY = scale;
93}
94
95/// Per-frame update: spins an object ever faster, from 1/16 turn a frame up to
96/// 1/8.
98 void *obj = (void *)fieldObject;
99 struct RampedSpinObject *spin = obj;
100 u32 step;
101
102 step = spin->rampFrames * 0x50;
103 spin->angle = spin->angle + step + 0x1000;
104 if (step < 0x1000U) {
105 spin->rampFrames = spin->rampFrames + 1;
106 }
107}
108
109/// Spins and shrinks an object by 0x1c0 a frame, then releases it.
111
112/// Effect slot callback of a Mars Djinni's sparks. States 0 and 1 repeat: the
113/// spark flies 120 pixels up the screen (give or take 3/32 turn) from its
114/// origin and starts over. Set to 2, it stops where it arrives; 40 frames
115/// later, states 3 and 4 swarm it round a point 20 pixels over the leader.
116/// Set to 5, it is freed once it arrives.
118 struct Object *owner;
119 struct EffectVector position;
120 s32 state;
121
123 state = effect->state;
124
125 if (state == 0) {
126 effect->x = effect->originX;
127 effect->z = effect->originZ;
128 position.x = effect->x;
129 position.z = effect->z;
130 Vector_AddPolarOffset(0x780000,
131 ((Random16() * 3 << 11) >> 16) -
132 ((Random16() * 3 << 11) >> 16) + 0xc000,
133 &position);
134 effect->targetX = position.x;
135 effect->targetZ = position.z;
136 effect->acceleration = 0x50000;
137 effect->maxSpeed = 0x50000;
138 effect->limitTurnStep = state;
139 effect->state++;
140
141 ((struct AnimationObject *)effect->object)->image.priority =
142 owner->sprite->image.priority;
143 effect->flags = 0;
144 effect->age = 0;
145 if ((gFrameTick & 1) != 0)
147 } else if (state == 1) {
148 if ((s16)effect->age == 3) {
149 ((struct AnimationObject *)effect->object)->image.priority = 0;
150 effect->flags = 4;
151 }
152 if (EffectSlot_HasPendingTarget(effect) == 0)
153 effect->state--;
154 } else if (state == 2) {
155 if (EffectSlot_HasPendingTarget(effect) == 0) {
156 effect->originX = effect->x;
157 effect->originZ = effect->z;
158 ((struct AnimationObject *)effect->object)->image.priority = 0;
159 effect->flags = 4;
160 effect->render = 0;
161 effect->state++;
162 effect->callbackDelay = 40;
163 }
164 } else if (state == 3) {
165 effect->render = 1;
166 effect->x = effect->originX;
167 effect->z = effect->originZ;
168 position.x = owner->pos.x;
169 position.y = owner->pos.y + 0x140000;
170 position.z = owner->pos.z;
171 Camera_WorldToScreen(&position);
172 Vector_AddPolarOffset(0x40000, Random16(), &position);
173 effect->targetX = position.x;
174 effect->targetZ = position.z;
175 effect->state++;
176 if ((gFrameTick & 1) != 0)
178 } else if (state == 4) {
179 if (EffectSlot_HasPendingTarget(effect) == 0)
180 effect->state--;
181 } else if (state == 5) {
182 if (EffectSlot_HasPendingTarget(effect) == 0)
184 }
185}
void Motion_SetVarCbAndRefresh(u32 objectId, s32 count)
The event command "run repeated motion": as ObjectMotion_SetVariantCallback, then waits for it to end...
void ObjectMotion_Launch(u32 objectId, s32 speed, s32 frames)
The event command "actor jump": throws the actor upward at speed pixels per frame with a jump sound (...
void ObjectMotion_ArmCallback(s32 objectId, s32 angle, s32 wait)
The event command "actor face direction": the actor turns toward angle (0x10000 a full turn; ObjectMo...
struct FieldActor * Object_GetById(s32 actor)
Returns an actor, or NULL if it does not exist.
void BattleFx_InitializeSlots(void)
Allocates and clears the effect slots (heap block 56) and starts their update callback.
Definition djinni.c:261
void BattleFx_RunAngledApproachPhases(struct EffectSlot *particle)
Effect slot callback of a Jupiter Djinni's light particles: each circles its centre while it widens f...
Definition djinni.c:295
void BattleFx_AdvanceSpinAngle(union FieldObject *fieldObject)
Per-frame update: spins an object 1/8 turn a frame.
Definition djinni.c:287
void BattleFx_ClearActiveSlotsAndScheduleUpdates(void)
Stops the effect slots: removes their callback, frees every slot still in use and releases their heap...
Definition djinni.c:271
u32 EffectSlot_HasPendingTarget(struct EffectSlot *effect)
Returns nonzero while an effect slot that stops at its target still has one (it has not arrived),...
void BattleFx_ClearOwnedSlot(struct EffectSlot *slot)
Frees an effect slot and its sprite.
void EffectSlot_Initialize(struct EffectSlot *effect, s32 kind, s32 x, s32 z)
Fills an effect slot with a new sprite of kind at (x, z): stopping at its target, top speed 2,...
void EffectSlot_SetCallback(struct EffectSlot *effect, EffectCallback callback)
Gives an effect slot its per-frame callback, starting at state 0.
void EffectSlot_SetObjectMode(struct EffectSlot *effect, s32 mode)
Sets the animation of an effect slot's sprite.
void ObjectDispatch_ReleaseFar(struct DispatchObject *obj)
void ObjectDispatch_SelectAnimationFar(void *raw, s32 no)
void ObjectGroup_SetChildValueUnlessFifteenFar(void *raw_parent, u32 value)
void Shop_RestoreFieldPaletteFar(void)
void Shop_SaveAndTintFieldPaletteFar(s32 layer)
void AudioCommand_PlayFar(s32 id)
void WaitFrames(s32 frames)
The game's frame loop: runs frames frames and returns.
Definition frame.c:97
u32 gFrameTick
Counted up by every VBlank.
const u32 gBattleFx_PulseScales[3]
Two scales that alternate ((gFrameTick >> 2) & 1); nothing reads the third word.
Definition fxdata.c:440
struct GameState gGameState
void * gEffectWork
Slot 56: points to a scene-specific structure.
void BattleFx_SetObjectAlternatingWords(union FieldObject *fieldObject)
Per-frame update: makes an object pulse, switching its scale between the two values of gBattleFx_Puls...
Definition jupiter.c:86
void BattleEffect_UpdatePhasedRadialParticle(struct EffectSlot *effect)
Effect slot callback of a Mars Djinni's sparks.
Definition jupiter.c:117
void BattleFx_ShrinkObjectAndDestroySlow(union FieldObject *fieldObject)
Spins and shrinks an object by 0x1c0 a frame, then releases it.
Definition jupiter.c:110
void BattleFx_AdvanceAngleWithRamp(union FieldObject *fieldObject)
Per-frame update: spins an object ever faster, from 1/16 turn a frame up to 1/8.
Definition jupiter.c:97
void Djinn_RunJupiterJoinEffect(s32 djinniId)
A Jupiter Djinni joins the party: it bounces three times, spins, leaps out of sight and bursts into 2...
Definition jupiter.c:10
void Vector_AddPolarOffset(s32 radius, s32 angle, void *position)
Moves the point position by radius in direction angle on the ground plane: x by the cosine,...
Definition math.c:23
u32 Random16(void)
Advances the game's random number generator (the C library's classic linear congruential one),...
Definition math.c:10
void Camera_WorldToScreen(struct EffectVector *position)
Converts a world position (16.16 pixels) to the screen: x and z receive the screen's x and y and y be...
Definition setup.c:293
What every part of psynergy_effects.c shares: its includes and the macros and types more than one par...
#define DEFINE_SHRINK_AND_DESTROY(name, step)
Defines a per-frame update that spins an object 1/8 turn a frame while its scale changes by step,...
#define SE_173
Definition songs.h:168
#define SE_174
Definition songs.h:169
#define SE_164
Definition songs.h:159
#define SE_175
Definition songs.h:170
#define SE_HEAVY_IMPACT
Definition songs.h:127
#define SE_140
Definition songs.h:133
#define SE_145
Definition songs.h:138
#define SE_HIGH_JUMP
Definition songs.h:148
#define NULL
Definition bilibin.h:6
An animated sprite: its image and shadow, scale, rotation, size and up to four animation layers.
Definition animspr.h:108
struct AnimationSpritePart image
Definition animspr.h:109
u16 priority
2 when created
Definition animspr.h:100
The work of a Psynergy effect scene: its caster and target, where it takes place, the map state it re...
Definition fx_scene.h:31
struct EffectSlot slots[24]
Definition fx_scene.h:73
A field object as the object dispatcher's far calls take it.
A particle a Psynergy effect moves and draws: its sprite, its position and target,...
Definition effect_slot.h:18
s32 scaleY
16.16 fixed point, 0x10000 full size
Definition effect_slot.h:30
void * object
the slot's sprite, released with the slot
Definition effect_slot.h:19
s32 scaleX
16.16 fixed point, 0x10000 full size
Definition effect_slot.h:29
A world position, as Camera_WorldToScreen converts it to the screen.
Definition battle.h:73
s32 y
16.16 fixed-point pixels
Definition battle.h:75
s32 z
16.16 fixed-point pixels
Definition battle.h:76
s32 x
16.16 fixed-point pixels
Definition battle.h:74
s32 selectedActor
the leader: its unit and its actor
Definition game_state.h:59
An effect object that moves and draws one sprite: its position, scale, velocity and target,...
Definition motobj.h:20
s32 scaleX
16.16 fixed point, 0x10000 full size
Definition motobj.h:27
s32 z
16.16 fixed-point pixels
Definition motobj.h:25
void(*) update(union FieldObject *object)
run first each frame
Definition motobj.h:63
s32 y
16.16 fixed-point pixels
Definition motobj.h:24
s32 scaleY
16.16 fixed point, 0x10000 full size
Definition motobj.h:28
s32 x
16.16 fixed-point pixels
Definition motobj.h:23
A field actor (struct FieldActor), seen with its position as one vector.
Definition run_scene.c:389
struct EffectVector pos
Definition run_scene.c:392
struct AnimationObject * sprite
Definition run_scene.c:396
A spinning object: its angle, and at 0x64 the frames its spin has been speeding up for (BattleFx_Adva...
Definition jupiter.c:77
u8 unk08[0x5c]
Definition jupiter.c:80
signed int s32
Definition types.h:14
unsigned int u32
Definition types.h:15
signed short s16
Definition types.h:12
unsigned short u16
Definition types.h:13
unsigned char u8
Definition types.h:11
An object on the field, read as an actor or as an effect.