Browse Source

pixel resolution status bars. also start with scoring and pickups.

Thomas B 1 month ago
parent
commit
e43390cee8
15 changed files with 236 additions and 49 deletions
  1. BIN
      data/bar_1.png
  2. BIN
      data/bar_2.png
  3. BIN
      data/bar_3.png
  4. BIN
      data/bar_4.png
  5. BIN
      data/bar_5.png
  6. BIN
      data/bar_6.png
  7. BIN
      data/bar_7.png
  8. 0
    0
      data/bar_8.png
  9. 34
    18
      src/game.c
  10. 3
    1
      src/game.h
  11. 4
    2
      src/main.c
  12. 28
    4
      src/obj.c
  13. 1
    1
      src/obj.h
  14. 150
    21
      src/sprites.c
  15. 16
    2
      src/sprites.h

BIN
data/bar_1.png View File


BIN
data/bar_2.png View File


BIN
data/bar_3.png View File


BIN
data/bar_4.png View File


BIN
data/bar_5.png View File


BIN
data/bar_6.png View File


BIN
data/bar_7.png View File


data/health.png → data/bar_8.png View File


+ 34
- 18
src/game.c View File

@@ -20,7 +20,6 @@
20 20
 #include <gbdk/platform.h>
21 21
 #include <gbdk/metasprites.h>
22 22
 #include <rand.h>
23
-#include <stdint.h>
24 23
 
25 24
 #include "maps.h"
26 25
 #include "obj.h"
@@ -43,31 +42,39 @@ static void status(uint8_t health, uint8_t power, uint8_t *hiwater) {
43 42
     if (health > 0) {
44 43
         switch (health >> 6) {
45 44
             case 3:
46
-                spr_draw(SPR_HEALTH, FLIP_X, BAR_OFFSET_X, HEALTH_OFFSET_Y - 24, hiwater);
45
+                spr_draw(SPR_HEALTH_1 + (((health >> 6) == 3) ? ((health >> 3) & 7) : 7),
46
+                         FLIP_X, BAR_OFFSET_X, HEALTH_OFFSET_Y - 24, hiwater);
47 47
             case 2:
48
-                spr_draw(SPR_HEALTH, FLIP_X, BAR_OFFSET_X, HEALTH_OFFSET_Y - 16, hiwater);
48
+                spr_draw(SPR_HEALTH_1 + (((health >> 6) == 2) ? ((health >> 3) & 7) : 7),
49
+                         FLIP_X, BAR_OFFSET_X, HEALTH_OFFSET_Y - 16, hiwater);
49 50
             case 1:
50
-                spr_draw(SPR_HEALTH, FLIP_X, BAR_OFFSET_X, HEALTH_OFFSET_Y - 8, hiwater);
51
+                spr_draw(SPR_HEALTH_1 + (((health >> 6) == 1) ? ((health >> 3) & 7) : 7),
52
+                         FLIP_X, BAR_OFFSET_X, HEALTH_OFFSET_Y - 8, hiwater);
51 53
             case 0:
52
-                spr_draw(SPR_HEALTH, FLIP_X, BAR_OFFSET_X, HEALTH_OFFSET_Y - 0, hiwater);
54
+                spr_draw(SPR_HEALTH_1 + (((health >> 6) == 0) ? ((health >> 3) & 7) : 7),
55
+                         FLIP_X, BAR_OFFSET_X, HEALTH_OFFSET_Y - 0, hiwater);
53 56
         }
54 57
     }
55 58
 
56 59
     if (power > 0) {
57 60
         switch (power >> 6) {
58 61
             case 3:
59
-                spr_draw(SPR_POWER, FLIP_X, BAR_OFFSET_X, POWER_OFFSET_Y + 0, hiwater);
62
+                spr_draw(SPR_POWER_1 + (((power >> 6) == 3) ? ((power >> 3) & 7) : 7),
63
+                         FLIP_X, BAR_OFFSET_X, POWER_OFFSET_Y + 0, hiwater);
60 64
             case 2:
61
-                spr_draw(SPR_POWER, FLIP_X, BAR_OFFSET_X, POWER_OFFSET_Y + 8, hiwater);
65
+                spr_draw(SPR_POWER_1 + (((power >> 6) == 2) ? ((power >> 3) & 7) : 7),
66
+                         FLIP_X, BAR_OFFSET_X, POWER_OFFSET_Y + 8, hiwater);
62 67
             case 1:
63
-                spr_draw(SPR_POWER, FLIP_X, BAR_OFFSET_X, POWER_OFFSET_Y + 16, hiwater);
68
+                spr_draw(SPR_POWER_1 + (((power >> 6) == 1) ? ((power >> 3) & 7) : 7),
69
+                         FLIP_X, BAR_OFFSET_X, POWER_OFFSET_Y + 16, hiwater);
64 70
             case 0:
65
-                spr_draw(SPR_POWER, FLIP_X, BAR_OFFSET_X, POWER_OFFSET_Y + 24, hiwater);
71
+                spr_draw(SPR_POWER_1 + (((power >> 6) == 0) ? ((power >> 3) & 7) : 7),
72
+                         FLIP_X, BAR_OFFSET_X, POWER_OFFSET_Y + 24, hiwater);
66 73
         }
67 74
     }
68 75
 }
69 76
 
70
-void game(void) {
77
+int32_t game(void) {
71 78
     disable_interrupts();
72 79
     DISPLAY_OFF;
73 80
     map_game();
@@ -86,13 +93,14 @@ void game(void) {
86 93
     uint8_t ship_hiwater = 0;
87 94
     uint16_t health = HEALTH_MAX;
88 95
     uint16_t power = POWER_MAX;
96
+    int32_t score = 0;
89 97
 
90 98
     obj_init();
91 99
 
92 100
     // TODO remove
93 101
     obj_add(SPR_LIGHT, 64, 64, 0, 0);
94 102
     //obj_add(SPR_DARK, -64, -64, 0, 0);
95
-    obj_add(SPR_DARK, -32, 0, 0, 0);
103
+    //obj_add(SPR_DARK, -32, 0, 0, 0);
96 104
     obj_add(SPR_SHOT_LIGHT, 32, 32, 0, 0);
97 105
     obj_add(SPR_SHOT_DARK, -32, -32, 0, 0);
98 106
 
@@ -152,13 +160,19 @@ void game(void) {
152 160
             }
153 161
         }
154 162
 
155
-        uint8_t damage = obj_act(&spd_x, &spd_y);
156
-        if (health > damage) {
157
-            health -= damage;
158
-        } else if (health < damage) {
159
-            health = 0;
160
-
161
-            // TODO
163
+        int16_t damage = obj_act(&spd_x, &spd_y, &score);
164
+        if (damage > 0) {
165
+            if (health > damage) {
166
+                health -= damage;
167
+            } else if (health <= damage) {
168
+                health = 0;
169
+                break;
170
+            }
171
+        } else if (damage < 0) {
172
+            health += -damage;
173
+            if (health > HEALTH_MAX) {
174
+                health = HEALTH_MAX;
175
+            }
162 176
         }
163 177
 
164 178
         // adjust speed down when not moving
@@ -226,4 +240,6 @@ void game(void) {
226 240
 
227 241
         vsync();
228 242
     }
243
+
244
+    return score;
229 245
 }

+ 3
- 1
src/game.h View File

@@ -20,6 +20,8 @@
20 20
 #ifndef __GAME_H__
21 21
 #define __GAME_H__
22 22
 
23
+#include <stdint.h>
24
+
23 25
 #define SPEED_INC 1
24 26
 #define SPEED_DEC 1
25 27
 
@@ -40,6 +42,6 @@
40 42
 
41 43
 #define SHOT_SPEED 23
42 44
 
43
-void game(void);
45
+int32_t game(void);
44 46
 
45 47
 #endif // __GAME_H__

+ 4
- 2
src/main.c View File

@@ -23,7 +23,6 @@
23 23
 #include <gbdk/platform.h>
24 24
 #include <gbdk/metasprites.h>
25 25
 #include <rand.h>
26
-#include <stdint.h>
27 26
 
28 27
 #include "maps.h"
29 28
 #include "obj.h"
@@ -73,5 +72,8 @@ void main(void) {
73 72
     seed |= ((uint16_t)DIV_REG) << 8;
74 73
     initarand(seed);
75 74
 
76
-    game();
75
+    while (1) {
76
+        int32_t score = game();
77
+        // TODO
78
+    }
77 79
 }

+ 28
- 4
src/obj.c View File

@@ -122,8 +122,11 @@ enum OBJ_STATE obj_add(enum SPRITES sprite, int16_t off_x, int16_t off_y, int16_
122 122
     return OBJ_ADDED;
123 123
 }
124 124
 
125
-uint8_t obj_act(int16_t *spd_off_x, int16_t *spd_off_y) {
126
-    uint8_t damage = 0;
125
+#define PICKUP_SMALL_RANGE (10 << POS_SCALE_OBJS)
126
+#define PICKUP_LARGE_RANGE (16 << POS_SCALE_OBJS)
127
+
128
+int16_t obj_act(int16_t *spd_off_x, int16_t *spd_off_y, int32_t *score) {
129
+    int16_t damage = 0;
127 130
 
128 131
     for (uint8_t i = 0; i < MAX_OBJ; i++) {
129 132
         if (!objs[i].active) {
@@ -131,7 +134,7 @@ uint8_t obj_act(int16_t *spd_off_x, int16_t *spd_off_y) {
131 134
         }
132 135
 
133 136
         switch (objs[i].sprite) {
134
-            case SPR_DARK: {
137
+            case SPR_DARK:
135 138
                 if ((abs(objs[i].off_x) <= GRAVITY_RANGE) && (abs(objs[i].off_y) <= GRAVITY_RANGE)) {
136 139
                     if (objs[i].off_x > 0) {
137 140
                         *spd_off_x += (GRAVITY_RANGE - objs[i].off_x) >> GRAVITY_SHIFT;
@@ -148,7 +151,28 @@ uint8_t obj_act(int16_t *spd_off_x, int16_t *spd_off_y) {
148 151
                 if ((abs(objs[i].off_x) <= DAMAGE_RANGE) && (abs(objs[i].off_y) <= DAMAGE_RANGE)) {
149 152
                     damage += DAMAGE_INC;
150 153
                 }
151
-            } break;
154
+                break;
155
+
156
+            case SPR_LIGHT:
157
+                // TODO
158
+                if ((abs(objs[i].off_x) <= PICKUP_LARGE_RANGE) && (abs(objs[i].off_y) <= PICKUP_LARGE_RANGE)) {
159
+                    damage -= 1;
160
+                }
161
+                break;
162
+
163
+            case SPR_SHOT_DARK:
164
+                if ((abs(objs[i].off_x) <= PICKUP_SMALL_RANGE) && (abs(objs[i].off_y) <= PICKUP_SMALL_RANGE)) {
165
+                    (*score)--;
166
+                    objs[i].active = 0;
167
+                }
168
+                break;
169
+
170
+            case SPR_SHOT_LIGHT:
171
+                if ((abs(objs[i].off_x) <= PICKUP_SMALL_RANGE) && (abs(objs[i].off_y) <= PICKUP_SMALL_RANGE)) {
172
+                    (*score)++;
173
+                    objs[i].active = 0;
174
+                }
175
+                break;
152 176
 
153 177
             default:
154 178
                 break;

+ 1
- 1
src/obj.h View File

@@ -31,7 +31,7 @@ enum OBJ_STATE {
31 31
 
32 32
 void obj_init(void);
33 33
 enum OBJ_STATE obj_add(enum SPRITES sprite, int16_t off_x, int16_t off_y, int16_t spd_x, int16_t spd_y);
34
-uint8_t obj_act(int16_t *spd_off_x, int16_t *spd_off_y);
34
+int16_t obj_act(int16_t *spd_off_x, int16_t *spd_off_y, int32_t *score);
35 35
 void obj_draw(int16_t spd_x, int16_t spd_y, uint8_t *hiwater);
36 36
 
37 37
 #endif // __OBJ_H__

+ 150
- 21
src/sprites.c View File

@@ -32,7 +32,14 @@
32 32
 #include "light.h"
33 33
 #include "dark.h"
34 34
 #include "shoot.h"
35
-#include "health.h"
35
+#include "bar_1.h"
36
+#include "bar_2.h"
37
+#include "bar_3.h"
38
+#include "bar_4.h"
39
+#include "bar_5.h"
40
+#include "bar_6.h"
41
+#include "bar_7.h"
42
+#include "bar_8.h"
36 43
 
37 44
 // Metasprite tiles are loaded into VRAM starting at tile number 0
38 45
 #define TILE_NUM_START 0
@@ -53,84 +60,206 @@ const palette_color_t power_palettes[4] = {
53 60
 };
54 61
 
55 62
 static struct sprites metasprites[SPRITE_COUNT] = {
56
-    {
63
+    { // SPR_SHIP_0
57 64
         .ms = rockshp_0_metasprites,
58 65
         .ti = rockshp_0_tiles,
59 66
         .pa = rockshp_0_palettes,
60 67
         .pa_i = OAMF_CGB_PAL0,
61 68
         .cnt = rockshp_0_TILE_COUNT,
62 69
         .off = TILE_NUM_START
63
-    }, {
70
+    },
71
+    { // SPR_SHIP_90
64 72
         .ms = rockshp_90_metasprites,
65 73
         .ti = rockshp_90_tiles,
66 74
         .pa = NULL,
67 75
         .pa_i = OAMF_CGB_PAL0,
68 76
         .cnt = rockshp_90_TILE_COUNT,
69 77
         .off = TILE_NUM_START
70
-    }, {
78
+    },
79
+    { // SPR_THRUST_0
71 80
         .ms = thrust_0_metasprites,
72 81
         .ti = thrust_0_tiles,
73 82
         .pa = thrust_0_palettes,
74 83
         .pa_i = OAMF_CGB_PAL1,
75 84
         .cnt = thrust_0_TILE_COUNT,
76 85
         .off = TILE_NUM_START
77
-    }, {
86
+    },
87
+    { // SPR_THRUST_90
78 88
         .ms = thrust_90_metasprites,
79 89
         .ti = thrust_90_tiles,
80 90
         .pa = NULL,
81 91
         .pa_i = OAMF_CGB_PAL1,
82 92
         .cnt = thrust_90_TILE_COUNT,
83 93
         .off = TILE_NUM_START
84
-    }, {
94
+    },
95
+    { // SPR_LIGHT
85 96
         .ms = light_metasprites,
86 97
         .ti = light_tiles,
87 98
         .pa = light_palettes,
88 99
         .pa_i = OAMF_CGB_PAL2,
89 100
         .cnt = light_TILE_COUNT,
90 101
         .off = TILE_NUM_START
91
-    }, {
102
+    },
103
+    { // SPR_DARK
92 104
         .ms = dark_metasprites,
93 105
         .ti = dark_tiles,
94 106
         .pa = dark_palettes,
95 107
         .pa_i = OAMF_CGB_PAL3,
96 108
         .cnt = dark_TILE_COUNT,
97 109
         .off = TILE_NUM_START
98
-    }, {
110
+    },
111
+    { // SPR_SHOT
99 112
         .ms = shoot_metasprites,
100 113
         .ti = shoot_tiles,
101 114
         .pa = shoot_palettes,
102 115
         .pa_i = OAMF_CGB_PAL4,
103 116
         .cnt = shoot_TILE_COUNT,
104 117
         .off = TILE_NUM_START
105
-    }, {
118
+    },
119
+    { // SPR_SHOT_LIGHT
106 120
         .ms = shoot_metasprites,
107 121
         .ti = shoot_tiles,
108 122
         .pa = NULL,
109 123
         .pa_i = OAMF_CGB_PAL2,
110 124
         .cnt = shoot_TILE_COUNT,
111 125
         .off = SPR_SHOT
112
-    }, {
126
+    },
127
+    { // SPR_SHOT_DARK
113 128
         .ms = shoot_metasprites,
114 129
         .ti = shoot_tiles,
115 130
         .pa = NULL,
116 131
         .pa_i = OAMF_CGB_PAL3,
117 132
         .cnt = shoot_TILE_COUNT,
118 133
         .off = SPR_SHOT
119
-    }, {
120
-        .ms = health_metasprites,
121
-        .ti = health_tiles,
122
-        .pa = health_palettes,
134
+    },
135
+    { // SPR_HEALTH_1
136
+        .ms = bar_1_metasprites,
137
+        .ti = bar_1_tiles,
138
+        .pa = bar_1_palettes,
123 139
         .pa_i = OAMF_CGB_PAL5,
124
-        .cnt = health_TILE_COUNT,
140
+        .cnt = bar_1_TILE_COUNT,
125 141
         .off = TILE_NUM_START
126
-    }, {
127
-        .ms = health_metasprites,
128
-        .ti = health_tiles,
142
+    },
143
+    { // SPR_HEALTH_2
144
+        .ms = bar_2_metasprites,
145
+        .ti = bar_2_tiles,
146
+        .pa = NULL,
147
+        .pa_i = OAMF_CGB_PAL5,
148
+        .cnt = bar_2_TILE_COUNT,
149
+        .off = TILE_NUM_START
150
+    },
151
+    { // SPR_HEALTH_3
152
+        .ms = bar_3_metasprites,
153
+        .ti = bar_3_tiles,
154
+        .pa = NULL,
155
+        .pa_i = OAMF_CGB_PAL5,
156
+        .cnt = bar_3_TILE_COUNT,
157
+        .off = TILE_NUM_START
158
+    },
159
+    { // SPR_HEALTH_4
160
+        .ms = bar_4_metasprites,
161
+        .ti = bar_4_tiles,
162
+        .pa = NULL,
163
+        .pa_i = OAMF_CGB_PAL5,
164
+        .cnt = bar_4_TILE_COUNT,
165
+        .off = TILE_NUM_START
166
+    },
167
+    { // SPR_HEALTH_5
168
+        .ms = bar_5_metasprites,
169
+        .ti = bar_5_tiles,
170
+        .pa = NULL,
171
+        .pa_i = OAMF_CGB_PAL5,
172
+        .cnt = bar_5_TILE_COUNT,
173
+        .off = TILE_NUM_START
174
+    },
175
+    { // SPR_HEALTH_6
176
+        .ms = bar_6_metasprites,
177
+        .ti = bar_6_tiles,
178
+        .pa = NULL,
179
+        .pa_i = OAMF_CGB_PAL5,
180
+        .cnt = bar_6_TILE_COUNT,
181
+        .off = TILE_NUM_START
182
+    },
183
+    { // SPR_HEALTH_7
184
+        .ms = bar_7_metasprites,
185
+        .ti = bar_7_tiles,
186
+        .pa = NULL,
187
+        .pa_i = OAMF_CGB_PAL5,
188
+        .cnt = bar_7_TILE_COUNT,
189
+        .off = TILE_NUM_START
190
+    },
191
+    { // SPR_HEALTH_8
192
+        .ms = bar_8_metasprites,
193
+        .ti = bar_8_tiles,
194
+        .pa = NULL,
195
+        .pa_i = OAMF_CGB_PAL5,
196
+        .cnt = bar_8_TILE_COUNT,
197
+        .off = TILE_NUM_START
198
+    },
199
+    { // SPR_POWER_1
200
+        .ms = bar_1_metasprites,
201
+        .ti = bar_1_tiles,
129 202
         .pa = power_palettes,
130 203
         .pa_i = OAMF_CGB_PAL6,
131
-        .cnt = health_TILE_COUNT,
132
-        .off = SPR_HEALTH
133
-    }
204
+        .cnt = bar_1_TILE_COUNT,
205
+        .off = SPR_HEALTH_1
206
+    },
207
+    { // SPR_POWER_2
208
+        .ms = bar_2_metasprites,
209
+        .ti = bar_2_tiles,
210
+        .pa = NULL,
211
+        .pa_i = OAMF_CGB_PAL6,
212
+        .cnt = bar_2_TILE_COUNT,
213
+        .off = SPR_HEALTH_2
214
+    },
215
+    { // SPR_POWER_3
216
+        .ms = bar_3_metasprites,
217
+        .ti = bar_3_tiles,
218
+        .pa = NULL,
219
+        .pa_i = OAMF_CGB_PAL6,
220
+        .cnt = bar_3_TILE_COUNT,
221
+        .off = SPR_HEALTH_3
222
+    },
223
+    { // SPR_POWER_4
224
+        .ms = bar_4_metasprites,
225
+        .ti = bar_4_tiles,
226
+        .pa = NULL,
227
+        .pa_i = OAMF_CGB_PAL6,
228
+        .cnt = bar_4_TILE_COUNT,
229
+        .off = SPR_HEALTH_4
230
+    },
231
+    { // SPR_POWER_5
232
+        .ms = bar_5_metasprites,
233
+        .ti = bar_5_tiles,
234
+        .pa = NULL,
235
+        .pa_i = OAMF_CGB_PAL6,
236
+        .cnt = bar_5_TILE_COUNT,
237
+        .off = SPR_HEALTH_5
238
+    },
239
+    { // SPR_POWER_6
240
+        .ms = bar_6_metasprites,
241
+        .ti = bar_6_tiles,
242
+        .pa = NULL,
243
+        .pa_i = OAMF_CGB_PAL6,
244
+        .cnt = bar_6_TILE_COUNT,
245
+        .off = SPR_HEALTH_6
246
+    },
247
+    { // SPR_POWER_7
248
+        .ms = bar_7_metasprites,
249
+        .ti = bar_7_tiles,
250
+        .pa = NULL,
251
+        .pa_i = OAMF_CGB_PAL6,
252
+        .cnt = bar_7_TILE_COUNT,
253
+        .off = SPR_HEALTH_7
254
+    },
255
+    { // SPR_POWER_8
256
+        .ms = bar_8_metasprites,
257
+        .ti = bar_8_tiles,
258
+        .pa = NULL,
259
+        .pa_i = OAMF_CGB_PAL6,
260
+        .cnt = bar_8_TILE_COUNT,
261
+        .off = SPR_HEALTH_8
262
+    },
134 263
 };
135 264
 
136 265
 void spr_init(void) {

+ 16
- 2
src/sprites.h View File

@@ -35,8 +35,22 @@ enum SPRITES {
35 35
     SPR_SHOT,
36 36
     SPR_SHOT_LIGHT,
37 37
     SPR_SHOT_DARK,
38
-    SPR_HEALTH,
39
-    SPR_POWER,
38
+    SPR_HEALTH_1,
39
+    SPR_HEALTH_2,
40
+    SPR_HEALTH_3,
41
+    SPR_HEALTH_4,
42
+    SPR_HEALTH_5,
43
+    SPR_HEALTH_6,
44
+    SPR_HEALTH_7,
45
+    SPR_HEALTH_8,
46
+    SPR_POWER_1,
47
+    SPR_POWER_2,
48
+    SPR_POWER_3,
49
+    SPR_POWER_4,
50
+    SPR_POWER_5,
51
+    SPR_POWER_6,
52
+    SPR_POWER_7,
53
+    SPR_POWER_8,
40 54
 
41 55
     SPRITE_COUNT
42 56
 };

Loading…
Cancel
Save