-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathintro.c
252 lines (211 loc) · 6.19 KB
/
intro.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
#include <gb/gb.h>
#include "defines.h"
#include "fade.h"
#include "gamestate.h"
#include "set_data_rle.h"
#include "intro.h"
#include "mmlgb/driver/music.h"
#include "sgb_send_packet.h"
#include "intro_bg.h"
#include "intro_bg_dx.h"
#include "data/palettes/intro_sprites.h"
#include "data/sprite/intro_sprites.h"
#include "data/sprite/intro_flash.h"
UBYTE intro_frame;
extern UBYTE intro_song_data;
#define INTRO_STATE_WALK 1U
#define INTRO_STATE_TRIP 2U
#define INTRO_STATE_BLINK 3U
const UBYTE SGB_INTRO_PAL01[16] = {
1, 255, 127, 27, 38, 209, 8, 34, 0, 0, 0, 0, 0, 0, 0, 0
};
const UBYTE SGB_INTRO_ATTRDIV[16] = {
(6U << 3) + 1U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U
};
void initIntro() {
disable_interrupts();
DISPLAY_OFF;
if(sgb_mode) {
sgb_send_packet(SGB_INTRO_PAL01); delay(62U);
sgb_send_packet(SGB_INTRO_ATTRDIV);
}
move_bkg(0U, 112U);
OBP0_REG = 0xD0U; // 11010000
BGP_REG = 0xE4U; // 11100100
if(CGB_MODE) {
set_bkg_data_rle(0U, intro_bg_dx_data_length, intro_bg_dx_data);
set_bkg_tiles_rle(0U, 0U, intro_bg_dx_tiles_width, intro_bg_dx_tiles_height, intro_bg_dx_tiles);
set_bkg_palette_buffer(0U, intro_bg_dx_palette_data_length, intro_bg_dx_palette_data);
VBK_REG = 1U;
set_bkg_tiles_rle(0U, 0U, intro_bg_dx_tiles_width, intro_bg_dx_tiles_height, intro_bg_dx_palettes);
VBK_REG = 0U;
} else {
set_bkg_data_rle(0U, intro_bg_data_length, intro_bg_data);
set_bkg_tiles_rle(0U, 0U, intro_bg_tiles_width, intro_bg_tiles_height, intro_bg_tiles);
}
set_sprite_data(0U, intro_sprites_data_length, intro_sprites_data);
set_sprite_palette(0U, intro_sprites_palette_data_length, intro_sprites_palette_data);
clearSprites();
setMusicBank(SONG_BANK_INTRO);
playMusic(&intro_song_data);
HIDE_WIN;
SHOW_SPRITES;
SHOW_BKG;
SPRITES_8x16;
DISPLAY_ON;
enable_interrupts();
}
void updateIntro() {
UBYTE frame;
switch(scene_state) {
case INTRO_STATE_WALK:
if(ticks & 1U) {
player_x--;
cat_x--;
}
if((ticks & 7U) == 7U) {
intro_frame++;
if(intro_frame == 6U) intro_frame = 0U;
}
frame = intro_frame << 2;
// Player sprites
setSprite(player_x, player_y-scroll_y, frame, OBJ_PAL0);
setSprite(player_x+8, player_y-scroll_y, frame+2U, OBJ_PAL0);
// Cat sprites
cat_y = player_y-12U + ((ticks & 16U) >> 4);
setSprite(cat_x, cat_y-scroll_y-16U, 32U, OBJ_PAL0 | 1U);
setSprite(cat_x+8U, cat_y-scroll_y-16U, 34U, OBJ_PAL0 | 1U);
setSprite(cat_x, cat_y-scroll_y, 36U, OBJ_PAL0 | 1U);
setSprite(cat_x+8U, cat_y-scroll_y, 38U, OBJ_PAL0 | 1U);
if(player_x == 77U) {
scene_state = INTRO_STATE_TRIP;
player_y = 239U;
ticks = 0U;
}
break;
case INTRO_STATE_TRIP:
if(ticks & 1U) {
if(player_x < 55U) {
if(cat_y >= 130U || (ticks & 3U) == 3U) {
cat_y--;
}
}
if(player_x != 45U) player_x--;
}
if((ticks & 3U) == 3U) {
if(scroll_y && cat_y < scroll_y+64U) {
scroll_y--;
}
}
if((ticks & 7U) == 7U) {
if(cat_y >= 130U || (ticks & 15U) == 15U) {
cat_x++;
}
}
if((ticks & 15U) == 15U) {
if(player_x != 45U) player_y++;
}
if(player_x > 45U) {
frame = 24U;
} else {
frame = 28U;
player_y = 240U;
}
// Player sprites
setSprite(player_x, player_y-scroll_y, frame, OBJ_PAL0);
setSprite(player_x+8, player_y-scroll_y, frame+2U, OBJ_PAL0);
// Player shocked mark
if(player_x > 68U) {
setSprite(player_x, player_y-scroll_y-13U, 52U, OBJ_PAL0 | 2U);
setSprite(player_x+8, player_y-scroll_y-13U, 54U, OBJ_PAL0 | 2U);
}
// Exclamation mark
if((ticks & 16U) && cat_y < 210U && cat_y > 180U) {
setSprite(player_x+4U, player_y-scroll_y-13U, 50U, OBJ_PAL0 | 3U);
}
frame = 56U;
if(cat_y < 180U) {
frame = 40U;
}
if(cat_y < 130U) {
setSprite(cat_x+4U, cat_y-scroll_y-10U, 48U, OBJ_PAL0 | 1U);
} else {
setSprite(cat_x, cat_y-scroll_y-16U, frame, OBJ_PAL0 | 1U);
setSprite(cat_x+8U, cat_y-scroll_y-16U, frame+2U, OBJ_PAL0 | 1U);
setSprite(cat_x, cat_y-scroll_y, frame+4U, OBJ_PAL0 | 1U);
setSprite(cat_x+8U, cat_y-scroll_y, frame+6U, OBJ_PAL0 | 1U);
}
if(cat_y < 110U) {
scene_state = INTRO_STATE_BLINK;
intro_frame = 0U;
set_sprite_data(0U, intro_flash_data_length, intro_flash_data);
}
break;
case INTRO_STATE_BLINK:
if((ticks & 3U) == 3U) {
if(scroll_y) {
scroll_y--;
}
}
if((ticks & 3U) == 3U) {
intro_frame++;
}
if(intro_frame == 0U) {
setSprite(cat_x, cat_y-scroll_y-16U, 0U, OBJ_PAL0 | 2U);
setSprite(cat_x+8U, cat_y-scroll_y-16U, 2U, OBJ_PAL0 | 2U);
setSprite(cat_x+16U, cat_y-scroll_y-16U, 4U, OBJ_PAL0 | 2U);
setSprite(cat_x, cat_y-scroll_y, 6U, OBJ_PAL0 | 2U);
setSprite(cat_x+8U, cat_y-scroll_y, 8U, OBJ_PAL0 | 2U);
setSprite(cat_x+16U, cat_y-scroll_y, 10U, OBJ_PAL0 | 2U);
}
else if(intro_frame == 1U) {
setSprite(cat_x+9U, cat_y-scroll_y-4U, 12U, OBJ_PAL0 | 2U);
}
else if(intro_frame == 2U) {
setSprite(cat_x+4U, cat_y-scroll_y-8U, 16U, OBJ_PAL0 | 2U);
setSprite(cat_x+12U, cat_y-scroll_y-8U, 18U, OBJ_PAL0 | 2U);
}
else if(intro_frame == 3U) {
setSprite(cat_x-2U, cat_y-scroll_y-11U, 20U, OBJ_PAL0 | 2U);
setSprite(cat_x+2U, cat_y-scroll_y-11U, 22U, OBJ_PAL0 | 2U);
setSprite(cat_x+10U, cat_y-scroll_y-11U, 24U, OBJ_PAL0 | 2U);
setSprite(cat_x+18U, cat_y-scroll_y-11U, 26U, OBJ_PAL0 | 2U);
}
else if(intro_frame == 4U) {
setSprite(cat_x-2U, cat_y-scroll_y-11U, 28U, OBJ_PAL0 | 2U);
setSprite(cat_x+2U, cat_y-scroll_y-11U, 30U, OBJ_PAL0 | 2U);
setSprite(cat_x+10U, cat_y-scroll_y-11U, 32U, OBJ_PAL0 | 2U);
setSprite(cat_x+18U, cat_y-scroll_y-11U, 34U, OBJ_PAL0 | 2U);
}
if(scroll_y == 16U) {
gamestate = GAMESTATE_TITLE;
}
break;
}
}
void enterIntro() {
initIntro();
fadeFromWhite(8U);
scene_state = INTRO_STATE_WALK;
scroll_y = 112U;
player_x = 185U;
player_y = 240U;
cat_x = player_x + 13U;
cat_y = 228U;
intro_frame = 0U;
ticks = 0U;
while(gamestate == GAMESTATE_INTRO) {
updateJoystate();
updateIntro();
ticks++;
if(CLICKED(J_START)) {
gamestate = GAMESTATE_TITLE;
}
clearRemainingSprites();
wait_vbl_done();
move_bkg(0U, scroll_y);
}
clearRemainingSprites();
fadeToWhite(8U);
STOP_MUSIC;
}