Browse Source

add letters to show names in highscore

Thomas B 1 month ago
parent
commit
32a0222f5f
8 changed files with 89 additions and 36 deletions
  1. 2
    2
      Makefile
  2. 0
    0
      data/numbers_fnt.png
  3. BIN
      data/text_fnt.png
  4. 1
    0
      src/game.c
  5. 4
    3
      src/main.c
  6. 72
    22
      src/maps.c
  7. 4
    3
      src/maps.h
  8. 6
    6
      src/score.ba0.c

+ 2
- 2
Makefile View File

@@ -85,9 +85,9 @@ $(BUILD_DIR)/$(DATA_DIR)/%.c $(BUILD_DIR)/$(DATA_DIR)/%.h: $(DATA_DIR)/%.png
85 85
 	$(if $(findstring _map,$<),           \
86 86
 		@echo "Converting map $<" &&  \
87 87
 		$(PNGA) $< -o $@ -spr8x8 -map -use_map_attributes -noflip \
88
-	,$(if $(findstring numbers,$<), \
88
+	,$(if $(findstring _fnt,$<), \
89 89
 		@echo "Converting font $<" && \
90
-		$(PNGA) $< -o $@ -spr8x8 -sw 16 -sh 16 -map \
90
+		$(PNGA) $< -o $@ -spr8x8 -sw 16 -sh 16 -map -noflip \
91 91
 	,                                     \
92 92
 		@echo "Converting tile $<" && \
93 93
 		$(PNGA) $< -o $@ -spr8x8      \

data/numbers.png → data/numbers_fnt.png View File


BIN
data/text_fnt.png View File


+ 1
- 0
src/game.c View File

@@ -103,6 +103,7 @@ int32_t game(void) NONBANKED {
103 103
     obj_add(SPR_SHOT_LIGHT, 32, 32, 0, 0);
104 104
     obj_add(SPR_SHOT_DARK, -32, -32, 0, 0);
105 105
 
106
+    win_init(0);
106 107
     uint8_t x_off = win_game_draw(score);
107 108
     move_win(MINWNDPOSX + DEVICE_SCREEN_PX_WIDTH - x_off, MINWNDPOSY + DEVICE_SCREEN_PX_HEIGHT - 16);
108 109
 

+ 4
- 3
src/main.c View File

@@ -36,10 +36,11 @@ static void highscore(uint8_t is_black) NONBANKED {
36 36
     HIDE_WIN;
37 37
 
38 38
     hide_sprites_range(SPR_NUM_START, MAX_HARDWARE_SPRITES);
39
-    win_score_clear();
39
+    win_score_clear(is_black);
40 40
 
41 41
     for (uint8_t i = 0; i < SCORE_NUM; i++) {
42
-        int32_t score = is_black ? -score_lowest(i).score : score_highest(i).score;
42
+
43
+        struct scores score = is_black ? score_lowest(i) : score_highest(i);
43 44
         win_score_draw(score, i, is_black);
44 45
     }
45 46
 
@@ -85,6 +86,7 @@ static void splash(void) NONBANKED {
85 86
     obj_add(SPR_LIGHT, 42, -42, 0, 0);
86 87
     obj_add(SPR_DARK, -42, -42, 0, 0);
87 88
 
89
+    win_init(1);
88 90
     splash_win();
89 91
 
90 92
     DISPLAY_ON;
@@ -114,7 +116,6 @@ static void splash(void) NONBANKED {
114 116
 void main(void) NONBANKED {
115 117
     spr_init();
116 118
     snd_init();
117
-    win_init();
118 119
 
119 120
     splash();
120 121
 

+ 72
- 22
src/maps.c View File

@@ -22,22 +22,32 @@
22 22
 #include "maps.h"
23 23
 
24 24
 #include "gb/gb.h"
25
+#include "score.h"
25 26
 #include "title_map.h"
26 27
 #include "bg_map.h"
27
-#include "numbers.h"
28
+#include "numbers_fnt.h"
29
+#include "text_fnt.h"
28 30
 
29 31
 #define MAX_DIGITS 7
30 32
 
31 33
 // TODO inverted score color not visible on DMG
32 34
 
33
-const unsigned char num_attr_1[40] = {
35
+const unsigned char num_attr_1[104] = {
34 36
     0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,
35 37
     0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,
38
+    0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,
39
+    0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,
40
+    0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,0x81,
41
+    0x81,0x81,0x81,0x81,
36 42
 };
37 43
 
38
-const unsigned char num_attr_2[40] = {
44
+const unsigned char num_attr_2[104] = {
45
+    0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,
46
+    0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,
47
+    0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,
39 48
     0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,
40 49
     0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,
50
+    0x82,0x82,0x82,0x82,
41 51
 };
42 52
 
43 53
 const palette_color_t num_pal_inv[4] = {
@@ -45,6 +55,8 @@ const palette_color_t num_pal_inv[4] = {
45 55
     RGB8(  0,  0,  0), RGB8(  0,  0,  0), RGB8(248,252,248), RGB8(  0,  0,  0)
46 56
 };
47 57
 
58
+static uint8_t fnt_off = 0;
59
+
48 60
 void map_title(void) NONBANKED {
49 61
     SWITCH_ROM(BANK(title_map));
50 62
     set_bkg_palette(OAMF_CGB_PAL0, title_map_PALETTE_COUNT, title_map_palettes);
@@ -61,11 +73,18 @@ void map_game(void) NONBANKED {
61 73
     set_bkg_tiles(0, 0, bg_map_WIDTH / bg_map_TILE_W, bg_map_HEIGHT / bg_map_TILE_H, bg_map_map);
62 74
 }
63 75
 
64
-void win_init(void) NONBANKED {
65
-    SWITCH_ROM(BANK(numbers));
66
-    set_bkg_palette(OAMF_CGB_PAL0 + bg_map_PALETTE_COUNT, numbers_PALETTE_COUNT, numbers_palettes);
67
-    set_bkg_palette(OAMF_CGB_PAL0 + bg_map_PALETTE_COUNT + 1, numbers_PALETTE_COUNT, num_pal_inv);
68
-    set_win_data(bg_map_TILE_COUNT, numbers_TILE_COUNT, numbers_tiles);
76
+void win_init(uint8_t is_splash) NONBANKED {
77
+    fnt_off = is_splash ? title_map_TILE_COUNT : bg_map_TILE_COUNT;
78
+
79
+    SWITCH_ROM(BANK(numbers_fnt));
80
+    set_bkg_palette(OAMF_CGB_PAL0 + bg_map_PALETTE_COUNT, numbers_fnt_PALETTE_COUNT, numbers_fnt_palettes);
81
+    set_bkg_palette(OAMF_CGB_PAL0 + bg_map_PALETTE_COUNT + numbers_fnt_PALETTE_COUNT, numbers_fnt_PALETTE_COUNT, num_pal_inv);
82
+    set_win_data(fnt_off, numbers_fnt_TILE_COUNT, numbers_fnt_tiles);
83
+
84
+    if (is_splash) {
85
+        SWITCH_ROM(BANK(text_fnt));
86
+        set_win_data(fnt_off + numbers_fnt_TILE_COUNT, text_fnt_TILE_COUNT, text_fnt_tiles);
87
+    }
69 88
 }
70 89
 
71 90
 static void set_win_based(uint8_t x, uint8_t y, uint8_t w, uint8_t h,
@@ -76,18 +95,47 @@ static void set_win_based(uint8_t x, uint8_t y, uint8_t w, uint8_t h,
76 95
     set_win_based_tiles(x, y, w, h, tiles, base_tile);
77 96
 }
78 97
 
79
-static void digit(uint8_t val, uint8_t digit, uint8_t x_off, uint8_t y_off, uint8_t is_black) NONBANKED {
80
-    SWITCH_ROM(BANK(numbers));
81
-    uint8_t off = val * numbers_WIDTH / numbers_TILE_W;
98
+static void character(uint8_t c, uint8_t pos, uint8_t x_off, uint8_t y_off, uint8_t is_black) NONBANKED {
99
+    SWITCH_ROM(BANK(text_fnt));
100
+    uint8_t off = c * text_fnt_WIDTH / text_fnt_TILE_W;
101
+
102
+    set_win_based(x_off + (pos * text_fnt_WIDTH / text_fnt_TILE_W), y_off,
103
+                  text_fnt_WIDTH / text_fnt_TILE_W, 1,
104
+                  text_fnt_map + off, fnt_off + numbers_fnt_TILE_COUNT,
105
+                  (is_black ? num_attr_2 : num_attr_1) + off);
106
+
107
+    set_win_based(x_off + (pos * text_fnt_WIDTH / text_fnt_TILE_W), y_off + 1,
108
+                  text_fnt_WIDTH / text_fnt_TILE_W, 1,
109
+                  text_fnt_map + off + (sizeof(text_fnt_map) / 2), fnt_off + numbers_fnt_TILE_COUNT,
110
+                  (is_black ? num_attr_2 : num_attr_1) + off);
111
+}
112
+
113
+static void str3(uint16_t name, uint8_t x_off, uint8_t y_off, uint8_t is_black) NONBANKED {
114
+    character((name >> 10) & 0x1F, 0, x_off, y_off, is_black);
115
+    character((name >>  5) & 0x1F, 1, x_off, y_off, is_black);
116
+    character((name >>  0) & 0x1F, 2, x_off, y_off, is_black);
117
+}
82 118
 
83
-    set_win_based(x_off + (digit * numbers_WIDTH / numbers_TILE_W), y_off,
84
-                  numbers_WIDTH / numbers_TILE_W, 1,
85
-                  numbers_map + off, bg_map_TILE_COUNT,
119
+static void str(const char *s, uint8_t x_off, uint8_t y_off, uint8_t is_black) NONBANKED {
120
+    uint8_t n = 0;
121
+    while (*s) {
122
+        character(*s - 'a', n++, x_off, y_off, is_black);
123
+        s++;
124
+    }
125
+}
126
+
127
+static void digit(uint8_t val, uint8_t pos, uint8_t x_off, uint8_t y_off, uint8_t is_black) NONBANKED {
128
+    SWITCH_ROM(BANK(numbers_fnt));
129
+    uint8_t off = val * numbers_fnt_WIDTH / numbers_fnt_TILE_W;
130
+
131
+    set_win_based(x_off + (pos * numbers_fnt_WIDTH / numbers_fnt_TILE_W), y_off,
132
+                  numbers_fnt_WIDTH / numbers_fnt_TILE_W, 1,
133
+                  numbers_fnt_map + off, fnt_off,
86 134
                   (is_black ? num_attr_2 : num_attr_1) + off);
87 135
 
88
-    set_win_based(x_off + (digit * numbers_WIDTH / numbers_TILE_W), y_off + 1,
89
-                  numbers_WIDTH / numbers_TILE_W, 1,
90
-                  numbers_map + off + (sizeof(numbers_map) / 2), bg_map_TILE_COUNT,
136
+    set_win_based(x_off + (pos * numbers_fnt_WIDTH / numbers_fnt_TILE_W), y_off + 1,
137
+                  numbers_fnt_WIDTH / numbers_fnt_TILE_W, 1,
138
+                  numbers_fnt_map + off + (sizeof(numbers_fnt_map) / 2), fnt_off,
91 139
                   (is_black ? num_attr_2 : num_attr_1) + off);
92 140
 }
93 141
 
@@ -134,20 +182,22 @@ void win_splash_draw(int32_t lowest, int32_t highest) NONBANKED {
134 182
     number(highest, 0xFE, 0, 0);
135 183
 }
136 184
 
137
-void win_score_clear(void) NONBANKED {
185
+void win_score_clear(uint8_t is_black) NONBANKED {
138 186
     SWITCH_ROM(BANK(title_map));
139 187
     set_win_based(0, 0,
140 188
                   title_map_WIDTH / title_map_TILE_W, title_map_HEIGHT / title_map_TILE_H,
141 189
                   title_map_map, 0, title_map_MAP_ATTRIBUTES);
190
+
191
+    str(is_black ? "black" : "white", 10 - 5, 1, is_black);
142 192
 }
143 193
 
144
-void win_score_draw(int32_t score, uint8_t off, uint8_t is_black) NONBANKED {
145
-    number(off, 1, 4 + off * 3, is_black);
146
-    number(score, 5, 4 + off * 3, is_black);
194
+void win_score_draw(struct scores score, uint8_t off, uint8_t is_black) NONBANKED {
195
+    str3(score.name, 0, 4 + off * 3, is_black);
196
+    number(is_black ? -score.score : score.score, 7, 4 + off * 3, is_black);
147 197
 }
148 198
 
149 199
 uint8_t win_game_draw(int32_t score) NONBANKED {
150
-    fill_win(0, 0, 10, 2, (uint8_t)bg_map_TILE_COUNT + (uint8_t)numbers_TILE_COUNT, 0x81);
200
+    fill_win(0, 0, 10, 2, fnt_off + numbers_fnt_TILE_COUNT, 0x81);
151 201
 
152 202
     uint8_t is_black = 0;
153 203
     if (score < 0) {

+ 4
- 3
src/maps.h View File

@@ -21,14 +21,15 @@
21 21
 #define __MAPS_H__
22 22
 
23 23
 #include <stdint.h>
24
+#include "score.h"
24 25
 
25 26
 void map_title(void);
26 27
 void map_game(void);
27 28
 
28
-void win_init(void);
29
+void win_init(uint8_t is_splash);
29 30
 void win_splash_draw(int32_t lowest, int32_t highest);
30
-void win_score_clear(void);
31
-void win_score_draw(int32_t score, uint8_t off, uint8_t is_black);
31
+void win_score_clear(uint8_t is_black);
32
+void win_score_draw(struct scores score, uint8_t off, uint8_t is_black);
32 33
 uint8_t win_game_draw(int32_t score);
33 34
 
34 35
 #endif // __MAPS_H__

+ 6
- 6
src/score.ba0.c View File

@@ -69,13 +69,13 @@ static void score_init(void) NONBANKED {
69 69
     scores[0].score = 10000;
70 70
 
71 71
     scores[1].name = convert_name('a', 'b', 'c');
72
-    scores[1].score = 8000;
72
+    scores[1].score = 8765;
73 73
 
74 74
     scores[2].name = convert_name('a', 'b', 'c');
75
-    scores[2].score = 6000;
75
+    scores[2].score = 6999;
76 76
 
77 77
     scores[3].name = convert_name('a', 'b', 'c');
78
-    scores[3].score = 4000;
78
+    scores[3].score = 4321;
79 79
 
80 80
     scores[4].name = convert_name('a', 'b', 'c');
81 81
     scores[4].score = 2000;
@@ -84,13 +84,13 @@ static void score_init(void) NONBANKED {
84 84
     scores[5].score = -2000;
85 85
 
86 86
     scores[6].name = convert_name('a', 'b', 'c');
87
-    scores[6].score = -4000;
87
+    scores[6].score = -4321;
88 88
 
89 89
     scores[7].name = convert_name('a', 'b', 'c');
90
-    scores[7].score = -6000;
90
+    scores[7].score = -6999;
91 91
 
92 92
     scores[8].name = convert_name('a', 'b', 'c');
93
-    scores[8].score = -8000;
93
+    scores[8].score = -8765;
94 94
 
95 95
     scores[9].name = convert_name('a', 'b', 'c');
96 96
     scores[9].score = -10000;

Loading…
Cancel
Save