Alchemy
Loading...
Searching...
No Matches

mirrored_wall.c

Go to the documentation of this file.
1/// @file
2/// The walls of Berserk, Spasm and Recovery.
3/// Part of effect.c, the battle effect object, compiled only through it.
4
6
7// The canvas blitters, and the 48-frame wall effects.
8
9/// Builds the two usual routines that draw onto the 128x128 canvas, both
10/// clipped on both axes.
11///
12/// Called during setup by about twenty effect parts, from the gathering
13/// lights and the Djinn beams to the casting impacts and Ragnarok, usually
14/// with effect->side as `flip` so pictures face the targets. Builds the
15/// blitters in heap slots HEAP_SLOT_BLITTER and HEAP_SLOT_BLITTER_ALTERNATE,
16/// which the caller frees (EFFECT_RELEASE_BLITTERS).
17///
18/// flip : nonzero draws mirrored.
19/// out : [0] keeps the higher colour index, [1] adds the colours (up to 63).
21 if (flip == 0) {
27 } else {
35 }
36}
37
38/// The wall rises wide and shakes the screen hard.
39///
40/// Abilities: Berserk (kind 353).
42 BattleFx_RunMirroredWall(effect, 1);
43}
44/// The wall rises with a long gentle shake and the recovery sound.
45///
46/// Abilities: Spasm (kind 348).
48 BattleFx_RunMirroredWall(effect, 0);
49}
50/// A wide wall of fire, without a shake.
51///
52/// Abilities: Recovery (kind 389).
54 BattleFx_RunMirroredWall(effect, 2);
55}
56/// Raises a symmetrical wall (the EarthWall images) at the first target's
57/// feet for 48 frames; the target glows and the battle shows the result on
58/// frame 24.
59/// mode : 0 actual size, a gentle shake for 32 frames
60/// 1 1.25 times as wide, a hard shake for 8 frames
61/// 2 1.25 times as wide, no shake, in the Fireball colours
62///
63/// Called by BattleFx_RunBerserk, BattleFx_RunSpasm and
64/// BattleFx_RunRecovery. Loads its colours over the first 64 of the
65/// background palette, sets BG2PA and BG2X so the wall stands on the target,
66/// and sets work->shakeFrames.
68 void **cursor;
69 struct BattleEffectWork *work;
70 void *canvas;
71 u8 *palette;
72 s32 x;
73 struct EffectPosition screenPosition;
74 BlitterPair draw;
75 void **slots;
76 s32 frame;
77 s32 cell;
78
79 cursor = gBattleFxWork;
80 EFFECT_GET_WORK_AND_CANVAS(cursor, work, canvas);
81 work->effect = effect;
83
84 // Setup. The EarthWall images, coloured with the Mars Djinn palette (the
85 // Fireball palette in mode 2), each palette replacing the one before.
87 Iwram_CopyWords((void *)BG_PLTT, palette, 128);
88 palette += 128;
89 Resource_DecodeType01(palette, work->sheet);
91 Iwram_CopyWords((void *)BG_PLTT, palette, 128);
92 if (mode == 2) {
94 Iwram_CopyWords((void *)BG_PLTT, palette, 128);
95 }
96
97 // Scroll BG2 so the canvas's x 64 is on the target. Modes 1 and 2 show
98 // the canvas 1.25 times as wide, so the target's x is scaled by 4/5.
99 EffectPosition_ProjectBattler(work->effect->actors[0], &screenPosition);
100 if (mode == 0) {
101 REG_BG2PA = Q_8_8(1);
102 x = 64 - screenPosition.x;
103 REG_BG2X = x << 8;
104 } else {
105 REG_BG2PA = Q_8_8(0.8);
106 x = (-screenPosition.x * 4) / 5 + 64;
107 REG_BG2X = x << 8;
108 }
109
110 // The left half as drawn, the right half mirrored, keeping the higher
111 // colour.
113 slots = gWorkSlot;
114 draw[0] = slots[HEAP_SLOT_BLITTER];
117 draw[1] = slots[HEAP_SLOT_BLITTER_ALTERNATE];
118 // Trails keep half a frame.
120
121 // Mode 2 sets no shake but still applies Camera_ApplyShake's 16 below,
122 // which does nothing while shakeFrames is 0.
123 if (mode == 2) {
124 work->shakeFrames = 0;
126 } else if (mode == 1) {
127 work->shakeFrames = 8;
129 } else {
130 work->shakeFrames = 32;
131 }
132
133 for (frame = 0; frame != 48; frame++) {
134 // Frame loop. The target glows for 32 frames from frame 0: white in
135 // mode 2, red otherwise.
136 if (frame == 0) {
137 if (mode == 2)
139 -1, 0, 32);
140 else
142 SPRITE_COLOR_RED_TINT, -1, 0, 32);
143 }
144 if (frame == 24)
146 if (frame == 8 && mode == 0)
148
149 // Images 0, 1 and 2, four frames each, then 1 and 2 by turns, up to
150 // frame 27, standing 8 pixels below the target's feet; the trail fades
151 // after that. The left half is drawn as is, the right mirrored.
152 if (frame <= 31) {
153 cell = frame / 4;
154 if (cell > 2)
155 cell = (cell & 1) + 1;
156 if (frame <= 27) {
157 draw[0](canvas, work->sheet + gMirroredWall_Cells[cell],
158 64 - gMirroredWall_CellWidths[cell],
159 (screenPosition.y - gMirroredWall_CellHeights[cell]) + 8,
162 draw[1](canvas, work->sheet + gMirroredWall_Cells[cell], 64,
163 (screenPosition.y - gMirroredWall_CellHeights[cell]) + 8,
166 }
167 }
168 if (mode == 0)
169 Camera_ApplyShake(2, 2);
170 else
171 Camera_ApplyShake(16, 16);
172 EFFECT_END_FRAME(work);
173 }
174
176}
@ SPRITE_COLOR_WHITE
solid colour 15, white
Definition animspr.h:26
@ SPRITE_COLOR_RED_TINT
red raised to full
Definition animspr.h:28
void * gBattleFxWork[]
@ COMPOSITE_FLIP_X
@ COMPOSITE_ADDITIVE
@ COMPOSITE_MAX
BattleEffectDrawRectangle DrawRectangle
void BattleFx_BeginCanvasLayer(s32 bgControl)
Opens the canvas layer: starts the background palette fade, makes BG2 the canvas, alpha-blended over ...
Definition canvas.c:314
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.
@ CANVAS_COPY_AND_FADE
copy, keeping 50% or 75% (transferValue) of each pixel in the canvas for the next frame
#define EFFECT_GET_WORK_AND_CANVAS(cursor, work, canvas)
The work block and canvas occupy adjacent slots, starting at HEAP_SLOT_BATTLE_EFFECT.
#define EFFECT_FINISH_CANVAS()
The usual end of a canvas effect: stops the transfer callback before freeing what it reads,...
#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_END_FRAME(work)
The usual end of an effect frame: counts down the targets' flash timers (ObjectGroup_TickMemberTimers...
u16 gMirroredWall_Cells[]
u8 gMirroredWall_CellWidths[]
u8 gMirroredWall_CellHeights[]
void AudioCommand_PlayFar(s32 id)
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_BLITTER_ALTERNATE
Definition heap_state.h:47
@ HEAP_SLOT_BLITTER
Definition heap_state.h:46
#define Q_8_8(n)
The BG2/BG3 affine matrix entries are signed 8.8 fixed point: texels stepped per screen pixel.
Definition io_reg.h:59
#define REG_BG2X
Definition io_reg.h:65
#define BG_PLTT
Definition io_reg.h:157
#define REG_BG2PA
Definition io_reg.h:61
static s32 Iwram_CopyWords(volatile void *destination, const volatile void *source, s32 size)
Definition iwram_call.h:85
void BattleFx_RunRecovery(struct BattleEffectArgument *effect)
A wide wall of fire, without a shake.
void BattleFx_FetchRectangleBlitters(s32 flip, BlitterPair out)
Builds the two usual routines that draw onto the 128x128 canvas, both clipped on both axes.
void BattleFx_RunBerserk(struct BattleEffectArgument *effect)
The wall rises wide and shakes the screen hard.
void BattleFx_RunMirroredWall(struct BattleEffectArgument *effect, s32 mode)
Raises a symmetrical wall (the EarthWall images) at the first target's feet for 48 frames; the target...
void BattleFx_RunSpasm(struct BattleEffectArgument *effect)
The wall rises with a long gentle shake and the recovery sound.
void EffectPosition_ProjectBattler(s32 id, struct EffectPosition *position)
The screen position of a battler, 16 pixels higher.
Definition positions.c:100
char ResourceId_EarthWallSheet
char ResourceId_MarsDjinnSheet
char ResourceId_FireballSheet
s32 Resource_DecodeType01(const void *source, void *destination)
Decodes a type-01 resource and returns its unpacked byte count.
Definition decompress.c:31
#define SE_RECOVERY
Definition songs.h:119
#define SE_212
Definition songs.h:207
void * gWorkSlot[]
The command shared by an effect's caller, dispatcher and handlers.
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
A point projected onto the screen, with its depth.
Definition effect_step.h:46
s32 y
screen pixels
Definition effect_step.h:59
s32 x
screen pixels
Definition effect_step.h:58
void * Resource_GetTableEntry(s32 index)
Returns the ROM address of resource index from the resource directory.
Definition system.c:150
signed int s32
Definition types.h:14
unsigned char u8
Definition types.h:11
#define EFFECT_CLIP_BOUNDS
Clips overflow on all four sides.
Definition effect.h:224
DrawRectangle BlitterPair[2]
A blitter pair: [0] built in HEAP_SLOT_BLITTER and [1] in HEAP_SLOT_BLITTER_ALTERNATE (BattleFx_Fetch...
Definition effect.h:244