-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlevel.c
152 lines (115 loc) · 3.19 KB
/
level.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
#include <yaul.h>
#include <assert.h>
#include <stdint.h>
#include <string.h>
#include "cd.h"
#include "enemies.h"
#include "player.h"
#include "scroll.h"
#include "sprite.h"
#include "level.h"
#include "vdp1_hw.h"
#include "print.h"
#include "format_lvl.h"
#define LEVEL_COUNT 4
extern loaded_level_t *loaded_level;
static const char *_level_filenames[] = {
"LEVEL0.LVL",
"LEVEL1.LVL",
"LEVEL0.LVL",
"LEVEL1.LVL"
};
static lvl_t * const _lvl = (lvl_t *)LWRAM(0x00010000);
void
level_init(void)
{
loaded_level->level = -1;
}
/* XXX: Hack */
static void
_level_loading_screen_show(void)
{
vdp2_scrn_display_set(VDP2_SCRN_DISP_NONE);
scroll_backcolor_set(RGB1555(1, 0, 0, 0));
/* XXX: Ugly way of clearing VDP1 screen */
vdp2_sprite_priority_set(0, 0);
vdp1_sync();
vdp2_sync();
vdp1_sync_wait();
vdp2_sync_wait();
vdp2_sprite_priority_set(0, 5);
vdp1_hw_cmdt_list_start(); {
print_buffer(1, 1, "NOW LOADING...");
} vdp1_hw_cmdt_list_finish();
vdp1_sync();
vdp2_sync();
vdp1_sync_wait();
vdp2_sync_wait();
vdp2_scrn_display_set(VDP2_SCRN_DISPTP_NBG0 |
VDP2_SCRN_DISPTP_NBG1 |
VDP2_SCRN_DISPTP_NBG2 |
VDP2_SCRN_DISPTP_NBG3);
}
#define LEVEL_REQUEST_NONE (0)
#define LEVEL_REQUEST_LOAD (1)
#define LEVEL_REQUEST_RELOAD (2)
static uint32_t _loading_request = LEVEL_REQUEST_NONE;
static void
_state_level_reload(void)
{
loaded_level->player_start.x = _lvl->player_x;
loaded_level->player_start.y = _lvl->player_y;
sprite_list_delete_all();
player_lvl_process(_lvl);
scroll_lvl_process(_lvl);
enemies_lvl_process(_lvl);
scroll_backcolor_set(RGB888_RGB1555(1, 36, 34, 52));
const int32_t start_row = (fix16_int32_to(loaded_level->player_start.y) / 224) * 14;
scroll_screen_move(start_row);
}
static void
_state_level_load(void)
{
_level_loading_screen_show();
/* Don't try to read from actual CD */
const char * const level_filename = _level_filenames[loaded_level->level];
cd_load_nosize(level_filename, _lvl);
sprite_load_reset_all();
_state_level_reload();
}
void
level_load_loop(void)
{
if (_loading_request == LEVEL_REQUEST_NONE) {
return;
}
switch (_loading_request) {
case LEVEL_REQUEST_LOAD:
_state_level_load();
break;
case LEVEL_REQUEST_RELOAD:
_state_level_reload();
break;
}
_loading_request = LEVEL_REQUEST_NONE;
}
void
level_load(uint8_t level)
{
if (_loading_request != LEVEL_REQUEST_NONE) {
return;
}
loaded_level->level = level & (LEVEL_COUNT - 1);
_loading_request = LEVEL_REQUEST_LOAD;
}
void
level_reload(void)
{
if (loaded_level->level < 0) {
return;
}
if (_loading_request != LEVEL_REQUEST_NONE) {
return;
}
_loading_request = LEVEL_REQUEST_RELOAD;
}