Browse Source

add large debug marker. properly keep coordinates in range.

Thomas B 1 month ago
parent
commit
563f97ed06
8 changed files with 36 additions and 15 deletions
  1. 4
    9
      Makefile
  2. BIN
      data/debug_marker_spr32.png
  3. 1
    0
      src/game.c
  4. 2
    1
      src/game.h
  5. 1
    1
      src/main.c
  6. 15
    4
      src/obj.c
  7. 12
    0
      src/sprite_data.c
  8. 1
    0
      src/sprites.h

+ 4
- 9
Makefile View File

@@ -101,21 +101,16 @@ flash: $(BIN)
101 101
 
102 102
 $(BUILD_DIR)/$(DATA_DIR)/%.c $(BUILD_DIR)/$(DATA_DIR)/%.h: $(DATA_DIR)/%.png
103 103
 	@mkdir -p $(@D)
104
+	$(eval SPRFLAG = $(shell echo "$<" | sed -n 's/.*_spr\([0-9]\+\).*/\-sw \1 \-sh \1/p'))
104 105
 	$(if $(findstring _map,$<),                                                             \
105 106
 		@echo "Converting map $<" &&                                                    \
106 107
 		$(PNGA) $< -o $@ -spr8x8 -map -use_map_attributes -noflip                       \
107 108
 	,$(if $(findstring _fnt,$<),                                                            \
108 109
 		@echo "Converting font $<" &&                                                   \
109 110
 		$(PNGA) $< -o $@ -spr8x8 -sw 16 -sh 16 -map -noflip                             \
110
-	,$(if $(findstring _spr8,$<),                                                           \
111
+	,$(if $(findstring _spr,$<),                                                            \
111 112
 		@echo "Converting 8x8 sprite $<" &&                                             \
112
-		$(PNGA) $< -o $@ -spr8x8 -sw 8 -sh 8 -noflip                                    \
113
-	,$(if $(findstring _spr16,$<),                                                          \
114
-		@echo "Converting 16x16 sprite $<" &&                                           \
115
-		$(PNGA) $< -o $@ -spr8x8 -sw 16 -sh 16 -noflip                                  \
116
-	,$(if $(findstring _spr24,$<),                                                          \
117
-		@echo "Converting 24x24 sprite $<" &&                                           \
118
-		$(PNGA) $< -o $@ -spr8x8 -sw 24 -sh 24 -noflip                                  \
113
+		$(PNGA) $< -o $@ -spr8x8 $(SPRFLAG) -noflip                                     \
119 114
 	,$(if $(findstring pause,$<),                                                           \
120 115
 		@echo "Converting 40x16 sprite $<" &&                                           \
121 116
 		$(PNGA) $< -o $@ -spr8x8 -sw 40 -sh 16 -noflip                                  \
@@ -125,7 +120,7 @@ $(BUILD_DIR)/$(DATA_DIR)/%.c $(BUILD_DIR)/$(DATA_DIR)/%.h: $(DATA_DIR)/%.png
125 120
 	,                                                                                       \
126 121
 		@echo "Converting tile $<" &&                                                   \
127 122
 		$(PNGA) $< -o $@ -spr8x8                                                        \
128
-	)))))))
123
+	)))))
129 124
 
130 125
 $(BUILD_DIR)/%.o: %.c $(SPRITES)
131 126
 	@mkdir -p $(@D)

BIN
data/debug_marker_spr32.png View File


+ 1
- 0
src/game.c View File

@@ -321,6 +321,7 @@ int32_t game(void) NONBANKED {
321 321
 
322 322
         if (debug_flags & DBG_MARKER) {
323 323
             spr_draw(SPR_DEBUG, FLIP_NONE, 0, 0, 0, &hiwater);
324
+            spr_draw(SPR_DEBUG_LARGE, FLIP_NONE, 0, 0, 0, &hiwater);
324 325
         }
325 326
 
326 327
         if (redraw) {

+ 2
- 1
src/game.h View File

@@ -30,7 +30,8 @@
30 30
 #define SPEED_MAX_IDLE 16
31 31
 
32 32
 #define POS_SCALE_OBJS 5
33
-#define POS_MASK_OBJS 0x1FFF
33
+#define POS_OBJS_MAX (INT16_MAX >> (8 - POS_SCALE_OBJS))
34
+#define POS_OBJS_MIN (-(INT16_MAX >> (8 - POS_SCALE_OBJS)) - 1)
34 35
 
35 36
 #define POS_SCALE_BG 6
36 37
 #define POS_MASK_BG 0x3FFF

+ 1
- 1
src/main.c View File

@@ -37,7 +37,7 @@
37 37
 #include "main.h"
38 38
 
39 39
 #ifdef DEBUG
40
-enum debug_flag debug_flags = DBG_MENU;
40
+enum debug_flag debug_flags = DBG_MENU | DBG_MARKER;
41 41
 #else
42 42
 enum debug_flag debug_flags = 0;
43 43
 #endif

+ 15
- 4
src/obj.c View File

@@ -59,10 +59,10 @@
59 59
 #define GRAVITY_RANGE (24 << POS_SCALE_OBJS)
60 60
 #define GRAVITY_SHIFT (POS_SCALE_OBJS + 4)
61 61
 
62
-#define DAMAGE_RANGE (16 << POS_SCALE_OBJS)
62
+#define DAMAGE_RANGE (14 << POS_SCALE_OBJS)
63 63
 #define DAMAGE_INC 5
64 64
 
65
-#define HEALTH_RANGE (18 << POS_SCALE_OBJS)
65
+#define HEALTH_RANGE (12 << POS_SCALE_OBJS)
66 66
 #define HEALTH_INC HEALTH_MAX
67 67
 
68 68
 #define PICKUP_SMALL_RANGE (12 << POS_SCALE_OBJS)
@@ -126,8 +126,19 @@ int16_t obj_do(int16_t *spd_off_x, int16_t *spd_off_y, int32_t *score, uint8_t *
126 126
         }
127 127
 
128 128
         // move objects by their speed and compensate for movement of the background / ship
129
-        objs[i].off_x = (objs[i].off_x + objs[i].spd_x - spd_x) & POS_MASK_OBJS;
130
-        objs[i].off_y = (objs[i].off_y + objs[i].spd_y - spd_y) & POS_MASK_OBJS;
129
+        objs[i].off_x = objs[i].off_x + objs[i].spd_x - spd_x;
130
+        objs[i].off_y = objs[i].off_y + objs[i].spd_y - spd_y;
131
+
132
+        if (objs[i].off_x > POS_OBJS_MAX) {
133
+            objs[i].off_x -= POS_OBJS_MAX - POS_OBJS_MIN + 1;
134
+        } else if (objs[i].off_x < POS_OBJS_MIN) {
135
+            objs[i].off_x += POS_OBJS_MAX - POS_OBJS_MIN + 1;
136
+        }
137
+        if (objs[i].off_y > POS_OBJS_MAX) {
138
+            objs[i].off_y -= POS_OBJS_MAX - POS_OBJS_MIN + 1;
139
+        } else if (objs[i].off_y < POS_OBJS_MIN) {
140
+            objs[i].off_y += POS_OBJS_MAX - POS_OBJS_MIN + 1;
141
+        }
131 142
 
132 143
         // only update travel time if we're actually moving
133 144
         if ((objs[i].spd_x != 0) || (objs[i].spd_y != 0)) {

+ 12
- 0
src/sprite_data.c View File

@@ -30,6 +30,7 @@
30 30
 #include "expl_spr16.h"
31 31
 #include "pause.h"
32 32
 #include "debug_marker.h"
33
+#include "debug_marker_spr32.h"
33 34
 
34 35
 BANKREF(power_palettes)
35 36
 
@@ -174,4 +175,15 @@ struct sprites metasprites[SPRITE_COUNT] = {
174 175
         .off = TILE_NUM_START,
175 176
         .bank = BANK(debug_marker),
176 177
     },
178
+    { // SPR_DEBUG_LARGE
179
+        .ms = debug_marker_spr32_metasprites,
180
+        .ms_n = ARR_LEN(debug_marker_spr32_metasprites),
181
+        .ti = debug_marker_spr32_tiles,
182
+        .pa = debug_marker_spr32_palettes,
183
+        .pa_n = debug_marker_spr32_PALETTE_COUNT,
184
+        .pa_i = OAMF_CGB_PAL7 | PALETTE_DYNAMIC_LOAD_IP,
185
+        .cnt = debug_marker_spr32_TILE_COUNT,
186
+        .off = TILE_NUM_START,
187
+        .bank = BANK(debug_marker_spr32),
188
+    },
177 189
 };

+ 1
- 0
src/sprites.h View File

@@ -37,6 +37,7 @@ enum SPRITES {
37 37
     SPR_EXPL,
38 38
     SPR_PAUSE,
39 39
     SPR_DEBUG,
40
+    SPR_DEBUG_LARGE,
40 41
 
41 42
     SPRITE_COUNT
42 43
 };

Loading…
Cancel
Save