Digimon World 3 decomp
The European version, SLES_039.36
Loading...
Searching...
No Matches
background.c
Go to the documentation of this file.
1/* The title screen's background, and its eight looping sprite animations */
2
3#include "menus/title.h"
4
5/* Steps one of the background's looping animations by a frame and returns its sprite
6 frame (300: nothing drawn); callers pass depth 0, it recurses past entries already over */
8 AnimFrame *frame = &frames[anim->index];
9
10 if (depth == 0) {
11 anim->timer--;
12 }
13 if (anim->timer <= 0) {
14 frame++;
15 anim->index++;
16 anim->timer += frame->duration;
17 if (frame->frame == 0xFF) {
18 /* Back to the first frame */
19 frame = frames;
20 anim->index = 0;
21 anim->timer += frame->duration;
22 }
23 STDWTITL_stepLoopingAnimation(anim, frames, depth + 1);
24 }
25 return frame->frame;
26}
27
28/* Draws the title screen's background, from entries 0-2 of its file */
30 SpriteDrawer sprite;
31
32 initSpriteDrawer(&sprite);
33 sprite.setLayerId(task->layerId, 0);
34 sprite.setAltClut(0, 0x1F3);
35 sprite.setTexture(0x300, 0);
36 sprite.draw(FILE_CACHE.getEntry(STDWTITL_BACKGROUND(0)), 0, 0, 0);
37 sprite.setTexture(0x340, 0);
38 sprite.draw(FILE_CACHE.getEntry(STDWTITL_BACKGROUND(1)), 0, 0, 0);
39 sprite.setTexture(0x380, 0);
40 sprite.draw(FILE_CACHE.getEntry(STDWTITL_BACKGROUND(2)), 0, 0, 0);
41}
42
43/* Steps and draws the background's eight looping sprite animations; the last two at
44 the positions picked for them */
46 SpriteDrawer sprite;
55
56 initSpriteDrawer(&sprite);
57 sprite.setLayerId(task->layerId, 0);
58 sprite.setTexture(0x3C0, 0);
59 if (frame0 != 300) {
60 sprite.draw(FILE_CACHE.getEntry(STDWTITL_BACKGROUND(3)), frame0, 0, 0);
61 }
62 if (frame1 != 300) {
63 sprite.draw(FILE_CACHE.getEntry(STDWTITL_BACKGROUND(3)), frame1, 0, 0);
64 }
65 if (frame2 != 300) {
66 sprite.draw(FILE_CACHE.getEntry(STDWTITL_BACKGROUND(3)), frame2, 0, 0);
67 }
68 if (frame3 != 300) {
69 sprite.draw(FILE_CACHE.getEntry(STDWTITL_BACKGROUND(3)), frame3, 0, 0);
70 }
71 if (frame4 != 300) {
72 sprite.draw(FILE_CACHE.getEntry(STDWTITL_BACKGROUND(8)), frame4, 0, 0);
73 }
74 if (frame5 != 300) {
75 sprite.draw(FILE_CACHE.getEntry(STDWTITL_BACKGROUND(8)), frame5, 0, 0);
76 }
77 if (frame6 != 300) {
78 sprite.draw(FILE_CACHE.getEntry(STDWTITL_BACKGROUND(8)), frame6, task->pos6.x, task->pos6.y);
79 }
80 if (frame7 != 300) {
81 sprite.draw(FILE_CACHE.getEntry(STDWTITL_BACKGROUND(8)), frame7, task->pos7.x, task->pos7.y);
82 }
83}
84
85/* The background's task: draws the background; once animated, also its eight
86 sprite animations, the last two with a random delay and position */
88 s32 i;
89
90 switch (task->state) {
91 case TASK_INIT:
92 default:
93 task->nextState(task);
94 break;
95 case TASK_DONE:
96 if (task->substate == 0) {
97 task->anims[0].index = 0;
99 task->anims[1].index = 0;
101 task->anims[2].index = 0;
103 task->anims[3].index = 0;
105 task->anims[4].index = 0;
107 task->anims[5].index = 0;
109 task->anims[6].index = 0;
110 task->anims[6].timer = STDWTITL_backgroundAnim6[0].duration + RANDOM.next() % 300;
111 task->anims[7].index = 0;
112 task->anims[7].timer = STDWTITL_backgroundAnim7[0].duration + RANDOM.next() % 240;
113 i = RANDOM.next() % 3;
116 i = RANDOM.next() % 5;
119 task->setSubstate(task, 1);
120 }
122 /* fallthrough */
123 case TASK_RUN:
125 break;
126 case TASK_KILL:
127 break;
128 }
129}
130
131/* Starts the background's sprite animations (the task's animate) */
133 if (task->state == TASK_RUN) {
134 task->setState(task, TASK_DONE);
135 }
136}
137
138/* Creates the title screen's background (task); skip is not used */
141
144 task->depth = 2;
145 task->skip = skip;
146 return task;
147}
s32 STDWTITL_stepLoopingAnimation(AnimState *anim, AnimFrame *frames, s32 depth)
Steps one of the background's looping animations by a frame and returns its sprite frame (300: nothin...
Definition background.c:7
void STDWTITL_drawBackgroundSprites(TitleBackgroundTask *task)
Steps and draws the background's eight looping sprite animations; the last two at the positions picke...
Definition background.c:45
void STDWTITL_tickBackground(TitleBackgroundTask *task)
The background's task: draws the background; once animated, also its eight sprite animations,...
Definition background.c:87
void STDWTITL_drawBackground(TitleBackgroundTask *task)
Draws the title screen's background, from entries 0-2 of its file.
Definition background.c:29
void STDWTITL_animateBackground(TitleBackgroundTask *task)
Starts the background's sprite animations (the task's animate)
Definition background.c:132
TitleBackgroundTask * STDWTITL_startBackgroundTask(s32 skip)
Creates the title screen's background (task); skip is not used.
Definition background.c:139
signed int s32
Definition common.h:11
AnimFrame STDWTITL_backgroundAnim7[]
Definition title.c:59
AnimFrame STDWTITL_backgroundAnim1[]
Definition title.c:16
AnimFrame STDWTITL_backgroundAnim2[]
Definition title.c:21
Point16 STDWTITL_background7Positions[]
Definition title.c:68
AnimFrame STDWTITL_backgroundAnim4[]
Definition title.c:38
AnimFrame STDWTITL_backgroundAnim5[]
Definition title.c:48
AnimFrame STDWTITL_backgroundAnim6[]
Definition title.c:54
Point16 STDWTITL_background6Positions[]
Definition title.c:65
AnimFrame STDWTITL_backgroundAnim0[]
Definition title.c:12
AnimFrame STDWTITL_backgroundAnim3[]
Definition title.c:29
#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
FileCache FILE_CACHE
The file cache.
Definition file_cache.c:7
Random RANDOM
Definition random.c:533
void initSpriteDrawer(SpriteDrawer *obj)
Clears a sprite drawer to neutral (no scale, gray tint, follows the scroll), gives it its methods and...
One frame of a sprite animation; frame 0xFF ends it (or loops it)
Definition gfx.h:296
s16 frame
Definition gfx.h:297
s16 duration
Definition gfx.h:298
s16 index
Definition gfx.h:302
s16 timer
Definition gfx.h:303
void *(* getEntry)(u32 fileAndIndex)
Definition file.h:96
s16 x
Definition title.h:211
s16 y
Definition title.h:212
s32(* next)(void)
0 to RANDOM_COUNT - 1
Definition random.h:15
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(* setAltClut)()
(x, y)
Definition gfx.h:243
void(* setLayerId)()
(id, depth)
Definition gfx.h:244
void(* draw)()
(sheet, frame, x, y)
Definition gfx.h:246
void(* setTexture)()
(x, y)
Definition gfx.h:242
void(* nextState)(struct TitleBackgroundTask *task)
Definition title.h:216
void(* animate)(struct TitleBackgroundTask *task)
Definition title.h:224
AnimState anims[8]
Definition title.h:218
void(* setSubstate)(struct TitleBackgroundTask *task, s32 substate)
Definition title.h:216
void(* setState)(struct TitleBackgroundTask *task, s32 state)
Definition title.h:216
void * createTask(void(*update)(), s32 size, s32 childrenSize)
createTaskWithId for a task nothing needs to find
Definition task.c:105
STDWTITL.PRO: the title screen, the opening movies and a notice screen.
#define STDWTITL_TITLE_LAYER
Definition title.h:30
#define STDWTITL_BACKGROUND(entry)
Definition title.h:43