Skip to content

Commit bc407a3

Browse files
committed
Add restart menu
1 parent 4adb00d commit bc407a3

File tree

5 files changed

+148
-17
lines changed

5 files changed

+148
-17
lines changed

ref/inv.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
import math
22

3-
speed = 6
4-
y = 40
5-
desty = 128
6-
a = []
3+
def output(name, a):
4+
s = ', '.join(map(str, a[::-1]))
5+
print(f"const u8 {name}[] = {{{s}}};")
76

8-
while desty - y > 1:
9-
y += (desty - y) / speed
10-
a.append(math.ceil(y))
7+
def down(speed, y, desty, a=None):
8+
if a is None: a = []
9+
while desty - y > 1:
10+
y += (desty - y) / speed
11+
a.append(math.ceil(y))
12+
return a
1113

12-
print(f"#{len(a)} {a[::-1]}")
14+
def up(speed, y, desty, a=None):
15+
if a is None: a = []
16+
while y - desty > 1:
17+
y -= (y - desty) / speed
18+
a.append(math.floor(y))
19+
return a
1320

14-
y = 128
15-
desty = 40
16-
a = []
21+
output('inventory_up_y', up(6, 128, 40))
22+
output('inventory_down_y', down(6, 40, 128))
1723

18-
while y - desty > 1:
19-
y -= (y - desty) / speed
20-
a.append(math.floor(y))
21-
22-
print(f"#{len(a)} {a[::-1]}")
24+
output('restart_menu_up_y', up(5, 144, 60, down(5, 128, 144)))
25+
output('restart_menu_down_y', up(5, 144, 128, down(5, 60, 144)))

src/bank0.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,14 @@ const u8 inventory_map[] = {
542542
116, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 118,
543543
116, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 118,
544544
116, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 118,
545-
123, 124, 124, 124, 124, 124, 124, 124, 124, 124, 124, 124, 124, 124, 124, 125};
545+
123, 124, 124, 124, 124, 124, 124, 124, 124, 124, 124, 124, 124, 124, 124, 125,
546+
};
547+
548+
const u8 restart_menu_map[] = {
549+
112, 113, 113, 113, 113, 113, 113, 113, 113, 113, 113, 113, 113, 113, 113, 115,
550+
116, 0, 204, 203, 205, 213, 0, 220, 207, 221, 222, 203, 220, 222, 0, 118,
551+
123, 124, 124, 124, 124, 124, 124, 124, 124, 124, 124, 124, 124, 124, 124, 125,
552+
};
546553

547554
const u8 blind_map[] = {204, 214, 211, 216, 206};
548555

@@ -554,6 +561,16 @@ const u8 inventory_down_y[] = {128, 127, 127, 127, 127, 126, 126, 125, 125,
554561
124, 123, 122, 120, 119, 117, 114, 111, 108,
555562
104, 99, 93, 86, 78, 67, 55};
556563

564+
const u8 restart_menu_up_y[] = {60, 61, 61, 61, 62, 62, 63, 64, 65,
565+
67, 69, 71, 74, 77, 82, 87, 94, 103,
566+
113, 127, 144, 143, 143, 143, 142, 142, 141,
567+
140, 139, 138, 136, 134, 132};
568+
569+
const u8 restart_menu_down_y[] = {128, 129, 129, 129, 130, 130, 131, 132, 133,
570+
134, 136, 138, 140, 144, 143, 143, 143, 142,
571+
142, 141, 140, 139, 137, 135, 133, 130, 127,
572+
122, 117, 110, 101, 91, 77};
573+
557574
const u8 msg_tiles[] = {
558575
// "wurstlord awakens"
559576
0x5b, 0x5c, 0x5d, 0x5e, 0x5f, 0x60, 0x61, 0x62, 0x63,

src/gameplay.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,16 @@ void gameplay_update(void) NONBANKED {
221221
}
222222

223223
inv_animate();
224+
restart_menu_animate();
224225
animate_end();
225226
pal_update();
226227
}
227228

228229
void do_turn(void) {
229230
if (inv_anim_up) {
230231
inv_update();
232+
} else if (restart_menu_up) {
233+
restart_menu_update();
231234
} else if (turn == TURN_PLAYER) {
232235
move_player();
233236
}
@@ -388,6 +391,9 @@ void move_player(void) {
388391
} else if (joy_action & J_A) {
389392
inv_open();
390393
sfx(SFX_OK);
394+
} else if (newjoy & J_START) {
395+
restart_menu_open();
396+
sfx(SFX_OK);
391397
}
392398
joy_action = 0;
393399
}

src/inventory.c

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "gameplay.h"
88
#include "joy.h"
99
#include "mob.h"
10+
#include "palette.h"
1011
#include "pickup.h"
1112
#include "sound.h"
1213
#include "sprite.h"
@@ -30,6 +31,13 @@
3031
#define INV_SELECT_X_OFFSET 32
3132
#define INV_SELECT_Y_OFFSET 40
3233

34+
#define RESTART_MENU_WIDTH 16
35+
#define RESTART_MENU_HEIGHT 3
36+
#define RESTART_MENU_Y (32 - RESTART_MENU_HEIGHT - 8)
37+
#define RESTART_MENU_SELECT_X_OFFSET 32
38+
#define RESTART_MENU_SELECT_Y_OFFSET 24
39+
#define RESTART_MENU_ANIM_FRAMES 33
40+
3341
#define INV_FLOOR_OFFSET 23 /* offset into inventory_map */
3442
#define INV_BLANK_ROW_OFFSET 49 /* offset into inventory_map */
3543
#define INV_BLIND_LEN 5 /* BLIND */
@@ -40,9 +48,12 @@
4048
#define TILE_0 0xe5
4149

4250
extern const u8 inventory_map[];
51+
extern const u8 restart_menu_map[];
4352

4453
extern const u8 inventory_up_y[];
4554
extern const u8 inventory_down_y[];
55+
extern const u8 restart_menu_up_y[];
56+
extern const u8 restart_menu_down_y[];
4657

4758
extern const u8 pick_type_name_tile[];
4859
extern const u8 pick_type_name_start[];
@@ -64,6 +75,10 @@ PickupType inv_selected_pick;
6475
u8 equip_type[MAX_EQUIPS];
6576
u8 equip_charge[MAX_EQUIPS];
6677

78+
u8 restart_menu_up;
79+
u8 restart_menu_anim_timer;
80+
u8 restart_menu_select;
81+
6782
void inv_init(void) {
6883
inv_select_timer = INV_SELECT_FRAMES;
6984
inv_selected_pick = PICKUP_TYPE_NONE;
@@ -169,6 +184,81 @@ void inv_animate(void) {
169184
}
170185
}
171186

187+
void restart_menu_update(void) {
188+
if (!restart_menu_anim_timer) {
189+
if (joy_action & (J_LEFT | J_RIGHT)) {
190+
restart_menu_select ^= 1;
191+
sfx(SFX_SELECT);
192+
}
193+
if (newjoy & J_B) {
194+
restart_menu_close();
195+
sfx(SFX_BACK);
196+
} else if (joy_action & J_A) {
197+
if (restart_menu_select) {
198+
restart_menu_up = 0;
199+
restart_menu_select = 0;
200+
// restart game
201+
doloadfloor = 1;
202+
pal_fadeout();
203+
music_main();
204+
gameplay_init();
205+
} else {
206+
restart_menu_close();
207+
sfx(SFX_BACK);
208+
}
209+
}
210+
joy_action = 0;
211+
}
212+
}
213+
214+
void restart_menu_animate(void) {
215+
if (restart_menu_anim_timer) {
216+
--restart_menu_anim_timer;
217+
if (restart_menu_up) {
218+
WY_REG = restart_menu_up_y[restart_menu_anim_timer];
219+
if (restart_menu_anim_timer == 20) {
220+
vmemcpy((u8 *)0x9da0, (u8 *)0x9c00, 0x20 * 18);
221+
set_win_tiles(0, 0, RESTART_MENU_WIDTH, RESTART_MENU_HEIGHT,
222+
restart_menu_map);
223+
#ifdef CGB_SUPPORT
224+
if (_cpu == CGB_TYPE) {
225+
VBK_REG = 1;
226+
vmemcpy((u8 *)0x9da0, (u8 *)0x9c00, 0x20 * 18);
227+
fill_win_rect(0, 0, RESTART_MENU_WIDTH, RESTART_MENU_HEIGHT, 3);
228+
VBK_REG = 0;
229+
}
230+
#endif
231+
vmemset((u8 *)0x9c60, 0, 0x20 * 8);
232+
}
233+
} else {
234+
WY_REG = restart_menu_down_y[restart_menu_anim_timer];
235+
if (restart_menu_anim_timer == 13) {
236+
vmemcpy((u8 *)0x9c00, (u8 *)0x9da0, 0x20 * 18);
237+
#ifdef CGB_SUPPORT
238+
if (_cpu == CGB_TYPE) {
239+
VBK_REG = 1;
240+
vmemcpy((u8 *)0x9c00, (u8 *)0x9da0, 0x20 * 18);
241+
VBK_REG = 0;
242+
}
243+
#endif
244+
}
245+
}
246+
}
247+
248+
if (restart_menu_anim_timer || restart_menu_up) {
249+
if (--inv_select_timer == 0) {
250+
inv_select_timer = INV_SELECT_FRAMES;
251+
++inv_select_frame;
252+
}
253+
*next_sprite++ = WY_REG + RESTART_MENU_SELECT_Y_OFFSET;
254+
*next_sprite++ = RESTART_MENU_SELECT_X_OFFSET +
255+
pickbounce[inv_select_frame & 7] +
256+
(restart_menu_select ? 40 : 0);
257+
*next_sprite++ = 0;
258+
*next_sprite++ = 0;
259+
}
260+
}
261+
172262
void inv_display_blind(void) {
173263
vram_copy(INV_FLOOR_ADDR, blind_map, INV_BLIND_LEN);
174264
counter_thirty(&st_recover);
@@ -207,6 +297,16 @@ void inv_close(void) {
207297
inv_anim_up = 0;
208298
}
209299

300+
void restart_menu_open(void) {
301+
restart_menu_anim_timer = RESTART_MENU_ANIM_FRAMES;
302+
restart_menu_up = 1;
303+
}
304+
305+
void restart_menu_close(void) {
306+
restart_menu_anim_timer = RESTART_MENU_ANIM_FRAMES;
307+
restart_menu_up = 0;
308+
}
309+
210310
u8 inv_acquire_pickup(PickupType ptype) {
211311
u8 i, len = pick_type_name_len[ptype];
212312
u16 equip_addr;

src/inventory.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
void inv_init(void);
1414
void inv_update(void);
1515
void inv_animate(void);
16+
void restart_menu_update(void);
17+
void restart_menu_animate(void);
1618

1719
void inv_display_blind();
1820
void inv_display_floor();
@@ -22,11 +24,14 @@ void inv_update_keys(void);
2224

2325
void inv_open(void);
2426
void inv_close(void);
27+
void restart_menu_open(void);
28+
void restart_menu_close(void);
2529

2630
u8 inv_acquire_pickup(PickupType ptype);
2731
void inv_use_pickup(void);
2832

2933
extern u8 inv_anim_up;
3034
extern u8 inv_anim_timer;
35+
extern u8 restart_menu_up;
3136

3237
#endif // INVENTORY_H_

0 commit comments

Comments
 (0)