Digimon World 3 decomp
The European version, SLES_039.36
Loading...
Searching...
No Matches
gauge.c
Go to the documentation of this file.
1/* The gauge game */
2
3#include "field/field_mode.h"
4
5/* The cursor goes back and forth over the gauge at the game's speed */
6static inline void moveGaugeCursor(GaugeGame *task) {
7 if (task->back) {
8 task->cursor -= task->speed;
9 if (task->cursor <= 0) {
10 task->cursor = 0;
11 task->back = 0;
12 }
13 } else {
14 task->cursor += task->speed;
15 if (task->cursor >= GAUGE_CURSOR_MAX) {
17 task->back = 1;
18 }
19 }
20}
21
22/*
23 * Draws the four frames sprite (0x60-0x63) at pos, next to the player, then
24 * the gauge: its cursor, its row of cells and its frame
25 */
26static inline void drawGauge(GaugeGame *task) {
27 SpriteDrawer drawer;
28 SpriteDrawer gauge;
29 void *sprites;
30 void *gaugeSprites;
31
32 sprites = FILE_CACHE.getEntry(FIELD_SPRITES_FILE << 16);
33 initSpriteDrawer(&drawer);
34 drawer.setLayerId(FIELD_LAYER_MAP, 4);
36 drawer.draw(sprites, GFX.funcs.getTime() % 48 / 12 + 0x60, task->pos.x, task->pos.y);
37 gaugeSprites = FILE_CACHE.getEntry((FIELD_SPRITES_FILE << 16) | 1);
38 initSpriteDrawer(&gauge);
41 gauge.setFollowScroll(0);
42 gauge.draw(gaugeSprites, GAUGE_CURSOR_FRAME, (task->cursor >> 8) + GAUGE_X, GAUGE_Y);
43 gauge.draw(gaugeSprites, task->row + GAUGE_ROW_FRAMES, GAUGE_X, GAUGE_Y);
44 gauge.draw(gaugeSprites, GAUGE_FRAME, GAUGE_X, GAUGE_Y);
45}
46
47/* A gauge game: a cursor runs back and forth along one of the gauge rows until
48 * cross is pressed, then slows down and stops; the cell it stops on (2 bits)
49 * fails (0) or calls FIELDSTG_battleFuncs.startEventBattle with 4 (1) or 7 (2). In Europe the rows are
50 * random only while GAME.randomGauges lasts, then it is GAUGE_EMPTY_ROW. The match
51 * depends on the cell read and shifted as two statements. */
53 u8 cell;
54 s32 index;
55 s32 shift;
56
57 switch (task->state) {
58 case TASK_INIT:
59 default:
60#if VERSION_EU || VERSION_JP
61 if (GAME.randomGauges > 0) {
62 task->row = RANDOM.next() & (GAUGE_ROWS - 1);
64 } else {
65 task->row = GAUGE_EMPTY_ROW;
66 }
67#else
68 task->row = RANDOM.next() & (GAUGE_ROWS - 1);
69#endif
70 task->speed = 0x100;
71 task->nextState(task);
72 /* fallthrough */
73 case TASK_RUN:
74 switch (task->substate) {
75 case 0:
76 default:
77 task->step += GFX.funcs.getFrameTime();
78 if (task->step > GAUGE_START_DELAY) {
79 task->nextSubstate(task);
80 }
81 break;
82 case 1:
83 switch (task->step) {
84 case GAUGE_RUNNING:
85 default:
86 if (PAD.getPressed(0) & (1 << PAD_CROSS)) {
87 if (!(RANDOM.next() & 3)) {
88 task->setStep(task, GAUGE_STOPPING_SLOWLY);
89 } else {
90 task->setStep(task, GAUGE_STOPPING);
91 }
93 }
94 break;
95 case GAUGE_STOPPING:
96 task->speed -= 0x10;
97 if (task->speed == 0) {
98 task->setStep(task, GAUGE_STOPPED);
99 }
100 break;
102 task->speed -= 4;
103 if (task->speed == 0) {
104 task->setStep(task, GAUGE_STOPPED);
105 }
106 break;
107 case GAUGE_STOPPED:
108#if VERSION_EU || VERSION_JP
109 index = task->cursor >> 10;
110 shift = (task->cursor >> 7) & 6;
111 cell = FIELDSTG_gaugeRows[task->row][index];
112 cell = (cell >> shift) & 3;
113 if (task->counter < GAUGE_RESULT_DELAY) {
114 if (task->counter == 0 && cell == 1) {
116 }
117 task->counter += GFX.funcs.getFrameTime();
118 break;
119 }
120#else
121 task->counter += GFX.funcs.getFrameTime();
122 if (task->counter < GAUGE_RESULT_DELAY) {
123 break;
124 }
125 index = task->cursor >> 10;
126 shift = (task->cursor >> 7) & 6;
127 cell = FIELDSTG_gaugeRows[task->row][index];
128 cell = (cell >> shift) & 3;
129#endif
130 switch (cell) {
131 case 0:
132 default:
133 task->setState(task, TASK_KILL);
134 break;
135 case 1:
137 task->setState(task, TASK_DONE);
138 break;
139 case 2:
141 task->setState(task, TASK_DONE);
142 break;
143 }
144 break;
145 }
146 moveGaugeCursor(task);
147 drawGauge(task);
148 break;
149 }
150 break;
151 case TASK_DONE:
152 case TASK_KILL:
153 break;
154 }
155}
156
157/* Creates the gauge game at a tile */
159 GaugeGame *task = createTask(FIELDSTG_runGauge, sizeof(GaugeGame), 0);
160
161 task->pos = pos;
162 return task;
163}
signed int s32
Definition common.h:11
unsigned char u8
Definition common.h:8
GfxState GFX
GFX: the graphics state and its methods.
Definition display.c:209
GameState GAME
The save data, the game mode and the methods.
Definition state.c:64
#define TASK_RUN
Definition task.h:35
#define TASK_KILL
Definition task.h:37
#define TASK_INIT
Tasks: every game object is a task, a heap block that starts with this header and is updated once per...
Definition task.h:34
#define TASK_DONE
Definition task.h:36
#define FIELD_LAYER_MAP
the map, its objects and characters, and the menus
Definition field_map.h:20
FIELDSTG.PRO: the field mode, where the player walks around the map.
#define GAUGE_X
where it is drawn, on the screen
Definition field_mode.h:227
#define GAUGE_Y
Definition field_mode.h:228
#define GAUGE_CURSOR_FRAME
Definition field_mode.h:230
#define GAUGE_START_DELAY
frames before the cursor runs
Definition field_mode.h:225
#define GAUGE_ROWS
A gauge game (FIELDSTG_createGauge, FIELDSTG_runGauge)
Definition field_mode.h:222
#define GAUGE_RUNNING
The steps of a running gauge.
Definition field_mode.h:234
#define GAUGE_CURSOR_MAX
the row's 48 pixels, in 1/256 pixels
Definition field_mode.h:224
#define FIELD_SPRITES_X
Where the field keeps its textures in VRAM: the two images of FIELD_SPRITES_FILE (its entries 2 and 3...
Definition field_mode.h:27
#define GAUGE_RESULT_DELAY
frames on the stopped cursor
Definition field_mode.h:226
#define FIELD_SPRITES_FILE
The field's effect sprites (FIELDSTG_drawSpotEffect): the discs number their files differently.
Definition field_mode.h:591
#define GAUGE_STOPPED
Definition field_mode.h:237
#define GAUGE_STOPPING_SLOWLY
one time in four
Definition field_mode.h:236
#define FIELD_SPRITES_Y
Definition field_mode.h:29
#define GAUGE_ROW_FRAMES
Definition field_mode.h:231
#define GAUGE_STOPPING
Definition field_mode.h:235
#define GAUGE_EMPTY_ROW
the European version's, all zeros
Definition field_mode.h:223
#define FIELD_SPRITES2_X
Definition field_mode.h:28
#define GAUGE_FRAME
its sprites, of FIELD_SPRITES_FILE's sheet 1
Definition field_mode.h:229
u8 * FIELDSTG_gaugeRows[]
The rows of FIELDSTG_runGauge's gauges, 2 bits a cell.
Definition fieldstg.c:2020
FieldBattleFuncs FIELDSTG_battleFuncs
Definition fieldstg.c:3653
FileCache FILE_CACHE
The file cache.
Definition file_cache.c:7
void FIELDSTG_runGauge(GaugeGame *task)
A gauge game: a cursor runs back and forth along one of the gauge rows until cross is pressed,...
Definition gauge.c:52
static void moveGaugeCursor(GaugeGame *task)
The cursor goes back and forth over the gauge at the game's speed.
Definition gauge.c:6
GaugeGame * FIELDSTG_createGauge(Vec2 pos)
Creates the gauge game at a tile.
Definition gauge.c:158
static void drawGauge(GaugeGame *task)
Draws the four frames sprite (0x60-0x63) at pos, next to the player, then the gauge: its cursor,...
Definition gauge.c:26
PadState PAD
Controller input: cleared by initPad, then the methods.
Definition pad.c:168
#define PAD_CROSS
Definition pad.h:31
Random RANDOM
Definition random.c:533
SoundState SOUND
rsin and rcos (libgte) read rsin_tbl[a - 0x800] and the like: their addresses before the table fall i...
Definition sound.c:180
#define SOUND_SYSTEM05
Definition sound.h:57
#define SOUND_MENU_MOVE
SYSTEM06.
Definition sound.h:43
void initSpriteDrawer(SpriteDrawer *obj)
Clears a sprite drawer to neutral (no scale, gray tint, follows the scroll), gives it its methods and...
void(* startEventBattle)(s32 index)
FIELDSTG_startEventBattle.
Definition field_map.h:502
void *(* getEntry)(u32 fileAndIndex)
Definition file.h:96
s32 randomGauges
gauge games left with random rows, reset with each new mode
Definition game_state.h:581
void(* setStep)(struct GaugeGame *task, s32 step)
Definition field_mode.h:240
void(* setState)(struct GaugeGame *task, s32 state)
Definition field_mode.h:240
void(* nextSubstate)(struct GaugeGame *task)
Definition field_mode.h:240
void(* nextState)(struct GaugeGame *task)
Definition field_mode.h:240
s32 cursor
along the row, 0-GAUGE_CURSOR_MAX
Definition field_mode.h:243
s32 back
the cursor goes back
Definition field_mode.h:245
s32 row
of FIELDSTG_gaugeRows
Definition field_mode.h:242
s32(* getFrameTime)(void)
Definition gfx.h:32
s32(* getTime)(void)
Definition gfx.h:31
GfxFuncs funcs
Definition gfx.h:77
s32(* getPressed)(s32 pad)
Definition pad.h:125
s32(* next)(void)
0 to RANDOM_COUNT - 1
Definition random.h:15
short(* playSound)(s32 id)
returns the voice of a key-on
Definition sound.h:187
Draws sprites from a sprite sheet (such as file 0x277, the menu graphics): a sheet has a table of fra...
Definition gfx.h:223
void(* setLayerId)()
(id, depth)
Definition gfx.h:244
void(* setFollowScroll)()
(on)
Definition gfx.h:251
void(* draw)()
(sheet, frame, x, y)
Definition gfx.h:246
void(* setTexture)()
(x, y)
Definition gfx.h:242
Definition gfx.h:352
s32 y
Definition gfx.h:354
s32 x
Definition gfx.h:353
void * createTask(void(*update)(), s32 size, s32 childrenSize)
createTaskWithId for a task nothing needs to find
Definition task.c:105