|
@@ -21,6 +21,7 @@
|
21
|
21
|
|
22
|
22
|
#include "maps.h"
|
23
|
23
|
|
|
24
|
+#include "gb/gb.h"
|
24
|
25
|
#include "title_map.h"
|
25
|
26
|
#include "bg_map.h"
|
26
|
27
|
#include "numbers.h"
|
|
@@ -38,6 +39,7 @@ const unsigned char num_attr_2[40] = {
|
38
|
39
|
0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,
|
39
|
40
|
0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,
|
40
|
41
|
};
|
|
42
|
+
|
41
|
43
|
const palette_color_t num_pal_inv[4] = {
|
42
|
44
|
//RGB8( 0, 0, 0), RGB8(248,252,248), RGB8( 0, 0, 0), RGB8( 0, 0, 0)
|
43
|
45
|
RGB8( 0, 0, 0), RGB8( 0, 0, 0), RGB8(248,252,248), RGB8( 0, 0, 0)
|
|
@@ -57,45 +59,38 @@ void map_game(void) {
|
57
|
59
|
set_bkg_tiles(0, 0, bg_map_WIDTH / bg_map_TILE_W, bg_map_HEIGHT / bg_map_TILE_H, bg_map_map);
|
58
|
60
|
}
|
59
|
61
|
|
60
|
|
-inline void set_win_based(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t *tiles, uint8_t base_tile, const uint8_t *attributes)
|
61
|
|
-{
|
|
62
|
+void win_init(void) {
|
|
63
|
+ set_bkg_palette(OAMF_CGB_PAL0 + bg_map_PALETTE_COUNT, numbers_PALETTE_COUNT, numbers_palettes);
|
|
64
|
+ set_bkg_palette(OAMF_CGB_PAL0 + bg_map_PALETTE_COUNT + 1, numbers_PALETTE_COUNT, num_pal_inv);
|
|
65
|
+ set_win_data(bg_map_TILE_COUNT, numbers_TILE_COUNT, numbers_tiles);
|
|
66
|
+}
|
|
67
|
+
|
|
68
|
+static void set_win_based(uint8_t x, uint8_t y, uint8_t w, uint8_t h,
|
|
69
|
+ const uint8_t *tiles, uint8_t base_tile, const uint8_t *attributes) {
|
62
|
70
|
VBK_REG = VBK_ATTRIBUTES;
|
63
|
71
|
set_win_tiles(x, y, w, h, attributes);
|
64
|
72
|
VBK_REG = VBK_TILES;
|
65
|
73
|
set_win_based_tiles(x, y, w, h, tiles, base_tile);
|
66
|
74
|
}
|
67
|
75
|
|
68
|
|
-static void digit(uint8_t val, uint8_t digit, uint8_t x_off, uint8_t is_black) {
|
|
76
|
+static void digit(uint8_t val, uint8_t digit, uint8_t x_off, uint8_t y_off, uint8_t is_black) {
|
69
|
77
|
uint8_t off = val * numbers_WIDTH / numbers_TILE_W;
|
70
|
78
|
|
71
|
|
- set_win_based(x_off + (digit * numbers_WIDTH / numbers_TILE_W), 0,
|
|
79
|
+ set_win_based(x_off + (digit * numbers_WIDTH / numbers_TILE_W), y_off,
|
72
|
80
|
numbers_WIDTH / numbers_TILE_W, 1,
|
73
|
81
|
numbers_map + off, bg_map_TILE_COUNT,
|
74
|
82
|
(is_black ? num_attr_2 : num_attr_1) + off);
|
75
|
83
|
|
76
|
|
- set_win_based(x_off + (digit * numbers_WIDTH / numbers_TILE_W), 1,
|
|
84
|
+ set_win_based(x_off + (digit * numbers_WIDTH / numbers_TILE_W), y_off + 1,
|
77
|
85
|
numbers_WIDTH / numbers_TILE_W, 1,
|
78
|
86
|
numbers_map + off + (sizeof(numbers_map) / 2), bg_map_TILE_COUNT,
|
79
|
87
|
(is_black ? num_attr_2 : num_attr_1) + off);
|
80
|
88
|
}
|
81
|
89
|
|
82
|
|
-
|
83
|
|
-void win_game_load(void) {
|
84
|
|
- set_bkg_palette(OAMF_CGB_PAL0 + bg_map_PALETTE_COUNT, numbers_PALETTE_COUNT, numbers_palettes);
|
85
|
|
- set_bkg_palette(OAMF_CGB_PAL0 + bg_map_PALETTE_COUNT + 1, numbers_PALETTE_COUNT, num_pal_inv);
|
86
|
|
- set_win_data(bg_map_TILE_COUNT, numbers_TILE_COUNT, numbers_tiles);
|
87
|
|
-}
|
88
|
|
-
|
89
|
|
-void win_game_draw(int32_t score) {
|
|
90
|
+static void number(int32_t score, uint8_t x_off, uint8_t y_off, uint8_t is_black) {
|
90
|
91
|
// TODO can not set numbers larger than int16 max?!
|
91
|
92
|
//score = 32767 + 1; // wtf?!
|
92
|
93
|
|
93
|
|
- uint8_t is_black = 0;
|
94
|
|
- if (score < 0) {
|
95
|
|
- score = -score;
|
96
|
|
- is_black = 1;
|
97
|
|
- }
|
98
|
|
-
|
99
|
94
|
uint8_t len = 0;
|
100
|
95
|
uint8_t digits[MAX_DIGITS];
|
101
|
96
|
do {
|
|
@@ -111,7 +106,47 @@ void win_game_draw(int32_t score) {
|
111
|
106
|
return;
|
112
|
107
|
}
|
113
|
108
|
|
|
109
|
+ uint8_t off = (x_off == 0xFF) ? (10 - len) : ((x_off == 0xFE) ? (20 - (len * 2)) : x_off);
|
114
|
110
|
for (uint8_t i = 0; i < len; i++) {
|
115
|
|
- digit(digits[len - i - 1], i, 10 - len, is_black);
|
|
111
|
+ digit(digits[len - i - 1], i, off, y_off, is_black);
|
|
112
|
+ }
|
|
113
|
+}
|
|
114
|
+
|
|
115
|
+static void fill_win(uint8_t x, uint8_t y, uint8_t w, uint8_t h, uint8_t tile, uint8_t attr) {
|
|
116
|
+ VBK_REG = VBK_ATTRIBUTES;
|
|
117
|
+ fill_win_rect(x, y, w, h, attr);
|
|
118
|
+ VBK_REG = VBK_TILES;
|
|
119
|
+ fill_win_rect(x, y, w, h, tile);
|
|
120
|
+}
|
|
121
|
+
|
|
122
|
+void win_splash_draw(int32_t lowest, int32_t highest) {
|
|
123
|
+ // reuse full black and white tiles at 0 and 1 from splash bg
|
|
124
|
+ fill_win(0, 0, 10, 2, 0, 0x00);
|
|
125
|
+ fill_win(10, 0, 10, 2, 1, 0x00);
|
|
126
|
+
|
|
127
|
+ number(lowest, 0, 0, 1);
|
|
128
|
+ number(highest, 0xFE, 0, 0);
|
|
129
|
+}
|
|
130
|
+
|
|
131
|
+void win_score_clear(void) {
|
|
132
|
+ set_win_based(0, 0,
|
|
133
|
+ title_map_WIDTH / title_map_TILE_W, title_map_HEIGHT / title_map_TILE_H,
|
|
134
|
+ title_map_map, 0, title_map_MAP_ATTRIBUTES);
|
|
135
|
+}
|
|
136
|
+
|
|
137
|
+void win_score_draw(int32_t score, uint8_t off, uint8_t is_black) {
|
|
138
|
+ number(off, 1, 4 + off * 3, is_black);
|
|
139
|
+ number(score, 5, 4 + off * 3, is_black);
|
|
140
|
+}
|
|
141
|
+
|
|
142
|
+void win_game_draw(int32_t score) {
|
|
143
|
+ fill_win(0, 0, 20, 2, bg_map_TILE_COUNT + numbers_TILE_COUNT, 0x81);
|
|
144
|
+
|
|
145
|
+ uint8_t is_black = 0;
|
|
146
|
+ if (score < 0) {
|
|
147
|
+ score = -score;
|
|
148
|
+ is_black = 1;
|
116
|
149
|
}
|
|
150
|
+
|
|
151
|
+ number(score, 0xFF, 0, is_black);
|
117
|
152
|
}
|