Digimon World 3 decomp
The European version, SLES_039.36
Loading...
Searching...
No Matches
deck_choice.c
Go to the documentation of this file.
1/* CARDGAME's deck choice: the decks' windows and the marker on the one
2 selected. */
3
5
6/* Draws the deck marker at its size, cycling its palettes (or running
7 through them once when fast) */
9 SpriteDrawer drawer;
10 s32 row;
11
12 if (marker->scaleX != 0 && marker->scaleY != 0) {
13 initSpriteDrawer(&drawer);
14 drawer.setPivot(marker->x, marker->y + 19);
15 drawer.setScale(marker->scaleX, marker->scaleY, 0x1000);
16 if (marker->fast == 0) {
17 drawer.setClutRow((marker->time >> 2) % 16);
18 } else {
19 row = marker->time >> 1;
20 if (row >= 7) {
21 row = 7;
22 }
23 drawer.setClutRow(row);
24 }
25 drawer.setLayerId(0x100, 1);
26 drawer.setTexture(0x280, 0);
27 drawer.draw(FILE_CACHE.getEntry(FILE_CARDGAME_TIMS << 16 | 2), 0x47, marker->x, marker->y);
28 marker->time += GFX.funcs.getFrameTime();
29 }
30}
31
32/* The deck marker's task: opens by growing over 10 frames, stays until
33 closed, then shrinks and is drawn every frame */
35 switch (marker->state) {
36 case 0:
37 default:
38 marker->nextState(marker);
39 marker->scaleDuration = 10;
40 marker->scaleTime = 10;
41 marker->phase = 0;
42 marker->scaleX = 0x1000;
43 marker->scaleY = 0;
44 break;
45 case 1:
46 switch (marker->phase) {
47 case 0:
48 marker->scaleY = 0x1000 - (marker->scaleTime << 12) / marker->scaleDuration;
49 marker->scaleTime -= GFX.funcs.getFrameTime();
50 if (marker->scaleTime <= 0) {
51 marker->scaleY = 0x1000;
52 marker->phase = 1;
53 }
54 break;
55 case 1:
56 break;
57 case 2:
58 marker->setState(marker, 2);
59 break;
60 }
61 break;
62 case 2:
63 marker->scaleY = (marker->scaleTime << 12) / marker->scaleDuration;
64 marker->scaleTime -= GFX.funcs.getFrameTime();
65 if (marker->scaleTime <= 0) {
66 marker->scaleY = 0;
67 marker->setState(marker, 3);
68 }
69 break;
70 case 3:
71 break;
72 }
73 CARDGAME_drawMarker(marker);
74}
75
76/* CardMarker.setPos: moves the marker to x, y */
78 marker->x = x;
79 marker->y = y;
80}
81
82/* CardMarker.setFast: runs its palettes once from the start (the deck was
83 picked) */
85 marker->fast = 1;
86 marker->time = 0;
87}
88
89/* CardMarker.close: shrinks it over 5 frames */
91 marker->scaleDuration = 5;
92 marker->scaleTime = 5;
93 marker->phase = 2;
94 marker->scaleY = 0x1000;
95}
96
97/* Creates the deck marker at x, y, which shows the selected deck window */
100
102 marker->close = CARDGAME_closeMarker;
104 marker->x = x;
105 marker->y = y;
106 marker->fast = 0;
107 return marker;
108}
109
110/* Draws a deck window's frame and icon at its size, the icon running through
111 its palettes once when it blinks */
113 s16 rows[8] = {0, 1, 2, 3, 2, 1, 0, 0};
114 SpriteDrawer frame;
115 SpriteDrawer icon;
116 s32 i;
117
118 if (window->scaleX != 0 && window->scaleY != 0) {
119 initSpriteDrawer(&frame);
120 frame.setPivot(window->x, window->y);
121 frame.setScale(window->scaleX, window->scaleY, 0x1000);
122 frame.setLayerId(0x100, 1);
123 frame.setTexture(0x280, 0);
124 frame.draw(FILE_CACHE.getEntry(FILE_CARDGAME_TIMS << 16 | 2), 0x45, window->x, window->y);
125 initSpriteDrawer(&icon);
126 icon.setPivot(window->x, window->y);
127 if (window->blink != 0) {
128 i = window->time >> 1;
129 if (i >= 7) {
130 i = 7;
131 }
132 icon.setClutRow(rows[i]);
133 window->time += GFX.funcs.getFrameTime();
134 }
135 icon.setScale(window->scaleX, window->scaleY, 0x1000);
136 icon.setLayerId(0x100, 1);
137 icon.setTexture(0x280, 0);
138 icon.draw(FILE_CACHE.getEntry(FILE_CARDGAME_TIMS << 16 | 2), 0x46, window->x, window->y);
139 }
140}
141
142/* A deck window's task: makes its name and colour counts, opens by widening
143 over 12 frames, shows them while open, and closes by narrowing */
145 s32 i;
146
147 switch (window->state) {
148 case 0:
149 default:
150 window->nextState(window);
151 window->scaleDuration = 12;
152 window->scaleTime = 12;
153 window->phase = 0;
154 window->scaleY = 0x1000;
155 window->scaleX = 0;
156 texts[0] = createTextWindow(0x100, 1, 0, 0);
157 texts[0]->setString(texts[0], GAME.decks[window->deck].name, -1);
158 texts[0]->setPos(texts[0], window->x + 5, window->y + 3);
159 for (i = 0; i < 6; i++) {
160 texts[i + 1] = createTextWindow(0x100, 1, 0, 0);
161 texts[i + 1]->setPos(texts[i + 1], window->x + CARDGAME_deckCountOffsets[i].x, window->y + CARDGAME_deckCountOffsets[i].y);
162 texts[i + 1]->setNumber(texts[i + 1], 0, window->counts[i]);
163 texts[i + 1]->setRightAlign(texts[i + 1], 1);
164 }
165 break;
166 case 1:
167 switch (window->phase) {
168 case 0:
169 window->scaleX = 0x1000 - (window->scaleTime << 12) / window->scaleDuration;
170 window->scaleTime -= GFX.funcs.getFrameTime();
171 if (window->scaleTime <= 0) {
172 window->scaleX = 0x1000;
173 window->phase = 1;
174 }
175 break;
176 case 1:
177 break;
178 case 2:
179 window->setState(window, 2);
180 break;
181 }
182 break;
183 case 2:
184 window->scaleX = (window->scaleTime << 12) / window->scaleDuration;
185 window->scaleTime -= GFX.funcs.getFrameTime();
186 if (window->scaleTime <= 0) {
187 window->scaleX = 0;
188 window->setState(window, 3);
189 }
190 break;
191 case 3:
192 break;
193 }
194 if (window->phase == 1) {
195 texts[0]->setPos(texts[0], window->x + 5, window->y + 3);
196 texts[0]->setVisible(texts[0], 1);
197 for (i = 0; i < 6; i++) {
198 texts[i + 1]->setVisible(texts[i + 1], 1);
199 texts[i + 1]->setPos(texts[i + 1], window->x + CARDGAME_deckCountOffsets[i].x, window->y + CARDGAME_deckCountOffsets[i].y);
200 }
201 } else {
202 texts[0]->setVisible(texts[0], 0);
203 for (i = 0; i < 6; i++) {
204 texts[i + 1]->setVisible(texts[i + 1], 0);
205 }
206 }
208}
209
210/* CardDeckWindow.setBlink: blinks its icon (the deck was picked) */
212 window->blink = 1;
213 window->time = 0;
214}
215
216/* CardDeckWindow.close: narrows it over 6 frames */
218 window->scaleDuration = 6;
219 window->scaleTime = 6;
220 window->phase = 2;
221 window->scaleX = 0x1000;
222}
223
224/* Creates the window of deck deck at x, y, with how many cards of each
225 colour it has */
227 CardDrawer drawer;
228 CardDeckWindow *window;
229 s32 i;
230
231 initCardDrawer(&drawer);
232 window = createTask(CARDGAME_updateDeckWindow, sizeof(CardDeckWindow), 7 * 4);
233 for (i = 0; i < 6; i++) {
234 window->counts[i] = 0;
235 }
236 for (i = 0; i < 40; i++) {
237 drawer.setCard(GAME.decks[deck].cards[i]);
238 window->counts[drawer.card->color - 1]++;
239 }
241 window->deck = deck;
242 window->x = x;
243 window->y = y;
244 window->blink = 0;
246 return window;
247}
CARDGAME.PRO: the card battle (mode 0x700).
void initCardDrawer(CardDrawer *obj)
Clears a card drawer, gives it its methods and binds it.
CardOffset CARDGAME_deckCountOffsets[]
where the deck window's six counts are
Definition cardgame_3.c:10
signed int s32
Definition common.h:11
signed short s16
Definition common.h:9
void CARDGAME_setMarkerPos(CardMarker *marker, s16 x, s16 y)
CardMarker.setPos: moves the marker to x, y.
Definition deck_choice.c:77
void CARDGAME_updateDeckWindow(CardDeckWindow *window, TextWindow **texts)
A deck window's task: makes its name and colour counts, opens by widening over 12 frames,...
void CARDGAME_drawMarker(CardMarker *marker)
Draws the deck marker at its size, cycling its palettes (or running through them once when fast)
Definition deck_choice.c:8
void CARDGAME_setMarkerFast(CardMarker *marker)
CardMarker.setFast: runs its palettes once from the start (the deck was picked)
Definition deck_choice.c:84
CardMarker * CARDGAME_createMarker(s16 x, s16 y)
Creates the deck marker at x, y, which shows the selected deck window.
Definition deck_choice.c:98
void CARDGAME_setDeckWindowBlink(CardDeckWindow *window)
CardDeckWindow.setBlink: blinks its icon (the deck was picked)
void CARDGAME_drawDeckWindow(CardDeckWindow *window)
Draws a deck window's frame and icon at its size, the icon running through its palettes once when it ...
void CARDGAME_closeMarker(CardMarker *marker)
CardMarker.close: shrinks it over 5 frames.
Definition deck_choice.c:90
void CARDGAME_closeDeckWindow(CardDeckWindow *window)
CardDeckWindow.close: narrows it over 6 frames.
void CARDGAME_updateMarker(CardMarker *marker)
The deck marker's task: opens by growing over 10 frames, stays until closed, then shrinks and is draw...
Definition deck_choice.c:34
CardDeckWindow * CARDGAME_createDeckWindow(s32 deck, s32 x, s32 y)
Creates the window of deck deck at x, y, with how many cards of each colour it has.
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
FileCache FILE_CACHE
The file cache.
Definition file_cache.c:7
#define FILE_CARDGAME_TIMS
CARDGAME's own pictures, a TIM archive.
Definition screen.h:15
void initSpriteDrawer(SpriteDrawer *obj)
Clears a sprite drawer to neutral (no scale, gray tint, follows the scroll), gives it its methods and...
A deck's window (CARDGAME_createDeckWindow): its name and how many cards of each of the six colours i...
Definition choice.h:39
s16 scaleDuration
Definition choice.h:51
s32 deck
in GAME.decks
Definition choice.h:41
s32 time
the blink
Definition choice.h:42
void(* close)(struct CardDeckWindow *window)
Definition choice.h:53
void(* setBlink)(struct CardDeckWindow *window)
Definition choice.h:52
u8 counts[6]
Definition choice.h:47
void(* setState)(struct CardDeckWindow *task, s32 state)
Definition choice.h:40
s16 scaleTime
Definition choice.h:50
void(* nextState)(struct CardDeckWindow *task)
Definition choice.h:40
u8 phase
0 opening, 1 open, 2 closing
Definition choice.h:48
Draws the cards' images (CardImage), from files 0x7E7-0x7EB.
Definition gfx.h:193
void(* setCard)()
(id)
Definition gfx.h:205
CardImage * card
Definition gfx.h:194
u8 color
from 1
Definition gfx.h:173
A blinking marker that opens and closes by scaling (CARDGAME_createMarker): frame 0x47 of the TIM arc...
Definition choice.h:20
s16 scaleX
Definition choice.h:25
s16 y
Definition choice.h:24
u8 phase
0 opening, 1 open, 2 closing
Definition choice.h:28
void(* close)(struct CardMarker *marker)
Definition choice.h:33
u8 fast
the blink's palette cycle
Definition choice.h:29
s32 time
the blink
Definition choice.h:22
void(* setState)(struct CardMarker *task, s32 state)
Definition choice.h:21
void(* setFast)(struct CardMarker *marker)
Definition choice.h:34
void(* setPos)(struct CardMarker *marker, s16 x, s16 y)
Definition choice.h:32
s16 scaleTime
Definition choice.h:30
void(* nextState)(struct CardMarker *task)
Definition choice.h:21
s16 scaleDuration
Definition choice.h:31
s32 state
Definition choice.h:21
s16 scaleY
Definition choice.h:26
s16 x
Definition choice.h:23
s16 x
Definition screen.h:60
s16 y
Definition screen.h:61
char name[0x16]
Definition game_state.h:274
s16 cards[40]
Definition game_state.h:275
void *(* getEntry)(u32 fileAndIndex)
Definition file.h:96
Deck decks[3]
Definition game_state.h:516
s32(* getFrameTime)(void)
Definition gfx.h:32
GfxFuncs funcs
Definition gfx.h:77
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(* setPivot)()
(x, y)
Definition gfx.h:250
void(* setScale)()
(x, y, z), ONE = 1.0
Definition gfx.h:248
void(* setLayerId)()
(id, depth)
Definition gfx.h:244
void(* setClutRow)()
(row)
Definition gfx.h:247
void(* draw)()
(sheet, frame, x, y)
Definition gfx.h:246
void(* setTexture)()
(x, y)
Definition gfx.h:242
A text window (createTextWindow): up to six text buffers (0 is shown, 1-5 are "work" buffers that con...
Definition text.h:131
void(* setRightAlign)()
no prototype: callers would truncate u8 args
Definition text.h:178
void(* setNumber)()
Definition text.h:166
void(* setPos)(struct TextWindow *obj, s16 x, s16 y)
Definition text.h:173
void(* setString)()
Definition text.h:165
void(* setVisible)(struct TextWindow *obj, u8 arg)
Definition text.h:177
void * createTask(void(*update)(), s32 size, s32 childrenSize)
createTaskWithId for a task nothing needs to find
Definition task.c:105
TextWindow * createTextWindow(s16 layerId, s16 style, s16 x, s16 y)
A text window on a layer, in a font style, at (x, y)