Browse Source

metasprite test

Thomas B 2 months ago
parent
commit
92635f1d0d
11 changed files with 259 additions and 638 deletions
  1. 4
    0
      .gitignore
  2. 40
    5
      Makefile
  3. 3
    1
      README.md
  4. BIN
      data/bg_map.png
  5. BIN
      data/dark.png
  6. BIN
      data/light.png
  7. BIN
      data/rockshp.png
  8. BIN
      data/shoot.png
  9. BIN
      data/thrustG.png
  10. 0
    632
      src/galaxy.c
  11. 212
    0
      src/main.c

+ 4
- 0
.gitignore View File

1
 build
1
 build
2
 *.gb
2
 *.gb
3
+.cache
4
+compile_commands.json
5
+bear.cfg
6
+tmp

+ 40
- 5
Makefile View File

7
 BIN := duality.gb
7
 BIN := duality.gb
8
 SRC_DIR := src
8
 SRC_DIR := src
9
 BUILD_DIR := build
9
 BUILD_DIR := build
10
+DATA_DIR := data
10
 
11
 
11
 SRCS := $(wildcard $(SRC_DIR)/*.c)
12
 SRCS := $(wildcard $(SRC_DIR)/*.c)
12
 OBJS := $(SRCS:%.c=$(BUILD_DIR)/%.o)
13
 OBJS := $(SRCS:%.c=$(BUILD_DIR)/%.o)
13
 
14
 
15
+ASSETS := $(wildcard $(DATA_DIR)/*.png)
16
+SPRITES := $(ASSETS:%.png=$(BUILD_DIR)/%.c)
17
+OBJS += $(SPRITES:%.c=%.o)
18
+
14
 LCC := $(GBDK_HOME)/bin/lcc
19
 LCC := $(GBDK_HOME)/bin/lcc
20
+PNGA := $(GBDK_HOME)/bin/png2asset
15
 GB_EMU := gearboy
21
 GB_EMU := gearboy
16
 
22
 
17
-LCCFLAGS := -Wa-l -Wl-m -Wm"-yn Duality"
23
+LCCFLAGS := -Wa-l -Wl-m -Wm"-yn Duality" -I$(BUILD_DIR)/$(DATA_DIR)
18
 EMUFLAGS := $(BIN)
24
 EMUFLAGS := $(BIN)
19
 
25
 
20
-GBDK_DEBUG = ON
21
-ifdef GBDK_DEBUG
26
+ifndef GBDK_RELEASE
22
 	LCCFLAGS += -debug -Wa-j -Wa-y -Wa-s -Wl-j -Wl-y -Wl-u -Wm-yS
27
 	LCCFLAGS += -debug -Wa-j -Wa-y -Wa-s -Wl-j -Wl-y -Wl-u -Wm-yS
23
 	EMUFLAGS += $(BUILD_DIR)/$(BIN:.gb=.sym)
28
 	EMUFLAGS += $(BUILD_DIR)/$(BIN:.gb=.sym)
29
+	BUILD_TYPE = Debug
30
+else
31
+	BUILD_TYPE = Release
24
 endif
32
 endif
25
 
33
 
26
-.PHONY: all run $(BIN) clean
34
+$(info BUILD_TYPE is $(BUILD_TYPE))
35
+
36
+.PHONY: all run $(BIN) clean compile_commands.json
27
 
37
 
28
 all: $(BIN)
38
 all: $(BIN)
29
 
39
 
40
+compile_commands.json:
41
+	@echo "Cleaning old build"
42
+	@make clean
43
+	@echo "Preparing bear.cfg"
44
+	@echo '{"compilation":{"compilers_to_recognize":[{"executable":"$(GBDK_HOME)/bin/sdcc","flags_to_add":[""],"flags_to_remove":[""]}]}}' > bear.cfg
45
+	@echo "Running full build within bear"
46
+	@bear --config bear.cfg -- make -j4
47
+	@rm -rf bear.cfg
48
+
30
 run: $(BIN)
49
 run: $(BIN)
31
 	@echo Emulating $<
50
 	@echo Emulating $<
32
 	@$(GB_EMU) $(EMUFLAGS)
51
 	@$(GB_EMU) $(EMUFLAGS)
33
 
52
 
53
+.PRECIOUS: $(BUILD_DIR)/$(DATA_DIR)/%.c $(BUILD_DIR)/$(DATA_DIR)/%.h
54
+$(BUILD_DIR)/$(DATA_DIR)/%.c $(BUILD_DIR)/$(DATA_DIR)/%.h: $(DATA_DIR)/%.png
55
+	@mkdir -p $(@D)
56
+	$(if $(findstring _map,$<),           \
57
+		@echo "Converting map $<" &&  \
58
+		$(PNGA) $< -o $@ -spr8x8 -map \
59
+	,                                     \
60
+		@echo "Converting tile $<" && \
61
+		$(PNGA) $< -o $@ -spr8x8      \
62
+	)
63
+
34
 $(BUILD_DIR)/%.o: %.c
64
 $(BUILD_DIR)/%.o: %.c
35
 	@mkdir -p $(@D)
65
 	@mkdir -p $(@D)
36
 	@echo Compiling $<
66
 	@echo Compiling $<
37
 	@$(LCC) $(LCCFLAGS) -c -o $@ $<
67
 	@$(LCC) $(LCCFLAGS) -c -o $@ $<
38
 
68
 
69
+$(BUILD_DIR)/%.o: $(BUILD_DIR)/%.c
70
+	@mkdir -p $(@D)
71
+	@echo Compiling $<
72
+	@$(LCC) $(LCCFLAGS) -c -o $@ $<
73
+
39
 $(BUILD_DIR)/%.o: %.s
74
 $(BUILD_DIR)/%.o: %.s
40
 	@mkdir -p $(@D)
75
 	@mkdir -p $(@D)
41
 	@echo Assembling $<
76
 	@echo Assembling $<
43
 
78
 
44
 $(BUILD_DIR)/$(BIN): $(OBJS)
79
 $(BUILD_DIR)/$(BIN): $(OBJS)
45
 	@echo Linking $@
80
 	@echo Linking $@
46
-	@$(LCC) $(LCCFLAGS) -o $@ $<
81
+	@$(LCC) $(LCCFLAGS) -o $@ $(OBJS)
47
 
82
 
48
 $(BIN): $(BUILD_DIR)/$(BIN)
83
 $(BIN): $(BUILD_DIR)/$(BIN)
49
 	@cp $< $@
84
 	@cp $< $@

+ 3
- 1
README.md View File

6
 ## Getting Started
6
 ## Getting Started
7
 
7
 
8
 You need the [GBDK-2020](https://gbdk.org/docs/api/docs_getting_started.html) to build the ROM and [Gearboy](https://github.com/drhelius/Gearboy) to emulate it comfortably.
8
 You need the [GBDK-2020](https://gbdk.org/docs/api/docs_getting_started.html) to build the ROM and [Gearboy](https://github.com/drhelius/Gearboy) to emulate it comfortably.
9
-Then just build and run it.
9
+Then just build a debug version and run it in the emulator, with debug symbols already loaded.
10
 
10
 
11
     make run
11
     make run
12
 
12
 
13
+For the release build, simply add `GBDK_RELEASE=1` to your make invocation after running `make clean`.
14
+
13
 ## License
15
 ## License
14
 
16
 
15
 To-Do
17
 To-Do

BIN
data/bg_map.png View File


BIN
data/dark.png View File


BIN
data/light.png View File


BIN
data/rockshp.png View File


BIN
data/shoot.png View File


BIN
data/thrustG.png View File


+ 0
- 632
src/galaxy.c View File

1
-/*
2
- * C version of the 'space' assembly demo.
3
- *
4
- * Little demo illustrating how to use the graphical possibilities
5
- *  of the GB (background, window and animated sprite)
6
- * I have used fixed-point values for both the position and
7
- *  speed of objects to get smooth movements
8
- * 
9
- * OBJ data             : 0x8000 -> 0x8FFF (unsigned)
10
- * Window data          : 0x8800 -> 0x97FF (unsigned)
11
- * Background data      : 0x8800 -> 0x97FF (signed)
12
- * 
13
- * Tiled 0xFC -> 0xFF are standard tiles (all black -> all white)
14
- * 
15
- * Keys:
16
- * Arrow keys           : Change the speed (and direction) of the sprite
17
- * Arrow keys + A       : Change the speed (and direction) of the window
18
- * Arrow keys + B       : Change the speed (and direction) of the background
19
- * START                : Open/close the door
20
- * SELECT               : Basic fading effect
21
- * 
22
- * Note that the window is kept in the lower right part of the screen
23
- * since it can't be made transparent
24
- */
25
-
26
-#include <gb/gb.h>
27
-#include <stdint.h>
28
-
29
-const unsigned char std_data[] = {
30
-
31
-  /* Basic tiles (0xFC to 0xFF) */
32
-  0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
33
-  0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,
34
-  0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,
35
-  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
36
-};
37
-
38
-const unsigned char earth_data[] = {
39
-
40
-  /* Tile 0x00 */
41
-  0x07,0x07,0x18,0x1F,0x32,0x2D,0x71,0x4E,0x70,0x4F,0xF8,0x87,0xF8,0x87,0xF8,0x87,
42
-  0xFC,0x83,0xFE,0x81,0x7F,0x40,0x7F,0x40,0x3F,0x20,0x1F,0x18,0x07,0x07,0x00,0x00,
43
-  0xC0,0xC0,0xF0,0x30,0x78,0x88,0x3C,0xC4,0x5C,0xA4,0x9E,0x62,0x3E,0xC2,0x3E,0xC2,
44
-  0x5E,0xA2,0x7E,0x82,0x0C,0xF4,0x0C,0xF4,0x98,0x68,0xB0,0x70,0xC0,0xC0,0x00,0x00,
45
-  0x07,0x07,0x1F,0x18,0x2F,0x30,0x4F,0x70,0x6F,0x50,0x9F,0xE0,0x9F,0xE0,0xBF,0xC0,
46
-  0xFF,0x80,0xB7,0xC8,0x63,0x5C,0x43,0x7C,0x3F,0x20,0x1F,0x18,0x07,0x07,0x00,0x00,
47
-  0xC0,0xC0,0xB0,0x70,0x18,0xE8,0x0C,0xF4,0x0C,0xF4,0x82,0x7E,0x82,0x7E,0x86,0x7A,
48
-  0xC6,0x3A,0xE6,0x1A,0xF4,0x0C,0xFC,0x04,0xF8,0x08,0xF0,0x30,0xC0,0xC0,0x00,0x00,
49
-
50
-  /* Tile 0x08 */
51
-  0x07,0x07,0x1E,0x19,0x20,0x3F,0x40,0x7F,0x42,0x7D,0x81,0xFE,0x81,0xFE,0x83,0xFC,
52
-  0xD7,0xA8,0xBB,0xC4,0x6E,0x51,0x7C,0x43,0x3F,0x20,0x1F,0x18,0x07,0x07,0x00,0x00,
53
-  0xC0,0xC0,0x70,0xB0,0xE8,0x18,0xF4,0x0C,0xF4,0x0C,0xFE,0x02,0xFE,0x02,0xFE,0x02,
54
-  0xFE,0x02,0x7E,0x82,0x3C,0xC4,0x3C,0xC4,0xF8,0x08,0xF0,0x30,0xC0,0xC0,0x00,0x00,
55
-  0x07,0x07,0x1B,0x1C,0x20,0x3F,0x40,0x7F,0x40,0x7F,0xE0,0x9F,0x90,0xEF,0x89,0xF6,
56
-  0x8D,0xF2,0x9F,0xE0,0x5E,0x61,0x6F,0x50,0x3F,0x20,0x1F,0x18,0x07,0x07,0x00,0x00,
57
-  0xC0,0xC0,0xB0,0x70,0x28,0xD8,0x04,0xFC,0x2C,0xD4,0x1E,0xE2,0x1E,0xE2,0x3E,0xC2,
58
-  0x7E,0x82,0xB6,0x4A,0xE4,0x1C,0xC4,0x3C,0xF8,0x08,0xF0,0x30,0xC0,0xC0,0x00,0x00,
59
-
60
-  /* Tile 0x10 */
61
-  0x07,0x07,0x18,0x1F,0x20,0x3F,0x40,0x7F,0x40,0x7F,0xEE,0x91,0xF1,0x8E,0xE0,0x9F,
62
-  0xE0,0x9F,0xF1,0x8E,0x71,0x4E,0x72,0x4D,0x3F,0x20,0x1F,0x18,0x07,0x07,0x00,0x00,
63
-  0xC0,0xC0,0xF0,0x30,0x08,0xF8,0x04,0xFC,0x04,0xFC,0x02,0xFE,0x02,0xFE,0x92,0x6E,
64
-  0xD6,0x2A,0xFE,0x02,0xEC,0x14,0xFC,0x04,0xF8,0x08,0xF0,0x30,0xC0,0xC0,0x00,0x00,
65
-  0x07,0x07,0x1D,0x1A,0x36,0x29,0x5C,0x63,0x6C,0x53,0xCE,0xB1,0x9F,0xE0,0x9E,0xE1,
66
-  0xAE,0xD1,0xBF,0xC0,0x47,0x78,0x47,0x78,0x2F,0x30,0x1F,0x18,0x07,0x07,0x00,0x00,
67
-  0xC0,0xC0,0x70,0xB0,0x08,0xF8,0x04,0xFC,0x04,0xFC,0xE2,0x1E,0x32,0xCE,0x0E,0xF2,
68
-  0x0E,0xF2,0x1E,0xE2,0x1C,0xE4,0x2C,0xD4,0xF8,0x08,0xF0,0x30,0xC0,0xC0,0x00,0x00,
69
-
70
-  /* Tile 0x18 */
71
-  0x07,0x07,0x1E,0x19,0x33,0x2C,0x49,0x76,0x42,0x7D,0xC4,0xBB,0xC1,0xBE,0xC1,0xBE,
72
-  0xE2,0x9D,0xF3,0x8C,0x78,0x47,0x78,0x47,0x3C,0x23,0x1C,0x1B,0x07,0x07,0x00,0x00,
73
-  0xC0,0xC0,0x70,0xB0,0x68,0x98,0xC4,0x3C,0xC4,0x3C,0xEE,0x12,0xF2,0x0E,0xE2,0x1E,
74
-  0xE2,0x1E,0xF2,0x0E,0x7C,0x84,0x7C,0x84,0xF8,0x08,0xF0,0x30,0xC0,0xC0,0x00,0x00
75
-};
76
-
77
-const unsigned char frame_data[] = {
78
-
79
-  /* Tile 0x00 */
80
-  0xFF,0x00,0x80,0x7F,0x80,0x7F,0x80,0x7F,0x80,0x7F,0x80,0x7F,0x80,0x7F,0x80,0x7F,
81
-  0xFF,0x00,0x01,0xFE,0x03,0xFC,0x07,0xF8,0x0F,0xF0,0x1F,0xE0,0x3F,0xC0,0x7F,0x80,
82
-  0xFF,0x00,0xFE,0x01,0xFC,0x03,0xF8,0x07,0xF0,0x0F,0xE0,0x1F,0xC0,0x3F,0x80,0x7F,
83
-  0xFF,0x00,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,
84
-  0xFF,0x00,0xFF,0x01,0xFD,0x03,0xF9,0x07,0xF1,0x0F,0xE1,0x1F,0xC1,0x3F,0x81,0x7F,
85
-  0x80,0x7F,0x81,0x7E,0x83,0x7C,0x87,0x78,0x8F,0x70,0x9F,0x60,0xBF,0x40,0xFF,0x00,
86
-  0xFF,0x70,0xFF,0x98,0xEF,0xB8,0xCF,0xF8,0xFF,0x70,0xFF,0x00,0xFF,0x00,0xFF,0x01,
87
-  0xFF,0x00,0xFE,0x01,0xFC,0x03,0xF8,0x07,0xF0,0x0F,0xE0,0x1F,0xC0,0x3F,0xFF,0xFF,
88
-
89
-  /* Tile 0x08 */
90
-  0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0xFF,0xFF,
91
-  0x00,0xFF,0x01,0xFE,0x03,0xFC,0x07,0xF8,0x0F,0xF0,0x1F,0xE0,0x3F,0xC0,0xFF,0xFF,
92
-  0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0xFF,
93
-  0xFF,0x0E,0xFF,0x13,0xFD,0x17,0xF9,0x1F,0xFE,0x0F,0xE0,0x1F,0xC0,0x3F,0x80,0xFF,
94
-  0x01,0xFF,0x01,0xFF,0x01,0xFF,0x01,0xFF,0x01,0xFF,0x01,0xFF,0x01,0xFF,0x01,0xFF,
95
-  0xFF,0x01,0xFF,0x01,0xFD,0x03,0xF9,0x07,0xF1,0x0F,0xE1,0x1F,0xC1,0x3F,0x81,0x7F,
96
-  0x80,0x7F,0x80,0x7F,0x80,0x7F,0x80,0x7F,0x80,0x7F,0x80,0x7F,0x80,0x7F,0x80,0x7F,
97
-  0x01,0xFF,0x01,0xFF,0x03,0xFD,0x07,0xF9,0x0F,0xF1,0x1F,0xE1,0x3F,0xC1,0x7F,0x81,
98
-
99
-  /* Tile 0x10 */
100
-  0xFF,0x01,0xFF,0x01,0xFF,0x01,0xFF,0x01,0xFF,0x01,0xFF,0x01,0xFF,0x01,0xFF,0x01,
101
-  0x01,0xFF,0x01,0xFE,0x03,0xFC,0x77,0xF8,0xFF,0x98,0xEF,0xB8,0xCF,0xF8,0x7F,0xF0,
102
-  0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x0E,0xFF,0x13,0xFD,0x17,0xF9,0x1F,0xFF,0x0E,
103
-  0x80,0x7F,0x81,0x7E,0x83,0x7C,0x87,0x78,0x8F,0x70,0x9F,0x60,0xBF,0x40,0xFF,0x7F,
104
-  0x01,0xFF,0x01,0xFF,0x01,0xFF,0x01,0xFF,0x01,0xFF,0x01,0xFF,0x01,0xFF,0xFF,0xFF,
105
-
106
-  /* Door1 */
107
-
108
-  /* Tile 0x15 */
109
-  0xFF,0x00,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0xFF,
110
-  0x00,0xFF,0x00,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0xFF,0x00,0xFF,0x00,0xFF,
111
-  0x00,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0xFF,0xFF,
112
-
113
-  /* Door2 */
114
-
115
-  /* Tile 0x18 */
116
-  0x00,0xFF,0x00,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0xFF,0x00,0xFF,0x00,0xFF,
117
-  0x00,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0xFF,0xFF,
118
-  0xFF,0x00,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0xFF,
119
-  0xFF,0x00,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
120
-
121
-  /* Door3 */
122
-
123
-  /* Tile 0x1C */
124
-  0x00,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0xFF,0xFF,
125
-  0xFF,0x00,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0xFF,
126
-  0x00,0xFF,0x00,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0xFF,0x00,0xFF,0x00,0xFF,
127
-  0x00,0xFF,0x00,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
128
-
129
-  /* Door4 */
130
-
131
-  /* Tile 0x20 */
132
-  0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
133
-};
134
-
135
-const unsigned char bkg_data[] = {
136
-
137
-  /* Tile 0x00 */
138
-  0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xEF,0xFF,0xFF,0xFF,0xFF,
139
-  0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,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0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xEF,0xFB,0xFF,0xFF,0xFF,0xFF,
184
-  0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0xFF,0xFD,0xFE,0xFE,0xFD,
185
-  0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFB,0xFF,0xFF,
186
-
187
-  /* Tile 0x28 */
188
-  0xF7,0xFF,0xFB,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
189
-  0xFF,0xFF,0xFF,0xFF,0xFF,0xBF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
190
-  0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,
191
-  0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFD,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
192
-  0xFF,0xFF,0xFF,0xFF,0x7F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
193
-};
194
-
195
-/*
196
- * Image size: 0x40 x 0x40
197
- * Number of tiles (total - unique): 0x40 - 0x2D
198
- */
199
-
200
-const unsigned char bkg_tiles[] = {
201
-  0x00,0x01,0x02,0x03,0xFC,0xFC,0x04,0xFC,
202
-  0xFC,0x05,0x06,0xFC,0x07,0x08,0x09,0x0A,
203
-  0xFC,0xFC,0xFC,0x02,0x0B,0x0C,0x0D,0xFC,
204
-  0x0E,0x0F,0x10,0xFC,0x11,0x12,0x13,0x14,
205
-  0x15,0x16,0x17,0xFC,0x18,0x19,0x1A,0xFC,
206
-  0x1B,0x1C,0x1D,0xFC,0xFC,0x1E,0x1F,0x20,
207
-  0x21,0x22,0xFC,0x23,0x24,0x25,0xFC,0x26,
208
-  0x27,0x13,0x28,0x29,0x2A,0x2B,0x2C,0x11
209
-};
210
-
211
-/*
212
- * Image size: 0x10 x 0x70
213
- * Number of tiles (total - unique): 0x1C - 0x1C
214
- */
215
-
216
-const unsigned char earth_tiles[] = {
217
-  0x00,0x02,
218
-  0x04,0x06,
219
-  0x08,0x0A,
220
-  0x0C,0x0E,
221
-  0x10,0x12,
222
-  0x14,0x16,
223
-  0x18,0x1A
224
-};
225
-
226
-/*
227
- * Image size: 0x80 x 0x50
228
- * Number of tiles (total - unique): 0xA0 - 0x15
229
- */
230
-
231
-const unsigned char frame_tiles[] = {
232
-  0x80,0x81,0xFD,0x82,0x83,0x81,0xFD,0x82,0x83,0x81,0xFD,0x82,0x83,0x81,0xFD,0x84,
233
-  0x85,0x86,0x87,0x88,0x89,0x8A,0x87,0x88,0x89,0x8A,0x87,0x88,0x89,0x8A,0x8B,0x8C,
234
-  0xFD,0x8D,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x8E,0x8F,
235
-  0x82,0x8C,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x85,0x90,
236
-  0x8E,0x8F,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFD,0x8D,
237
-  0x85,0x90,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x82,0x8C,
238
-  0xFD,0x8D,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x8E,0x8F,
239
-  0x82,0x8C,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x85,0x90,
240
-  0x8E,0x91,0xFD,0x82,0x83,0x81,0xFD,0x82,0x83,0x81,0xFD,0x82,0x83,0x81,0x92,0x8D,
241
-  0x93,0x8A,0x87,0x88,0x89,0x8A,0x87,0x88,0x89,0x8A,0x87,0x88,0x89,0x8A,0x87,0x94
242
-};
243
-
244
-/*
245
- * Image size: 0x60 x 0x30
246
- * Number of tiles (total - unique): 0x48 - 0x03
247
- */
248
-
249
-const unsigned char door1_tiles[] = {
250
-  0x95,0x95,0x95,0x95,0x95,0x95,0x95,0x95,0x95,0x95,0x95,0x95,
251
-  0x96,0x96,0x96,0x96,0x96,0x96,0x96,0x96,0x96,0x96,0x96,0x96,
252
-  0x97,0x97,0x97,0x97,0x97,0x97,0x97,0x97,0x97,0x97,0x97,0x97,
253
-  0x95,0x95,0x95,0x95,0x95,0x95,0x95,0x95,0x95,0x95,0x95,0x95,
254
-  0x96,0x96,0x96,0x96,0x96,0x96,0x96,0x96,0x96,0x96,0x96,0x96,
255
-  0x97,0x97,0x97,0x97,0x97,0x97,0x97,0x97,0x97,0x97,0x97,0x97,
256
-
257
-  0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,
258
-  0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,
259
-  0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,
260
-  0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,
261
-  0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,
262
-  0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC
263
-};
264
-
265
-/*
266
- * Image size: 0x60 x 0x30
267
- * Number of tiles (total - unique): 0x48 - 0x04
268
- */
269
-
270
-const unsigned char door2_tiles[] = {
271
-  0x98,0x98,0x98,0x98,0x98,0x98,0x98,0x98,0x98,0x98,0x98,0x98,
272
-  0x99,0x99,0x99,0x99,0x99,0x99,0x99,0x99,0x99,0x99,0x99,0x99,
273
-  0x9A,0x9A,0x9A,0x9A,0x9A,0x9A,0x9A,0x9A,0x9A,0x9A,0x9A,0x9A,
274
-  0x98,0x98,0x98,0x98,0x98,0x98,0x98,0x98,0x98,0x98,0x98,0x98,
275
-  0x99,0x99,0x99,0x99,0x99,0x99,0x99,0x99,0x99,0x99,0x99,0x99,
276
-  0x9B,0x9B,0x9B,0x9B,0x9B,0x9B,0x9B,0x9B,0x9B,0x9B,0x9B,0x9B,
277
-
278
-  0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,
279
-  0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,
280
-  0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,
281
-  0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,
282
-  0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,
283
-};
284
-
285
-/*
286
- * Image size: 0x60 x 0x30
287
- * Number of tiles (total - unique): 0x48 - 0x04
288
- */
289
-
290
-const unsigned char door3_tiles[] = {
291
-  0x9C,0x9C,0x9C,0x9C,0x9C,0x9C,0x9C,0x9C,0x9C,0x9C,0x9C,0x9C,
292
-  0x9D,0x9D,0x9D,0x9D,0x9D,0x9D,0x9D,0x9D,0x9D,0x9D,0x9D,0x9D,
293
-  0x9E,0x9E,0x9E,0x9E,0x9E,0x9E,0x9E,0x9E,0x9E,0x9E,0x9E,0x9E,
294
-  0x9C,0x9C,0x9C,0x9C,0x9C,0x9C,0x9C,0x9C,0x9C,0x9C,0x9C,0x9C,
295
-  0x9D,0x9D,0x9D,0x9D,0x9D,0x9D,0x9D,0x9D,0x9D,0x9D,0x9D,0x9D,
296
-  0x9F,0x9F,0x9F,0x9F,0x9F,0x9F,0x9F,0x9F,0x9F,0x9F,0x9F,0x9F,
297
-
298
-  0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,
299
-  0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,
300
-  0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,
301
-  0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,
302
-  0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC
303
-};
304
-
305
-/*
306
- * Image size: 0x60 x 0x30
307
- * Number of tiles (total - unique): 0x48 - 0x01
308
- */
309
-
310
-const unsigned char door4_tiles[] = {
311
-  0x95,0x95,0x95,0x95,0x95,0x95,0x95,0x95,0x95,0x95,0x95,0x95,
312
-  0x96,0x96,0x96,0x96,0x96,0x96,0x96,0x96,0x96,0x96,0x96,0x96,
313
-  0x97,0x97,0x97,0x97,0x97,0x97,0x97,0x97,0x97,0x97,0x97,0x97,
314
-  0x95,0x95,0x95,0x95,0x95,0x95,0x95,0x95,0x95,0x95,0x95,0x95,
315
-  0x96,0x96,0x96,0x96,0x96,0x96,0x96,0x96,0x96,0x96,0x96,0x96,
316
-  0xA0,0xA0,0xA0,0xA0,0xA0,0xA0,0xA0,0xA0,0xA0,0xA0,0xA0,0xA0,
317
-
318
-  0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,
319
-  0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,
320
-  0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,
321
-  0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,
322
-  0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC,0xFC
323
-};
324
-
325
-/* Should really be const, but sdcc doesnt yet support it. */
326
-const unsigned char * const film[] = {
327
-  &door1_tiles[0x0C*0],
328
-  &door2_tiles[0x0C*0],
329
-  &door3_tiles[0x0C*0],
330
-  &door4_tiles[0x0C*0],
331
-  &door1_tiles[0x0C*1],
332
-  &door2_tiles[0x0C*1],
333
-  &door3_tiles[0x0C*1],
334
-  &door4_tiles[0x0C*1],
335
-  &door1_tiles[0x0C*2],
336
-  &door2_tiles[0x0C*2],
337
-  &door3_tiles[0x0C*2],
338
-  &door4_tiles[0x0C*2],
339
-  &door1_tiles[0x0C*3],
340
-  &door2_tiles[0x0C*3],
341
-  &door3_tiles[0x0C*3],
342
-  &door4_tiles[0x0C*3],
343
-  &door1_tiles[0x0C*4],
344
-  &door2_tiles[0x0C*4],
345
-  &door3_tiles[0x0C*4],
346
-  &door4_tiles[0x0C*4],
347
-  &door1_tiles[0x0C*5],
348
-  &door2_tiles[0x0C*5],
349
-  &door3_tiles[0x0C*5],
350
-  &door4_tiles[0x0C*5],
351
-  &door1_tiles[0x0C*6]
352
-};
353
-
354
-#define NBDFRAMES 0x18                  /* Nb frames for the door */
355
-#define NBSFRAMES 0x07                  /* Nb frames for the sprite */
356
-#define WINSZX    0x80                  /* Size of the picture in the window */
357
-#define WINSZY    0x50
358
-#define MINWINX   (MAXWNDPOSX-WINSZX+1) /* Bounds of the window origin */
359
-#define MINWINY   (MAXWNDPOSY-WINSZY+1)
360
-#define MAXWINX   MAXWNDPOSX
361
-#define MAXWINY   MAXWNDPOSY
362
-#define FADESTEP  0x10                  /* Nb steps for the fading effect */
363
-#define STARTFADE (0x06*FADESTEP)       /* Initial value for the fading effect */
364
-
365
-#define CLOSED  0x00
366
-#define OPENING 0x01
367
-#define OPENED  0x02
368
-#define CLOSING 0x03
369
-
370
-static uint8_t time = 0;  /* Global "time" value (counter) */
371
-uint8_t doorstate = 0;    /* State of the door (OPENED, CLOSED...) */
372
-uint8_t doorpos = 0;      /* Current position in the door animation */
373
-static uint8_t color = 0; /* Current color for fading effect */
374
-uint8_t sframe = 0;       /* Current frame of the sprite */
375
-fixed bposx, bposy; /* Background position (fixed point) */
376
-fixed bspx, bspy;   /* Background speed (fixed point) */
377
-fixed wposx, wposy; /* Window position (fixed point) */
378
-fixed wspx, wspy;   /* Window speed (fixed point) */
379
-fixed sposx, sposy; /* Sprite position (fixed point) */
380
-fixed sspx, sspy;   /* Sprite speed (fixed point) */
381
-
382
-void fade(void);
383
-void scroll(void);
384
-void door(void);
385
-void animate_sprite(void);
386
-void tile_sprite(void);
387
-void place_sprite(void);
388
-
389
-/* Fade the screen (off and on) */
390
-void fade(void)
391
-{
392
-  if(color == 0)
393
-    return;
394
-  switch(color)
395
-    {
396
-    case STARTFADE:
397
-    case STARTFADE-4*FADESTEP:
398
-      BGP_REG = 0xF9U;
399
-      break;
400
-    case STARTFADE-FADESTEP:
401
-    case STARTFADE-3*FADESTEP:
402
-      BGP_REG = 0xFEU;
403
-      break;
404
-    case STARTFADE-2*FADESTEP:
405
-      BGP_REG = 0xFFU;
406
-      break;
407
-    case STARTFADE-5*FADESTEP:
408
-      BGP_REG = 0xE4U;
409
-      break;
410
-    }
411
-  color--;
412
-}
413
-
414
-/* Scroll the background, the window and the sprite */
415
-void scroll(void)
416
-{
417
-  /* Update background */
418
-  bposx.w += bspx.w;
419
-  bposy.w += bspy.w;
420
-  SCX_REG = bposx.b.h;
421
-  SCY_REG = bposy.b.h;
422
-
423
-  /* Update window */
424
-  wposx.w += wspx.w ;
425
-  wposy.w += wspy.w ;
426
-  /* X position */
427
-  if(wposx.b.h >= MAXWINX) {
428
-    wposx.b.h = MAXWINX;
429
-    /* Invert speed */
430
-    wspx.w = -(int16_t)wspx.w;
431
-  } else if(wposx.b.h <= MINWINX) {
432
-    wposx.b.h = MINWINX;
433
-    /* Invert speed */
434
-    wspx.w = -(int16_t)wspx.w;
435
-  }
436
-  WX_REG = wposx.b.h;
437
-  /* Y position */
438
-  if(wposy.b.h >= MAXWINY) {
439
-    wposy.b.h = MAXWINY;
440
-    /* Invert speed */
441
-    wspy.w = -(int16_t)wspy.w;
442
-  } else if(wposy.b.h <= MINWINY) {
443
-    wposy.b.h = MINWINY;
444
-    /* Invert speed */
445
-    wspy.w = -(int16_t)wspy.w;
446
-  }
447
-  WY_REG = wposy.b.h;
448
-
449
-  /* Update sprite */
450
-  sposx.w += sspx.w;
451
-  sposy.w += sspy.w;
452
-  place_sprite();
453
-}
454
-
455
-/* Open and close the door */
456
-void door(void)
457
-{
458
-  if(doorstate == OPENING) {
459
-    doorpos++;
460
-    /* Draw the door in the window */
461
-    set_win_tiles(2, 2, 12, 6, (unsigned char*)film[doorpos]);
462
-    if(doorpos == NBDFRAMES)
463
-      doorstate = OPENED;
464
-  } else if(doorstate == CLOSING) {
465
-    doorpos--;
466
-    /* Draw the door in the window */
467
-    set_win_tiles(2, 2, 12, 6, (unsigned char*)film[doorpos]);
468
-    if(doorpos == 0)
469
-      doorstate = CLOSED;
470
-  }
471
-}
472
-
473
-/* Animate sprite */
474
-void animate_sprite(void)
475
-{
476
-  if((time&0x07) == 0) {
477
-    sframe++;
478
-    if(sframe == NBSFRAMES)
479
-      sframe = 0;
480
-    tile_sprite();
481
-  }
482
-}
483
-
484
-/* Set sprite tiles */
485
-void tile_sprite(void)
486
-{
487
-  uint8_t s;
488
-
489
-  s = sframe<<1;
490
-  set_sprite_tile(0, earth_tiles[s]);
491
-  set_sprite_tile(1, earth_tiles[s+1]);
492
-}
493
-
494
-/* Place sprite */
495
-void place_sprite(void)
496
-{
497
-  move_sprite(0, sposx.b.h, sposy.b.h);
498
-  move_sprite(1, sposx.b.h+8, sposy.b.h);
499
-}
500
-
501
-void main(void)
502
-{
503
-  uint8_t i, j;
504
-
505
-  disable_interrupts();
506
-  DISPLAY_OFF;
507
-  LCDC_REG = LCDCF_OFF | LCDCF_WIN9C00 | LCDCF_WINON | LCDCF_BG8800 | LCDCF_BG9800 | LCDCF_OBJ16 | LCDCF_OBJON | LCDCF_BGON;
508
-  /*
509
-   * LCD        = Off
510
-   * WindowBank = 0x9C00
511
-   * Window     = On
512
-   * BG Chr     = 0x8800
513
-   * BG Bank    = 0x9800
514
-   * OBJ        = 8x16
515
-   * OBJ        = On
516
-   * BG         = On
517
-   */
518
-
519
-  doorstate = CLOSED;
520
-
521
-  /* Set palettes */
522
-  BGP_REG = OBP0_REG = OBP1_REG = 0xE4U;
523
-
524
-  /* Initialize the background */
525
-  set_bkg_data(0xFC, 0x04, std_data);
526
-  set_bkg_data(0x00, 0x2D, bkg_data);
527
-  /*
528
-   * Draw the background
529
-   *
530
-   * Width  = 0x100 = 0x20 * 8
531
-   * Height = 0x100 = 0x20 * 8
532
-   */
533
-  for(i = 0; i < 32; i+=8)
534
-    for(j = 0; j < 32; j+=8)
535
-      set_bkg_tiles(i, j, 8, 8, bkg_tiles);
536
-  bposx.w = 0;
537
-  SCX_REG = 0;
538
-  bposy.w = 0;
539
-  SCY_REG = 0;
540
-  bspx.w = 0xFF00;
541
-  bspy.w = 0x0080;
542
-
543
-  /* Initialize the window */
544
-  set_win_data(0x80, 0x21, frame_data);
545
-  /*
546
-   * Draw the frame in the window
547
-   *
548
-   * Width  = 0x80 = 0x10 * 8
549
-   * Height = 0x50 = 0x0A * 8
550
-   */
551
-  set_win_tiles(0, 0, 16, 10, frame_tiles);
552
-  /*
553
-   * Draw the door in the window
554
-   *
555
-   * Width  = 0x60 = 0x20 * 12
556
-   * Height = 0x30 = 0x20 * 6
557
-   */
558
-  set_win_tiles(2, 2, 12, 6, door1_tiles);
559
-  wposx.b.h = MAXWNDPOSX;
560
-  wposx.b.l = 0;
561
-  WX_REG = MAXWNDPOSX;
562
-  wposy.b.h = MAXWNDPOSY;
563
-  wposy.b.l = 0;
564
-  WY_REG = MAXWNDPOSY;
565
-  wspx.w = 0xFF80;
566
-  wspy.w = 0xFFC0;
567
-
568
-  /* Initialize the sprite */
569
-  set_sprite_data(0x00, 0x1C, earth_data);
570
-  set_sprite_prop(0, 0x00);
571
-  set_sprite_prop(1, 0x00);
572
-  sframe = 0;
573
-  sposx.w  = 0x1000;
574
-  sposy.w  = 0x1000;
575
-  sspx.w  = 0x0040;
576
-  sspy.w  = 0x0040;
577
-  tile_sprite();
578
-  place_sprite();
579
-
580
-  DISPLAY_ON;
581
-  enable_interrupts();
582
-
583
-  while(1) {
584
-    /* Skip four VBLs (slow down animation) */
585
-    for(i = 0; i < 4; i++)
586
-      vsync();
587
-    time++;
588
-    fade();
589
-    door();
590
-    scroll();
591
-    animate_sprite();
592
-    i = joypad();
593
-    if(i & J_B) {
594
-      if(i & J_UP)
595
-	bspy.w -= 0x0010;
596
-      if(i & J_DOWN)
597
-	bspy.w += 0x0010;
598
-      if(i & J_LEFT)
599
-	bspx.w -= 0x0010;
600
-      if(i & J_RIGHT)
601
-	bspx.w += 0x0010;
602
-    } else if(i & J_A) {
603
-      if(i & J_UP)
604
-	wspy.w -= 0x0010;
605
-      if(i & J_DOWN)
606
-	wspy.w += 0x0010;
607
-      if(i & J_LEFT)
608
-	wspx.w -= 0x0010;
609
-      if(i & J_RIGHT)
610
-	wspx.w += 0x0010;
611
-    } else {
612
-      if(i & J_SELECT)
613
-	color = STARTFADE;
614
-      if(i & J_START)
615
-	if(doorstate == CLOSED) {
616
-	  doorstate = OPENING;
617
-	  doorpos = 0;
618
-	} else if(doorstate == OPENED) {
619
-	  doorstate = CLOSING;
620
-	  doorpos = NBDFRAMES;
621
-	}
622
-      if(i & J_UP)
623
-	sspy.w -= 0x0010;
624
-      if(i & J_DOWN)
625
-	sspy.w += 0x0010;
626
-      if(i & J_LEFT)
627
-	sspx.w -= 0x0010;
628
-      if(i & J_RIGHT)
629
-	sspx.w += 0x0010;
630
-    }
631
-  }
632
-}

+ 212
- 0
src/main.c View File

1
+#include <gbdk/platform.h>
2
+#include <gbdk/metasprites.h>
3
+
4
+#include "rockshp.h"
5
+
6
+#define TILE_WIDTH          8
7
+#define TILE_HEIGHT         8
8
+#define NUM_BYTES_PER_TILE  16
9
+
10
+#define ACC_X 1
11
+#define ACC_Y 2
12
+
13
+// The metasprite will be built starting with hardware sprite zero (the first)
14
+#define SPR_NUM_START 0
15
+
16
+// Metasprite tiles are loaded into VRAM starting at tile number 0
17
+#define TILE_NUM_START 0
18
+
19
+int16_t PosX, PosY;
20
+int16_t SpdX, SpdY;
21
+uint8_t PosF;
22
+uint8_t idx, rot;
23
+
24
+size_t num_tiles;
25
+uint8_t flipped_data[NUM_BYTES_PER_TILE];
26
+
27
+uint8_t joyp = 0, old_joyp = 0;
28
+
29
+#define KEY_INPUT (old_joyp = joyp, joyp = joypad())
30
+#define KEY_DOWN(KEY) (joyp & (KEY))
31
+#define KEY_PRESSED(KEY) ((joyp ^ old_joyp) & joyp & (KEY))
32
+
33
+// Table for fast reversing of bits in a byte - used for flipping in X
34
+const uint8_t reverse_bits[256] = {
35
+    0x00,0x80,0x40,0xC0,0x20,0xA0,0x60,0xE0,0x10,0x90,0x50,0xD0,0x30,0xB0,0x70,0xF0,
36
+    0x08,0x88,0x48,0xC8,0x28,0xA8,0x68,0xE8,0x18,0x98,0x58,0xD8,0x38,0xB8,0x78,0xF8,
37
+    0x04,0x84,0x44,0xC4,0x24,0xA4,0x64,0xE4,0x14,0x94,0x54,0xD4,0x34,0xB4,0x74,0xF4,
38
+    0x0C,0x8C,0x4C,0xCC,0x2C,0xAC,0x6C,0xEC,0x1C,0x9C,0x5C,0xDC,0x3C,0xBC,0x7C,0xFC,
39
+    0x02,0x82,0x42,0xC2,0x22,0xA2,0x62,0xE2,0x12,0x92,0x52,0xD2,0x32,0xB2,0x72,0xF2,
40
+    0x0A,0x8A,0x4A,0xCA,0x2A,0xAA,0x6A,0xEA,0x1A,0x9A,0x5A,0xDA,0x3A,0xBA,0x7A,0xFA,
41
+    0x06,0x86,0x46,0xC6,0x26,0xA6,0x66,0xE6,0x16,0x96,0x56,0xD6,0x36,0xB6,0x76,0xF6,
42
+    0x0E,0x8E,0x4E,0xCE,0x2E,0xAE,0x6E,0xEE,0x1E,0x9E,0x5E,0xDE,0x3E,0xBE,0x7E,0xFE,
43
+    0x01,0x81,0x41,0xC1,0x21,0xA1,0x61,0xE1,0x11,0x91,0x51,0xD1,0x31,0xB1,0x71,0xF1,
44
+    0x09,0x89,0x49,0xC9,0x29,0xA9,0x69,0xE9,0x19,0x99,0x59,0xD9,0x39,0xB9,0x79,0xF9,
45
+    0x05,0x85,0x45,0xC5,0x25,0xA5,0x65,0xE5,0x15,0x95,0x55,0xD5,0x35,0xB5,0x75,0xF5,
46
+    0x0D,0x8D,0x4D,0xCD,0x2D,0xAD,0x6D,0xED,0x1D,0x9D,0x5D,0xDD,0x3D,0xBD,0x7D,0xFD,
47
+    0x03,0x83,0x43,0xC3,0x23,0xA3,0x63,0xE3,0x13,0x93,0x53,0xD3,0x33,0xB3,0x73,0xF3,
48
+    0x0B,0x8B,0x4B,0xCB,0x2B,0xAB,0x6B,0xEB,0x1B,0x9B,0x5B,0xDB,0x3B,0xBB,0x7B,0xFB,
49
+    0x07,0x87,0x47,0xC7,0x27,0xA7,0x67,0xE7,0x17,0x97,0x57,0xD7,0x37,0xB7,0x77,0xF7,
50
+    0x0F,0x8F,0x4F,0xCF,0x2F,0xAF,0x6F,0xEF,0x1F,0x9F,0x5F,0xDF,0x3F,0xBF,0x7F,0xFF
51
+};
52
+
53
+void set_tile(uint8_t tile_idx, uint8_t* data, uint8_t flip_x, uint8_t flip_y)
54
+{
55
+    size_t i;
56
+    for(i = 0; i < TILE_HEIGHT; i++)
57
+    {
58
+        size_t y = flip_y ? (TILE_HEIGHT-1-i) : i;
59
+        flipped_data[2*i] = flip_x ? reverse_bits[data[2*y]] : data[2*y];
60
+        flipped_data[2*i+1] = flip_x ? reverse_bits[data[2*y+1]] : data[2*y+1];
61
+    }
62
+    set_sprite_data(tile_idx, 1, flipped_data);
63
+}
64
+
65
+uint8_t get_tile_offset(uint8_t flipx, uint8_t flipy)
66
+{
67
+    flipx; flipy; // suppress compiler warnings
68
+    uint8_t offset = 0;
69
+    #if !HARDWARE_SPRITE_CAN_FLIP_Y
70
+    offset += flipy ? num_tiles : 0;
71
+    #endif
72
+    #if !HARDWARE_SPRITE_CAN_FLIP_X
73
+    offset <<= 1;
74
+    offset += flipx ? num_tiles : 0;
75
+    #endif
76
+    return offset;
77
+}
78
+
79
+void main(void) {
80
+    DISPLAY_OFF;
81
+
82
+    set_default_palette();
83
+
84
+    size_t i;
85
+    num_tiles = sizeof(rockshp_tiles) >> 4;
86
+    for(i = 0; i < num_tiles; i++)
87
+    {
88
+        set_tile(i + get_tile_offset(0, 0), rockshp_tiles + (i << 4), 0, 0);
89
+    }
90
+
91
+    // Show bkg and sprites
92
+    SHOW_BKG; SHOW_SPRITES;
93
+
94
+    // Check what size hardware sprite the metasprite is using (from sprite.h)
95
+    #if sprite_TILE_H == 16
96
+    SPRITES_8x16;
97
+    #else
98
+    SPRITES_8x8;
99
+    #endif
100
+    DISPLAY_ON;
101
+
102
+    // Set initial position to the center of the screen, zero out speed
103
+    PosX = (DEVICE_SCREEN_PX_WIDTH / 2) << 4;
104
+    PosY = (DEVICE_SCREEN_PX_HEIGHT / 2) << 4;
105
+    SpdX = SpdY = 0;
106
+
107
+    idx = 0; rot = 0;
108
+
109
+    while(1) {
110
+        KEY_INPUT;
111
+
112
+        PosF = 0;
113
+        // Game object
114
+        if (KEY_DOWN(J_UP)) {
115
+            SpdY -= 2;
116
+            if (SpdY < -32) SpdY = -32;
117
+            PosF |= ACC_Y;
118
+        } else if (KEY_DOWN(J_DOWN)) {
119
+            SpdY += 2;
120
+            if (SpdY > 32) SpdY = 32;
121
+            PosF |= ACC_Y;
122
+        }
123
+
124
+        if (KEY_DOWN(J_LEFT)) {
125
+            SpdX -= 2;
126
+            if (SpdX < -32) SpdX = -32;
127
+            PosF |= ACC_X;
128
+        } else if (KEY_DOWN(J_RIGHT)) {
129
+            SpdX += 2;
130
+            if (SpdX > 32) SpdX = 32;
131
+            PosF |= ACC_X;
132
+        }
133
+
134
+        // Press B button to cycle through metasprite animations
135
+        if (KEY_PRESSED(J_B)) {
136
+            idx++; if (idx >= (sizeof(rockshp_metasprites) >> 1)) idx = 0;
137
+        }
138
+
139
+        // Press A button to cycle metasprite through Normal/Flip-Y/Flip-XY/Flip-X and sub-pals
140
+        if (KEY_PRESSED(J_A)) {
141
+            rot++; rot &= 0xF;
142
+        }
143
+
144
+        PosX += SpdX, PosY += SpdY;
145
+
146
+        uint8_t hiwater = SPR_NUM_START;
147
+
148
+        // NOTE: In a real game it would be better to only call the move_metasprite..()
149
+        //       functions if something changed (such as movement or rotation). That
150
+        //       reduces CPU usage on frames that don't need updates.
151
+        //
152
+        // In this example they are called every frame to simplify the example code
153
+
154
+        // If not hidden the move and apply rotation to the metasprite
155
+        uint8_t subpal = rot >> 2;
156
+        switch (rot & 0x3) {
157
+            case 1:
158
+                hiwater += move_metasprite_flipy( rockshp_metasprites[idx],
159
+                                                  TILE_NUM_START + get_tile_offset(0, 1),
160
+                                                  subpal,
161
+                                                  hiwater,
162
+                                                  DEVICE_SPRITE_PX_OFFSET_X + (PosX >> 4),
163
+                                                  DEVICE_SPRITE_PX_OFFSET_Y + (PosY >> 4));
164
+                break;
165
+            case 2:
166
+                hiwater += move_metasprite_flipxy(rockshp_metasprites[idx],
167
+                                                  TILE_NUM_START + get_tile_offset(1, 1),
168
+                                                  subpal,
169
+                                                  hiwater,
170
+                                                  DEVICE_SPRITE_PX_OFFSET_X + (PosX >> 4),
171
+                                                  DEVICE_SPRITE_PX_OFFSET_Y + (PosY >> 4));
172
+                break;
173
+            case 3:
174
+                hiwater += move_metasprite_flipx( rockshp_metasprites[idx],
175
+                                                  TILE_NUM_START + get_tile_offset(1, 0),
176
+                                                  subpal,
177
+                                                  hiwater,
178
+                                                  DEVICE_SPRITE_PX_OFFSET_X + (PosX >> 4),
179
+                                                  DEVICE_SPRITE_PX_OFFSET_Y + (PosY >> 4));
180
+                break;
181
+            default:
182
+                hiwater += move_metasprite_ex(    rockshp_metasprites[idx],
183
+                                                  TILE_NUM_START + get_tile_offset(0, 0),
184
+                                                  subpal,
185
+                                                  hiwater,
186
+                                                  DEVICE_SPRITE_PX_OFFSET_X + (PosX >> 4),
187
+                                                  DEVICE_SPRITE_PX_OFFSET_Y + (PosY >> 4));
188
+                break;
189
+        }
190
+
191
+        // Hide rest of the hardware sprites, because amount of sprites differ between animation frames.
192
+        hide_sprites_range(hiwater, MAX_HARDWARE_SPRITES);
193
+
194
+        // Y Axis: update velocity (reduce speed) if no U/D button pressed
195
+        if (!(PosF & ACC_Y)) {
196
+            if (SpdY != 0) {
197
+                if (SpdY > 0) SpdY--;
198
+                else SpdY ++;
199
+            }
200
+        }
201
+
202
+        // X Axis: update velocity (reduce speed) if no L/R button pressed
203
+        if (!(PosF & ACC_X)) {
204
+            if (SpdX != 0) {
205
+                if (SpdX > 0) SpdX--;
206
+                else SpdX ++;
207
+            }
208
+        }
209
+
210
+        vsync();
211
+    }
212
+}

Loading…
Cancel
Save