Alchemy
Loading...
Searching...
No Matches

undead_sword.c

Go to the documentation of this file.
1/// @file
2/// Undead Sword.
3/// Part of effect.c, the battle effect object, compiled only through it.
4
6
7/// The blast sheet's seven spark pictures, after the lime column's 14x80
8/// picture.
9#define UNDEAD_SWORD_SPARK_SHEET (14 * 80)
10
11/// Two mirrored columns of light rise at the first target's feet and sink
12/// again, scattering 16 sparks that drift upward; the target is struck on frame
13/// 10.
14///
15/// Abilities: Undead Sword (kind 320).
16///
17/// 54 frames. BG2 is moved so that the canvas's centre line stands on the
18/// target. The sparks are work->particles 0 to 15, variant their age in
19/// frames.
21 void **slots;
22 void **cursor;
23 struct BattleEffectWork *work;
24 void *canvas;
25 void *sprites;
26 DrawRectangle draw[2];
27 struct EffectPosition screenPosition;
28 struct EffectStep *spark;
29 struct EffectStep *particle;
30 s32 frame;
31 s32 i;
32 s32 height;
33 s32 mode;
34 s32 x;
35 u8 *src;
36 s32 speed;
37 s32 angle;
38 s32 cell;
39 s32 size;
40
41 EFFECT_GET_SLOTS(slots, cursor, work, canvas);
42 work->effect = effect;
47 1);
49 work->sheet + UNDEAD_SWORD_SPARK_SHEET, 1, 0);
52
53 // Shift BG2 so that canvas x 64 lines up with the target.
54 EffectPosition_ProjectBattler(work->effect->actors[0], &screenPosition);
55 REG_BG2X = (64 - screenPosition.x) << 8;
56
57 // Scatter sparks in all directions from (64, 112), then drift upward; each
58 // starts 0 to 7 frames old, so they die at different times.
59 for (i = 0, spark = work->particles; i != 16; i++) {
60 speed = (Random16() & 0x1ff) + 128;
61 angle = Random16() & 0xffff;
62 spark->x = 0x400000;
63 spark->y = 0x700000;
64 spark->velocityX = (Trig_Sin(angle) * speed) >> 8;
65 spark->velocityY = (Trig_Cos(angle) * speed) >> 9;
66 spark->variant = Random16() & 7;
67 spark++;
68 }
69 work->shakeFrames = 8;
70 for (frame = 0; frame != 54; frame++) {
71 // Frame 10: the strike, with a second 8-frame shake.
72 if (frame == 10) {
73 work->shakeFrames = 8;
77 POSE_DAMAGE, 0, 8);
78 }
79
80 // The columns grow 12 pixels a frame from frame 8 and shrink 6 a frame
81 // after frame 31, held at 80 pixels between. Held, they are drawn
82 // brightest-wins, otherwise additive; each half builds its own blitter
83 // and releases it at once.
84 if (frame > 7) {
85 if (frame <= 31)
86 height = frame * 12 - 96;
87 else
88 height = 272 - frame * 6;
89 if (height > 0) {
90 if (height > 80) {
91 height = 80;
92 mode = COMPOSITE_MAX;
93 } else {
94 mode = COMPOSITE_ADDITIVE;
95 }
96 for (i = 0, x = 50; i != 2; i++, x += 14) {
97 if (i == 0)
99 else
104 canvas, work->sheet, x, 112 - height, 14, height);
106 }
107 }
108 }
109
110 // Two more sparks start each frame from frame 8; each advances to the
111 // next of seven pictures every three frames and drifts upward until it is
112 // 29 frames old. The blitters are fetched and released each frame, as the
113 // columns took the slot.
115 for (i = 0, particle = work->particles; i != 16; i++) {
116 if (frame >= i / 2 + 8 && particle->variant <= 28) {
117 s32 px;
118 s32 py;
119
120 cell = particle->variant / 3;
121 px = Q_16_16_TO_INT(particle->x);
122 py = Q_16_16_TO_INT(particle->y);
123 if (cell > 6)
124 cell = 6;
125 src = work->sheet + gUndeadSword_SparkCells[cell] +
127 size = gUndeadSword_SparkSizes[cell];
128 draw[0](canvas, src, px - size / 2, py - size / 2, size, size);
129 particle->variant++;
130 EffectStep_AdvanceWithGravity2D(particle, 62, -0x2000);
131 }
132 particle++;
133 }
135 if (frame <= 7)
136 Camera_ApplyShake(2, 2);
137 else
138 Camera_ApplyShake(16, 16);
139 EFFECT_END_FRAME(work);
140 }
143}
144
145#undef UNDEAD_SWORD_SPARK_SHEET
@ SPRITE_COLOR_WHITE
solid colour 15, white
Definition animspr.h:26
@ POSE_DAMAGE
taking damage
Definition battle.h:176
@ COMPOSITE_FLIP_X
@ COMPOSITE_ADDITIVE
@ COMPOSITE_MAX
BattleEffectDrawRectangle DrawRectangle
void BattleFx_ProcessPendingGraphicsTransfer(void)
Copies the canvas to VRAM once the effect has finished drawing a frame (transferPending): the 128x128...
Definition canvas.c:103
void BattleFx_EndCanvasLayer(void)
Closes the canvas layer: plays the closing sound, restores BG1's scroll and the projection centre,...
Definition canvas.c:490
void Resource_LoadAndDecompress(s32 id, void *dst, s32 skipPalette, s32 copyPalette)
Decompresses a resource whose first 128 bytes may be a palette.
void ObjectGroup_UpdateMembers(s32 actorId, s32 palette, s32 animation, s32 timerSlot, s32 timerFrames)
Updates every animation group of one battler's object.
Definition dispatch.c:254
What every part of the battle effect object shares: its includes, macros and frame-loop helpers.
#define EFFECT_RELEASE_BLITTERS()
Frees the two blitters, the alternate first.
@ CANVAS_COPY_AND_FADE
copy, keeping 50% or 75% (transferValue) of each pixel in the canvas for the next frame
#define EFFECT_SHOW_DAMAGE(hitSound)
Lets the battle show the damage: resumes its paused playback, which plays hitSound (an SE_ id; 0 keep...
#define EFFECT_START_TRANSFER(work, mode, value)
Sets the transfer, then starts copying the canvas to VRAM once a frame.
#define EFFECT_LOAD_BLITTER(slot, flags, mode)
Builds a blitter for the 128x128 canvas (1 << 7 pixels each way) in work slot slot: BattleFx_BuildBli...
#define EFFECT_GET_SLOTS(slots, cursor, work, canvas)
Starts at the effect's entry in the whole work-slot array.
#define EFFECT_END_FRAME(work)
The usual end of an effect frame: counts down the targets' flash timers (ObjectGroup_TickMemberTimers...
#define EFFECT_BEGIN_NARROW_CANVAS(bgControl)
Opens the canvas layer at the canvas's own width, one texel per pixel, where BattleFx_BeginCanvasLaye...
u16 gUndeadSword_SparkSizes[]
u16 gUndeadSword_SparkCells[]
void BattleMotion_ApplyVariantMotionFar(s32 id, s32 variant)
s32 Trig_Cos(s32 angle)
s32 Trig_Sin(s32 angle)
void Camera_ApplyShake(s32 rangeX, u32 rangeY)
Shakes the battle view while gBattleFxWork's shakeFrames lasts, moving BG1 and the projection centre ...
Definition hail.c:364
@ HEAP_SLOT_BATTLE_EFFECT
Definition heap_state.h:42
@ HEAP_SLOT_BATTLE_SHEET
Definition heap_state.h:44
@ HEAP_SLOT_BLITTER
Definition heap_state.h:46
#define REG_BG2X
Definition io_reg.h:65
u32 Random16(void)
Advances the game's random number generator (the C library's classic linear congruential one),...
Definition math.c:10
void Runtime_ReleaseHeapBlock(s32 slot)
void BattleFx_FetchRectangleBlitters(s32 flip, BlitterPair out)
Builds the two usual routines that draw onto the 128x128 canvas, both clipped on both axes.
void EffectPosition_ProjectBattler(s32 id, struct EffectPosition *position)
The screen position of a battler, 16 pixels higher.
Definition positions.c:100
void EffectStep_AdvanceWithGravity2D(struct EffectStep *step, s32 damping, s32 gravity)
Moves a particle one frame on the screen: adds its velocity, then gravity to its vertical speed,...
Definition positions.c:46
char ResourceId_BlastSheet
char ResourceId_LimeColumnSheet
char ResourceId_ParticleSpritesA
s32 Scheduler_RemoveCallback(SchedulerCallback callback)
Unschedules the task running callback: clears its routine and gives it order 0x7fff,...
Definition scheduler.c:146
#define SE_212
Definition songs.h:207
void * gWorkSlot[]
The command shared by an effect's caller, dispatcher and handlers.
s32 side
1 when the targets are the party, 0 for enemies
s16 actors[8]
the targets' unit ids, count of them
The running battle effect's work: its canvas image, 64 particles, the display registers it stages and...
s32 shakeFrames
shake frames left; Camera_ApplyShake counts down
struct BattleEffectArgument * effect
the command being run
struct EffectStep particles[64]
free while variant is -1
A point projected onto the screen, with its depth.
Definition effect_step.h:46
s32 x
screen pixels
Definition effect_step.h:58
A moving point of an effect: its position, its velocity and a value each effect uses its own way (a s...
Definition effect_step.h:13
s32 velocityX
16.16 fixed-point pixels per frame
Definition effect_step.h:28
s32 variant
each effect's own: a size, a countdown, -1 for idle
Definition effect_step.h:31
s32 x
16.16 fixed-point pixels
Definition effect_step.h:24
s32 y
16.16 fixed-point pixels
Definition effect_step.h:25
s32 velocityY
16.16 fixed-point pixels per frame
Definition effect_step.h:29
signed int s32
Definition types.h:14
unsigned char u8
Definition types.h:11
#define UNDEAD_SWORD_SPARK_SHEET
The blast sheet's seven spark pictures, after the lime column's 14x80 picture.
Definition undead_sword.c:9
void BattleFx_RunUndeadSword(struct BattleEffectArgument *effect)
Two mirrored columns of light rise at the first target's feet and sink again, scattering 16 sparks th...
#define EFFECT_CLIP_BOUNDS
Clips overflow on all four sides.
Definition effect.h:224
#define Q_16_16_TO_INT(v)
Definition effect.h:231