Browse Source

extend splash, add high-score screens, but not yet functional.

Thomas B 1 month ago
parent
commit
97fb029d4c
6 changed files with 174 additions and 27 deletions
  1. 0
    1
      src/game.c
  2. 51
    5
      src/main.c
  3. 55
    20
      src/maps.c
  4. 5
    1
      src/maps.h
  5. 32
    0
      src/score.c
  6. 31
    0
      src/score.h

+ 0
- 1
src/game.c View File

105
     obj_add(SPR_SHOT_LIGHT, 32, 32, 0, 0);
105
     obj_add(SPR_SHOT_LIGHT, 32, 32, 0, 0);
106
     obj_add(SPR_SHOT_DARK, -32, -32, 0, 0);
106
     obj_add(SPR_SHOT_DARK, -32, -32, 0, 0);
107
 
107
 
108
-    win_game_load();
109
     win_game_draw(score);
108
     win_game_draw(score);
110
     move_win(MINWNDPOSX + 0, MINWNDPOSY + DEVICE_SCREEN_PX_HEIGHT - 16);
109
     move_win(MINWNDPOSX + 0, MINWNDPOSY + DEVICE_SCREEN_PX_HEIGHT - 16);
111
     SHOW_WIN;
110
     SHOW_WIN;

+ 51
- 5
src/main.c View File

30
 #include "sound.h"
30
 #include "sound.h"
31
 #include "input.h"
31
 #include "input.h"
32
 #include "game.h"
32
 #include "game.h"
33
+#include "score.h"
34
+
35
+static void highscore(uint8_t is_black) {
36
+    hide_sprites_range(SPR_NUM_START, MAX_HARDWARE_SPRITES);
37
+    win_score_clear();
38
+
39
+    for (uint8_t i = 0; i < SCORE_NUM; i++) {
40
+        int32_t score = is_black ? -score_lowest(i) : score_highest(i);
41
+        win_score_draw(score, i, is_black);
42
+    }
43
+
44
+    move_win(MINWNDPOSX + 0, MINWNDPOSY);
45
+
46
+    while (1) {
47
+        key_read();
48
+
49
+        if (key_pressed(J_A) || key_pressed(J_B)) {
50
+            break;
51
+        }
52
+
53
+        vsync();
54
+    }
55
+}
56
+
57
+static void splash_win(void) {
58
+    // initially show the top 1 scores
59
+    int32_t low = score_lowest(0);
60
+    int32_t high = score_highest(0);
61
+
62
+    // only show on splash if they fit
63
+    if ((low >= -99999) && (high <= 99999)) {
64
+        win_splash_draw(-low, high);
65
+    }
66
+
67
+    move_win(MINWNDPOSX + 0, MINWNDPOSY + DEVICE_SCREEN_PX_HEIGHT - 16);
68
+    SHOW_WIN;
69
+}
33
 
70
 
34
 static void splash(void) {
71
 static void splash(void) {
35
     disable_interrupts();
72
     disable_interrupts();
45
     obj_add(SPR_LIGHT, 42, -42, 0, 0);
82
     obj_add(SPR_LIGHT, 42, -42, 0, 0);
46
     obj_add(SPR_DARK, -42, -42, 0, 0);
83
     obj_add(SPR_DARK, -42, -42, 0, 0);
47
 
84
 
48
-    while(1) {
85
+    splash_win();
86
+
87
+    while (1) {
49
         key_read();
88
         key_read();
50
-        if (key_down(0xFF)) {
89
+
90
+        if (key_pressed(J_LEFT)) {
91
+            highscore(1);
92
+            splash_win();
93
+        } else if (key_pressed(J_RIGHT)) {
94
+            highscore(0);
95
+            splash_win();
96
+        } else if (key_pressed(0xFF)) {
51
             break;
97
             break;
52
         }
98
         }
53
 
99
 
62
 void main(void) {
108
 void main(void) {
63
     spr_init();
109
     spr_init();
64
     snd_init();
110
     snd_init();
111
+    win_init();
65
 
112
 
66
-#ifndef DEBUG
67
     splash();
113
     splash();
68
-#endif // DEBUG
69
 
114
 
70
     uint16_t seed = DIV_REG;
115
     uint16_t seed = DIV_REG;
71
     waitpadup();
116
     waitpadup();
74
 
119
 
75
     while (1) {
120
     while (1) {
76
         int32_t score = game();
121
         int32_t score = game();
77
-        // TODO
122
+        score_add(score);
123
+        splash();
78
     }
124
     }
79
 }
125
 }

+ 55
- 20
src/maps.c View File

21
 
21
 
22
 #include "maps.h"
22
 #include "maps.h"
23
 
23
 
24
+#include "gb/gb.h"
24
 #include "title_map.h"
25
 #include "title_map.h"
25
 #include "bg_map.h"
26
 #include "bg_map.h"
26
 #include "numbers.h"
27
 #include "numbers.h"
38
     0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,
39
     0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,
39
     0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,
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
 const palette_color_t num_pal_inv[4] = {
43
 const palette_color_t num_pal_inv[4] = {
42
   //RGB8(  0,  0,  0), RGB8(248,252,248), RGB8(  0,  0,  0), RGB8(  0,  0,  0)
44
   //RGB8(  0,  0,  0), RGB8(248,252,248), RGB8(  0,  0,  0), RGB8(  0,  0,  0)
43
     RGB8(  0,  0,  0), RGB8(  0,  0,  0), RGB8(248,252,248), RGB8(  0,  0,  0)
45
     RGB8(  0,  0,  0), RGB8(  0,  0,  0), RGB8(248,252,248), RGB8(  0,  0,  0)
57
     set_bkg_tiles(0, 0, bg_map_WIDTH / bg_map_TILE_W, bg_map_HEIGHT / bg_map_TILE_H, bg_map_map);
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
     VBK_REG = VBK_ATTRIBUTES;
70
     VBK_REG = VBK_ATTRIBUTES;
63
     set_win_tiles(x, y, w, h, attributes);
71
     set_win_tiles(x, y, w, h, attributes);
64
     VBK_REG = VBK_TILES;
72
     VBK_REG = VBK_TILES;
65
     set_win_based_tiles(x, y, w, h, tiles, base_tile);
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
     uint8_t off = val * numbers_WIDTH / numbers_TILE_W;
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
                   numbers_WIDTH / numbers_TILE_W, 1,
80
                   numbers_WIDTH / numbers_TILE_W, 1,
73
                   numbers_map + off, bg_map_TILE_COUNT,
81
                   numbers_map + off, bg_map_TILE_COUNT,
74
                   (is_black ? num_attr_2 : num_attr_1) + off);
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
                   numbers_WIDTH / numbers_TILE_W, 1,
85
                   numbers_WIDTH / numbers_TILE_W, 1,
78
                   numbers_map + off + (sizeof(numbers_map) / 2), bg_map_TILE_COUNT,
86
                   numbers_map + off + (sizeof(numbers_map) / 2), bg_map_TILE_COUNT,
79
                   (is_black ? num_attr_2 : num_attr_1) + off);
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
     // TODO can not set numbers larger than int16 max?!
91
     // TODO can not set numbers larger than int16 max?!
91
     //score = 32767 + 1; // wtf?!
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
     uint8_t len = 0;
94
     uint8_t len = 0;
100
     uint8_t digits[MAX_DIGITS];
95
     uint8_t digits[MAX_DIGITS];
101
     do {
96
     do {
111
         return;
106
         return;
112
     }
107
     }
113
 
108
 
109
+    uint8_t off = (x_off == 0xFF) ? (10 - len) : ((x_off == 0xFE) ? (20 - (len * 2)) : x_off);
114
     for (uint8_t i = 0; i < len; i++) {
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
 }

+ 5
- 1
src/maps.h View File

24
 
24
 
25
 void map_title(void);
25
 void map_title(void);
26
 void map_game(void);
26
 void map_game(void);
27
-void win_game_load(void);
27
+
28
+void win_init(void);
29
+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);
28
 void win_game_draw(int32_t score);
32
 void win_game_draw(int32_t score);
29
 
33
 
30
 #endif // __MAPS_H__
34
 #endif // __MAPS_H__

+ 32
- 0
src/score.c View File

1
+/*
2
+ * score.c
3
+ * Duality
4
+ *
5
+ * Copyright (C) 2025 Thomas Buck <thomas@xythobuz.de>
6
+ *
7
+ * This program is free software: you can redistribute it and/or modify
8
+ * it under the terms of the GNU General Public License as published by
9
+ * the Free Software Foundation, either version 3 of the License, or
10
+ * (at your option) any later version.
11
+ *
12
+ * This program is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
+ * GNU General Public License for more details.
16
+ *
17
+ * See <http://www.gnu.org/licenses/>.
18
+ */
19
+
20
+#include "score.h"
21
+
22
+void score_add(int32_t score) {
23
+
24
+}
25
+
26
+int32_t score_highest(uint8_t off) {
27
+    return 8888 - off;
28
+}
29
+
30
+int32_t score_lowest(uint8_t off) {
31
+    return -(9999 - off);
32
+}

+ 31
- 0
src/score.h View File

1
+/*
2
+ * score.h
3
+ * Duality
4
+ *
5
+ * Copyright (C) 2025 Thomas Buck <thomas@xythobuz.de>
6
+ *
7
+ * This program is free software: you can redistribute it and/or modify
8
+ * it under the terms of the GNU General Public License as published by
9
+ * the Free Software Foundation, either version 3 of the License, or
10
+ * (at your option) any later version.
11
+ *
12
+ * This program is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
+ * GNU General Public License for more details.
16
+ *
17
+ * See <http://www.gnu.org/licenses/>.
18
+ */
19
+
20
+#ifndef __SCORE_H__
21
+#define __SCORE_H__
22
+
23
+#include <stdint.h>
24
+
25
+#define SCORE_NUM 5
26
+
27
+void score_add(int32_t score);
28
+int32_t score_highest(uint8_t off);
29
+int32_t score_lowest(uint8_t off);
30
+
31
+#endif // __SCORE_H__

Loading…
Cancel
Save