From aa42870720c70fe39602fa0af791a9865faa8204 Mon Sep 17 00:00:00 2001 From: Norman Bos Date: Mon, 8 Apr 2024 23:56:20 +0200 Subject: [PATCH] move project to this repo --- .gitignore | 2 +- .vscode/c_cpp_properties.json | 16 +++ .vscode/settings.json | 16 +++ Makefile | 62 +++++++++ README.md | 13 +- compile.bat | 15 +++ res/alphabet.c | 125 ++++++++++++++++++ res/alphabet.h | 31 +++++ res/blankScreen.c | 19 +++ res/blankScreen.h | 6 + res/collision-test/tilemap.c | 33 +++++ res/collision-test/tilemap.h | 27 ++++ res/collision-test/tileset.c | 56 ++++++++ res/collision-test/tileset.h | 25 ++++ res/dungeon_32x32.gbm | Bin 0 -> 7348 bytes res/dungeon_32x32.gbr | Bin 0 -> 6613 bytes res/dungeon_map.c | 133 +++++++++++++++++++ res/dungeon_map.h | 28 ++++ res/dungeon_tiles.c | 188 +++++++++++++++++++++++++++ res/dungeon_tiles.h | 103 +++++++++++++++ res/helloWorld.c | 30 +++++ res/helloWorld.h | 27 ++++ res/hud.c | 30 +++++ res/hud.h | 27 ++++ res/submarine_sprites.c | 75 +++++++++++ res/submarine_sprites.h | 36 +++++ res/underwater_map.c | 64 +++++++++ res/underwater_map.h | 27 ++++ res/underwater_tiles.c | 111 ++++++++++++++++ res/underwater_tiles.h | 31 +++++ src/actor.c | 238 ++++++++++++++++++++++++++++++++++ src/actor.h | 39 ++++++ src/collision.c | 49 +++++++ src/collision.h | 13 ++ src/main.c | 166 ++++++++++++++++++++++++ 35 files changed, 1858 insertions(+), 3 deletions(-) create mode 100644 .vscode/c_cpp_properties.json create mode 100644 .vscode/settings.json create mode 100644 Makefile create mode 100644 compile.bat create mode 100644 res/alphabet.c create mode 100644 res/alphabet.h create mode 100644 res/blankScreen.c create mode 100644 res/blankScreen.h create mode 100644 res/collision-test/tilemap.c create mode 100644 res/collision-test/tilemap.h create mode 100644 res/collision-test/tileset.c create mode 100644 res/collision-test/tileset.h create mode 100644 res/dungeon_32x32.gbm create mode 100644 res/dungeon_32x32.gbr create mode 100644 res/dungeon_map.c create mode 100644 res/dungeon_map.h create mode 100644 res/dungeon_tiles.c create mode 100644 res/dungeon_tiles.h create mode 100644 res/helloWorld.c create mode 100644 res/helloWorld.h create mode 100644 res/hud.c create mode 100644 res/hud.h create mode 100644 res/submarine_sprites.c create mode 100644 res/submarine_sprites.h create mode 100644 res/underwater_map.c create mode 100644 res/underwater_map.h create mode 100644 res/underwater_tiles.c create mode 100644 res/underwater_tiles.h create mode 100644 src/actor.c create mode 100644 src/actor.h create mode 100644 src/collision.c create mode 100644 src/collision.h create mode 100644 src/main.c diff --git a/.gitignore b/.gitignore index f1827ba..59515ac 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ .DS_Store **/obj -*/gbdk +**/gbdk # Prerequisites *.d diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..b1f27e8 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,16 @@ +{ + "configurations": [ + { + "name": "Win32", + "includePath": [ + "${workspaceFolder}/**" + ], + "defines": [ + "_DEBUG", + "UNICODE", + "_UNICODE" + ] + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..ce94c0a --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,16 @@ +{ + "files.associations": { + "*.md": "markdown", + "stdio.h": "c", + "gb.h": "c", + "font.h": "c", + "smiley.h": "c", + "character.h": "c", + "metasprites.h": "c", + "blankscreen.h": "c", + "underwater_map.h": "c", + "collision.h": "c", + "common.h": "c", + "actor.h": "c" + } +} diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..02c67b5 --- /dev/null +++ b/Makefile @@ -0,0 +1,62 @@ +# +# A Makefile that compiles all .c and .s files in "src" and "res" +# subdirectories and places the output in a "obj" subdirectory +# + +# If you move this project you can change the directory +# to match your GBDK root directory (ex: GBDK_HOME = "C:/GBDK/" +GBDK_HOME = gbdk + +LCC = $(GBDK_HOME)bin/lcc + +# You can set flags for LCC here +# For example, you can uncomment the line below to turn on debug output +# LCCFLAGS += -debug # Uncomment to enable debug output +# LCCFLAGS += -v # Uncomment for lcc verbose output + + +# You can set the name of the .gb ROM file here +PROJECTNAME = Submarine + +SRCDIR = src +OBJDIR = obj +RESDIR = res +BINS = $(OBJDIR)/$(PROJECTNAME).gb +CSOURCES = $(foreach dir,$(SRCDIR),$(notdir $(wildcard $(dir)/*.c))) $(foreach dir,$(RESDIR),$(notdir $(wildcard $(dir)/*.c))) +ASMSOURCES = $(foreach dir,$(SRCDIR),$(notdir $(wildcard $(dir)/*.s))) +OBJS = $(CSOURCES:%.c=$(OBJDIR)/%.o) $(ASMSOURCES:%.s=$(OBJDIR)/%.o) + +all: prepare $(BINS) + +compile.bat: Makefile + @echo "REM Automatically generated from Makefile" > compile.bat + @make -sn | sed y/\\//\\\\/ | sed s/mkdir\ -p\/mkdir\/ | grep -v make >> compile.bat + +# Compile .c files in "src/" to .o object files +$(OBJDIR)/%.o: $(SRCDIR)/%.c + $(LCC) $(LCCFLAGS) -c -o $@ $< + +# Compile .c files in "res/" to .o object files +$(OBJDIR)/%.o: $(RESDIR)/%.c + $(LCC) $(LCCFLAGS) -c -o $@ $< + +# Compile .s assembly files in "src/" to .o object files +$(OBJDIR)/%.o: $(SRCDIR)/%.s + $(LCC) $(LCCFLAGS) -c -o $@ $< + +# If needed, compile .c files in "src/" to .s assembly files +# (not required if .c is compiled directly to .o) +$(OBJDIR)/%.s: $(SRCDIR)/%.c + $(LCC) $(LCCFLAGS) -S -o $@ $< + +# Link the compiled object files into a .gb ROM file +$(BINS): $(OBJS) + $(LCC) $(LCCFLAGS) -o $(BINS) $(OBJS) + +prepare: + mkdir -p $(OBJDIR) + +clean: +# rm -f *.gb *.ihx *.cdb *.adb *.noi *.map + rm -f $(OBJDIR)/*.* + diff --git a/README.md b/README.md index aac1f9d..a362f33 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,11 @@ -# gameboy-submarine - A gameboy game developed with gbdk +# A template project with a Makefile that supports sub-directories. + +The Makefile will automatically detect and compile new source files when they are added to the "src" and "res" directories. + +Project directories + +- src: Main program source files (.c, .h, .s) can go here +- res: Program graphics and audio source files (.c, .h, .s) can go here +- obj: Compiled ROM (.gb) and debug files go in this directory + +Must have gbdk-2020 in a folder named "gbdk" in the root folder. diff --git a/compile.bat b/compile.bat new file mode 100644 index 0000000..6f2725b --- /dev/null +++ b/compile.bat @@ -0,0 +1,15 @@ +REM Automatically generated from Makefile +mkdir obj +gbdk\bin\lcc -c -o obj\main.o src\main.c +gbdk\bin\lcc -c -o obj\actor.o src\actor.c +gbdk\bin\lcc -c -o obj\collision.o src\collision.c +gbdk\bin\lcc -c -o obj\submarine_sprites.o res\submarine_sprites.c +gbdk\bin\lcc -c -o obj\alphabet.o res\alphabet.c +gbdk\bin\lcc -c -o obj\blankScreen.o res\blankScreen.c +gbdk\bin\lcc -c -o obj\helloWorld.o res\helloWorld.c +gbdk\bin\lcc -c -o obj\hud.o res\hud.c +gbdk\bin\lcc -c -o obj\underwater_tiles.o res\underwater_tiles.c +gbdk\bin\lcc -c -o obj\underwater_map.o res\underwater_map.c +gbdk\bin\lcc -c -o obj\tileset.o res\collision-test\tileset.c +gbdk\bin\lcc -c -o obj\tilemap.o res\collision-test\tilemap.c +gbdk\bin\lcc -o obj\Submarine.gb obj\main.o obj\actor.o obj\collision.o obj\submarine_sprites.o obj\alphabet.o obj\blankScreen.o obj\helloWorld.o obj\hud.o obj\underwater_tiles.o obj\underwater_map.o obj\tileset.o obj\tilemap.o diff --git a/res/alphabet.c b/res/alphabet.c new file mode 100644 index 0000000..b5d1d97 --- /dev/null +++ b/res/alphabet.c @@ -0,0 +1,125 @@ +/* + + ALPHABET.C + + Tile Source File. + + Info: + Form : All tiles as one unit. + Format : Gameboy 4 color. + Compression : None. + Counter : None. + Tile size : 8 x 8 + Tiles : 0 to 47 + + Palette colors : None. + SGB Palette : None. + CGB Palette : None. + + Convert to metatiles : No. + + This file was generated by GBTD v2.2 + +*/ + +/* Start of tile array. */ +unsigned char alphabet[] = + { + 0x7C, 0x7C, 0x86, 0x86, 0x8A, 0x8A, 0x92, 0x92, + 0xA2, 0xA2, 0xC2, 0xC2, 0x7C, 0x7C, 0x00, 0x00, + 0x10, 0x10, 0x30, 0x30, 0x10, 0x10, 0x10, 0x10, + 0x10, 0x10, 0x10, 0x10, 0x7C, 0x7C, 0x00, 0x00, + 0x7C, 0x7C, 0x82, 0x82, 0x02, 0x02, 0x1C, 0x1C, + 0x60, 0x60, 0x80, 0x80, 0xFE, 0xFE, 0x00, 0x00, + 0xFE, 0xFE, 0x04, 0x04, 0x18, 0x18, 0x04, 0x04, + 0x02, 0x02, 0x82, 0x82, 0x7C, 0x7C, 0x00, 0x00, + 0x0C, 0x0C, 0x14, 0x14, 0x24, 0x24, 0x44, 0x44, + 0x84, 0x84, 0xFE, 0xFE, 0x04, 0x04, 0x00, 0x00, + 0xFC, 0xFC, 0x80, 0x80, 0xFC, 0xFC, 0x02, 0x02, + 0x02, 0x02, 0x82, 0x82, 0x7C, 0x7C, 0x00, 0x00, + 0x7C, 0x7C, 0x80, 0x80, 0x80, 0x80, 0xFC, 0xFC, + 0x82, 0x82, 0x82, 0x82, 0x7C, 0x7C, 0x00, 0x00, + 0xFE, 0xFE, 0x82, 0x82, 0x04, 0x04, 0x08, 0x08, + 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, + 0x7C, 0x7C, 0x82, 0x82, 0x82, 0x82, 0x7C, 0x7C, + 0x82, 0x82, 0x82, 0x82, 0x7C, 0x7C, 0x00, 0x00, + 0x7C, 0x7C, 0x82, 0x82, 0x82, 0x82, 0x7E, 0x7E, + 0x02, 0x02, 0x02, 0x02, 0x7C, 0x7C, 0x00, 0x00, + 0x00, 0x00, 0x30, 0x30, 0x30, 0x30, 0x00, 0x00, + 0x30, 0x30, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, + 0x08, 0x08, 0x2E, 0x2E, 0xF8, 0xF8, 0x28, 0x28, + 0x3E, 0x3E, 0xE8, 0xE8, 0x20, 0x20, 0x00, 0x00, + 0x08, 0x08, 0x10, 0x10, 0x20, 0x20, 0x40, 0x40, + 0x20, 0x20, 0x10, 0x10, 0x08, 0x08, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x7C, 0x7C, 0x00, 0x00, + 0x7C, 0x7C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x20, 0x20, 0x10, 0x10, 0x08, 0x08, 0x04, 0x04, + 0x08, 0x08, 0x10, 0x10, 0x20, 0x20, 0x00, 0x00, + 0x3C, 0x3C, 0x42, 0x42, 0x02, 0x02, 0x0C, 0x0C, + 0x10, 0x10, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, + 0x7C, 0x7C, 0x82, 0x82, 0x9A, 0x9A, 0xAA, 0xAA, + 0xBC, 0xBC, 0x80, 0x80, 0x7C, 0x7C, 0x00, 0x00, + 0x38, 0x38, 0x44, 0x44, 0x82, 0x82, 0x82, 0x82, + 0xFE, 0xFE, 0x82, 0x82, 0x82, 0x82, 0x00, 0x00, + 0xFC, 0xFC, 0x82, 0x82, 0x82, 0x82, 0xFC, 0xFC, + 0x82, 0x82, 0x82, 0x82, 0xFC, 0xFC, 0x00, 0x00, + 0x7C, 0x7C, 0x82, 0x82, 0x80, 0x80, 0x80, 0x80, + 0x80, 0x80, 0x82, 0x82, 0x7C, 0x7C, 0x00, 0x00, + 0xF8, 0xF8, 0x84, 0x84, 0x82, 0x82, 0x82, 0x82, + 0x82, 0x82, 0x84, 0x84, 0xF8, 0xF8, 0x00, 0x00, + 0xFE, 0xFE, 0x80, 0x80, 0x80, 0x80, 0xFC, 0xFC, + 0x80, 0x80, 0x80, 0x80, 0xFE, 0xFE, 0x00, 0x00, + 0xFE, 0xFE, 0x80, 0x80, 0x80, 0x80, 0xFC, 0xFC, + 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, + 0x7C, 0x7C, 0x82, 0x82, 0x80, 0x80, 0x80, 0x80, + 0x8E, 0x8E, 0x82, 0x82, 0x7E, 0x7E, 0x00, 0x00, + 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0xFE, 0xFE, + 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x00, 0x00, + 0x7C, 0x7C, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, + 0x10, 0x10, 0x10, 0x10, 0x7C, 0x7C, 0x00, 0x00, + 0x1E, 0x1E, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, + 0x04, 0x04, 0x84, 0x84, 0x78, 0x78, 0x00, 0x00, + 0x84, 0x84, 0x88, 0x88, 0x90, 0x90, 0xF0, 0xF0, + 0x88, 0x88, 0x84, 0x84, 0x82, 0x82, 0x00, 0x00, + 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, + 0x40, 0x40, 0x40, 0x40, 0x7E, 0x7E, 0x00, 0x00, + 0x82, 0x82, 0xC6, 0xC6, 0xAA, 0xAA, 0x92, 0x92, + 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x00, 0x00, + 0x82, 0x82, 0xC2, 0xC2, 0xA2, 0xA2, 0x92, 0x92, + 0x8A, 0x8A, 0x86, 0x86, 0x82, 0x82, 0x00, 0x00, + 0x7C, 0x7C, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, + 0x82, 0x82, 0x82, 0x82, 0x7C, 0x7C, 0x00, 0x00, + 0xFC, 0xFC, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, + 0xFC, 0xFC, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, + 0x7C, 0x7C, 0x82, 0x82, 0x82, 0x82, 0x92, 0x92, + 0x8A, 0x8A, 0x84, 0x84, 0x7A, 0x7A, 0x00, 0x00, + 0xFC, 0xFC, 0x82, 0x82, 0x82, 0x82, 0x84, 0x84, + 0xF8, 0xF8, 0x84, 0x84, 0x82, 0x82, 0x00, 0x00, + 0x7C, 0x7C, 0x80, 0x80, 0x80, 0x80, 0x7C, 0x7C, + 0x02, 0x02, 0x02, 0x02, 0xFC, 0xFC, 0x00, 0x00, + 0xFE, 0xFE, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, + 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, + 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, + 0x82, 0x82, 0x82, 0x82, 0x7C, 0x7C, 0x00, 0x00, + 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, + 0x44, 0x44, 0x28, 0x28, 0x10, 0x10, 0x00, 0x00, + 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x92, 0x92, + 0xAA, 0xAA, 0xC6, 0xC6, 0x82, 0x82, 0x00, 0x00, + 0x82, 0x82, 0x44, 0x44, 0x28, 0x28, 0x10, 0x10, + 0x28, 0x28, 0x44, 0x44, 0x82, 0x82, 0x00, 0x00, + 0x82, 0x82, 0x44, 0x44, 0x28, 0x28, 0x10, 0x10, + 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, + 0xFE, 0xFE, 0x04, 0x04, 0x08, 0x08, 0x10, 0x10, + 0x20, 0x20, 0x40, 0x40, 0xFE, 0xFE, 0x00, 0x00, + 0x1C, 0x1C, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, + 0x10, 0x10, 0x10, 0x10, 0x1C, 0x1C, 0x00, 0x00, + 0x80, 0x80, 0x40, 0x40, 0x20, 0x20, 0x10, 0x10, + 0x08, 0x08, 0x04, 0x04, 0x02, 0x02, 0x00, 0x00, + 0x70, 0x70, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, + 0x10, 0x10, 0x10, 0x10, 0x70, 0x70, 0x00, 0x00, + 0x10, 0x10, 0x28, 0x28, 0x44, 0x44, 0x82, 0x82, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFE, 0x00, 0x00}; + +/* End of ALPHABET.C */ diff --git a/res/alphabet.h b/res/alphabet.h new file mode 100644 index 0000000..5cca50a --- /dev/null +++ b/res/alphabet.h @@ -0,0 +1,31 @@ +/* + + ALPHABET.H + + Include File. + + Info: + Form : All tiles as one unit. + Format : Gameboy 4 color. + Compression : None. + Counter : None. + Tile size : 8 x 8 + Tiles : 0 to 47 + + Palette colors : None. + SGB Palette : None. + CGB Palette : None. + + Convert to metatiles : No. + + This file was generated by GBTD v2.2 + +*/ + + +/* Bank of tiles. */ +#define alphabetBank 0 +/* Start of tile array. */ +extern unsigned char alphabet[]; + +/* End of ALPHABET.H */ diff --git a/res/blankScreen.c b/res/blankScreen.c new file mode 100644 index 0000000..b37d59a --- /dev/null +++ b/res/blankScreen.c @@ -0,0 +1,19 @@ +unsigned char blankScreen[] = + { + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30}; \ No newline at end of file diff --git a/res/blankScreen.h b/res/blankScreen.h new file mode 100644 index 0000000..060e41e --- /dev/null +++ b/res/blankScreen.h @@ -0,0 +1,6 @@ +/* Bank of tiles. */ +#define blankScreenBank 0 +/* Start of tile array. */ +extern unsigned char blankScreen[]; + +/* End of ALPHABET.H */ \ No newline at end of file diff --git a/res/collision-test/tilemap.c b/res/collision-test/tilemap.c new file mode 100644 index 0000000..1d42363 --- /dev/null +++ b/res/collision-test/tilemap.c @@ -0,0 +1,33 @@ +//AUTOGENERATED FILE FROM png2asset + +#include +#include +#include + +BANKREF(tilemap) + +const palette_color_t tilemap_palettes[4] = { + RGB8(255,255,255), RGB8(212,212,212), RGB8(138,138,138), RGB8( 0, 0, 0) + +}; + +const unsigned char tilemap_map[360] = { + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x09,0x09,0x09,0x00,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x00,0x09,0x09,0x09,0x00, + 0x00,0x09,0x09,0x09,0x00,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x00,0x09,0x09,0x09,0x00, + 0x00,0x09,0x09,0x09,0x07,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x00,0x09,0x09,0x09,0x00, + 0x00,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x00,0x09,0x09,0x09,0x00, + 0x00,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x00,0x09,0x09,0x09,0x00, + 0x00,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x00,0x09,0x09,0x09,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x09,0x09,0x09,0x07,0x09,0x09,0x09,0x00, + 0x00,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x00,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x00, + 0x00,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x00,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x00, + 0x00,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x00,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x00, + 0x00,0x09,0x09,0x09,0x09,0x05,0x09,0x09,0x09,0x09,0x09,0x00,0x00,0x06,0x09,0x09,0x09,0x08,0x00,0x00, + 0x00,0x09,0x09,0x09,0x09,0x00,0x09,0x09,0x09,0x09,0x09,0x00,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x00, + 0x00,0x06,0x09,0x09,0x09,0x01,0x00,0x00,0x00,0x00,0x00,0x02,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x00, + 0x00,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x00, + 0x00,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x00, + 0x00,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +}; diff --git a/res/collision-test/tilemap.h b/res/collision-test/tilemap.h new file mode 100644 index 0000000..b442241 --- /dev/null +++ b/res/collision-test/tilemap.h @@ -0,0 +1,27 @@ +//AUTOGENERATED FILE FROM png2asset +#ifndef METASPRITE_tilemap_H +#define METASPRITE_tilemap_H + +#include +#include +#include + +#define tilemap_TILE_ORIGIN 0 +#define tilemap_TILE_W 8 +#define tilemap_TILE_H 8 +#define tilemap_WIDTH 160 +#define tilemap_HEIGHT 144 +#define tilemap_TILE_COUNT 0 +#define tilemap_PALETTE_COUNT 1 +#define tilemap_COLORS_PER_PALETTE 4 +#define tilemap_TOTAL_COLORS 4 +#define tilemap_MAP_ATTRIBUTES 0 + +BANKREF_EXTERN(tilemap) + +extern const palette_color_t tilemap_palettes[4]; + +extern const unsigned char tilemap_map[360]; +#define tilemap_map_attributes tilemap_map + +#endif diff --git a/res/collision-test/tileset.c b/res/collision-test/tileset.c new file mode 100644 index 0000000..73617e5 --- /dev/null +++ b/res/collision-test/tileset.c @@ -0,0 +1,56 @@ +//AUTOGENERATED FILE FROM png2asset + +#include +#include +#include + +BANKREF(tileset) + +const palette_color_t tileset_palettes[4] = { + RGB8(255,255,255), RGB8(212,212,212), RGB8(138,138,138), RGB8( 0, 0, 0) + +}; + +const uint8_t tileset_tiles[160] = { + 0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff, + 0x7f,0x7f,0x3f,0x3f, + 0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff, + 0xfe,0xfe,0xfc,0xfc, + 0xfc,0xfc,0xfe,0xfe, + 0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff, + 0x3f,0x3f,0x7f,0x7f, + 0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff, + 0x3c,0x3c,0x7e,0x7e, + 0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff, + 0xfc,0xfc,0xfe,0xfe, + 0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff, + 0xfe,0xfe,0xfc,0xfc, + 0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff, + 0x7e,0x7e,0x3c,0x3c, + 0x3f,0x3f,0x7f,0x7f, + 0xff,0xff,0xff,0xff, + 0xff,0xff,0xff,0xff, + 0x7f,0x7f,0x3f,0x3f, + 0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00 + }; + diff --git a/res/collision-test/tileset.h b/res/collision-test/tileset.h new file mode 100644 index 0000000..530783b --- /dev/null +++ b/res/collision-test/tileset.h @@ -0,0 +1,25 @@ +//AUTOGENERATED FILE FROM png2asset +#ifndef METASPRITE_tileset_H +#define METASPRITE_tileset_H + +#include +#include +#include + +#define tileset_TILE_ORIGIN 0 +#define tileset_TILE_W 8 +#define tileset_TILE_H 8 +#define tileset_WIDTH 80 +#define tileset_HEIGHT 8 +#define tileset_TILE_COUNT 10 +#define tileset_PALETTE_COUNT 1 +#define tileset_COLORS_PER_PALETTE 4 +#define tileset_TOTAL_COLORS 4 + +BANKREF_EXTERN(tileset) + +extern const palette_color_t tileset_palettes[4]; +extern const uint8_t tileset_tiles[160]; + + +#endif diff --git a/res/dungeon_32x32.gbm b/res/dungeon_32x32.gbm new file mode 100644 index 0000000000000000000000000000000000000000..7418854b2d6f1f0518ef93de8515f113f7d07d88 GIT binary patch literal 7348 zcmeHMNpDjz5dPAILfQAFEMebDN?Vq;EL~ViOAA5biXf#CK_YE{Rt14jg}8D>oTk5QA>@ z9QLNN>7mh^@xfFs-ZOsr%5eIcp8hMp&55@BIwwZ6>5h12Y%JH&)HE?Mk+_(;p3bHc zBk8fGJDFT|{15vk>{LPX^FR;&3J=8>iBqh;stu2iTuP6QoNsNp(b|%@G^FG7HSg!- z_Y5xFe?5id>#4gOtEQjNrCv?#c(wLIAk52OzRO_jeFj>t>`hzs`OMKreO1qXyopUd zd<=!B=U05o;7ey1@Ak5%n9KohIoHr}{MM(h8GPgy)KA`e3N`=Yhpea8)c9?j2iF_m z?+vcA&C$O{*@vrLNYc3~ekD%R(>hX(+<)x(6U;Qu|9=C$cby~IR4#E5(z|R3e>JE! znXWmlMNLRH1GOPp9cJWZn+V=e4IEH`i7^l=DAPex%c{%_vQyTaiMqVq3N`C#qC1Q6 z3`{Y^pGx-Sf%_N4WVo_s@r3K=8GoNyEKhDQuXxr~rFhp(WYs}Xl`OeT_4UAPFp^9R z<^fYijp?B?Ak3^F`bNK~ni#U51GO?u<^uD8`M@GzF|aTgF9;2m080aWqfe8tnn>8w zcQIKGluAFfMb%dFPzvxHfYl-@*RKKA0_!T%H~1Cm8<*%$yqqVTUk_{u{I48eOdS1< z0IPg+&~LHU-3n|A@EtyV`ZN_2N1r_G1R8-|h5PdH7yLJ|6Y}dv$5-s~|4Me;+^2zAVUsq0b*G{gVF$pw@%oC+v?* zIdY@#?8|~I7?$u~Lh0Zb{rv!6Rapym6-c(50%-?2cpG}^PN01L9|R5+s{&TXVW2bU zyMS(>N1sdaf}Q0{-tnKCl01(U^UAO%vv$vO)xj749el}i-UvLy>q6Nsv*Ejd`c7SN zE8>iUZ|Aw3@OHM#tQ_og-nk2GP2$sk9*Nt59fiD=eUgn6-|@{cJOUgA5 zr+FlAtd4FC#etLtBUSoSI*tZ^y}mF2%7>F2%7>F2%7>F2%81OS7e`BuaAAb3-A2!wN H|IPUcmJ{&! literal 0 HcmV?d00001 diff --git a/res/dungeon_32x32.gbr b/res/dungeon_32x32.gbr new file mode 100644 index 0000000000000000000000000000000000000000..ba5ca530398d9883b6b3185f8bd72da43076139b GIT binary patch literal 6613 zcmeHLyKY=X7@pmYLmDm;h}tDICZr2xgcK@BL61zbN+QKJ!m$hubd>Nav~);$0A3+) zKuZVT?VmGy*0FI+s50@M@67!7Z~mFAefQ26Hy5q7@9??1f3W`g== z{P1x7E!I75?cKr)bw4{gSbws6dV0EdfB$%Wu)lY>e)`c5kG?rLdGcT|h~34ogx3$= zyGZXwyV33;f#qs>#c@%ji{z{SXfVzy!HA0mi(4$Z`;tMxu`+b|%pCSIALa58vkv9I zL305v4Xf3XGYJh1Omn(`WJFEyh-u>+eP}7laYPT0QzH3KXZd$-s_sJCVuYR! zpiaZmNuK2noAT%(O(-DSq^sOe6mUTq*B8NZkPIMJ4zy(sKof>7O_6eebs%Z-=!xeg z3ECDaCGUynWwd8Z>JcGk1C+QNAa9Kcod@$|K9@o81N}OGY5{~yMD95w0i%P4lCm3% zV)aGrZC=)J0$Y6`r&<5tg}S}4P5ZuXYsD`OBMkXc_7N7;vU2A`x{=CIrjvc0hoN$C zz(#in$+1AJe-0woR+`QO9Al}nvl}jvJFa^}G10)RQcF?YlH5m{4Nwkr!d!xEQTOr7 z;1Ye71ZJ#q`%EDV!eB(BG&{}H%hZ4FD@xpto=@_rPbX`#qkcjh63ci4GEFO&9%hm= ztB^`8Ens+(Tn^3Kd`?F?Z`(YQAM(mUtof*a#<{yx{jTSndc}k4ANZK`m7E^pLA#{> zs5&D%n~&nl^;KO}Crw{eclFyD_1FIXD;_rYd8%u3UG=*Xq?BG5_Wz9it^L2C{;Ffd zOVuy`e1LEaFdFm=XFN$n^{G)p-YGR`G&tc@Me!csQ5^NCX@$}LENjH9gS_b==87qa z7veWXAV{T79rs@lDg*x%r~mj$L(PG3yxEVVo|Iqe{Miyueu?Bg(-~4;i0||W(hYRV zL!GTNfnta$ZxY~9KihL{P_fJjP6P(~i9;wI+$B6Ly04jW-8T~Uhm7%%vFt6X^}?B) z`-DL%F{)n>g^P-&@Qgb9o}h~0tz%w_x8l)+V%HP7c(*Bx^dsY%U`cbT%y@-YW<||e zf6V7lQ2!`w^%Xs>+ZgV6y_bH?54^DNlK57B^N+t;=Oz6C{7#&J$$UhuNZqrd~(#$!=LJo}4p(}O; z4^Gyo4d0JZU-58RbX=CtxItIU+A(;B)F~=WDprit6~~q)8z0uePam-o&k z_AiXD4TQAvDlB_!lJ_aU7cw*M7l-$iHns!VELPzz%4Wi2PT- z2Xc`MTpZUtSIPMl16Dql#|kkR7Cvl#9_O$pVoNat!})t2pDxWJj?Eg<|`qg}&kdnVC? zlf#GWqrlOcsdOWk(NUA9{mC@Sg!O36;#r%Tl)-^P#{GV?> zCfJ*8r(GxW_;c*@zy4@H{r;rgd~~nvyz_p0{^y77_HTFE?#ajPjoW*#e12^p;McZ( ld-=*E&MSPYU2i|*&R_6P)33*s7 +/* Start of tile array. */ +unsigned char submarine_tileset[] = + { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x02, + 0x07, 0x07, 0x04, 0x07, 0x04, 0x07, 0x0B, 0x0F, + 0x6F, 0x68, 0x57, 0x79, 0xE7, 0x9A, 0xA7, 0xDA, + 0x91, 0xFF, 0x78, 0x7F, 0x6F, 0x6F, 0x07, 0x07, + 0x00, 0x00, 0x80, 0xC0, 0x80, 0x80, 0x80, 0x80, + 0x60, 0xE0, 0xA0, 0x60, 0xB0, 0x70, 0xDE, 0xFE, + 0xF3, 0x11, 0xE1, 0x91, 0xFD, 0x51, 0xFD, 0x51, + 0x8D, 0xF9, 0x06, 0xFE, 0xFC, 0xFC, 0xF8, 0xF8, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x07, 0x07, 0x04, 0x07, 0x04, 0x07, 0x0B, 0x0F, + 0x0F, 0x08, 0x17, 0x19, 0xE7, 0xFA, 0xE7, 0x9A, + 0xF1, 0xFF, 0x18, 0x1F, 0x0F, 0x0F, 0x07, 0x07, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, + 0x60, 0xE0, 0xA0, 0x60, 0xB0, 0x70, 0xDE, 0xFE, + 0xF3, 0x11, 0xE1, 0x91, 0xFD, 0x51, 0xFD, 0x51, + 0x8D, 0xF9, 0x06, 0xFE, 0xFC, 0xFC, 0xF8, 0xF8, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x02, + 0x07, 0x07, 0x04, 0x07, 0x04, 0x07, 0x0B, 0x0F, + 0x8F, 0x88, 0x97, 0x99, 0xE7, 0xFA, 0xE7, 0x9A, + 0xF1, 0xFF, 0x98, 0x9F, 0x8F, 0x8F, 0x07, 0x07, + 0x00, 0x00, 0x80, 0xC0, 0x80, 0x80, 0x80, 0x80, + 0x60, 0xE0, 0xA0, 0x60, 0xB0, 0x70, 0xDE, 0xFE, + 0xF3, 0x11, 0xE1, 0x91, 0xFD, 0x51, 0xFD, 0x51, + 0x8D, 0xF9, 0x06, 0xFE, 0xFC, 0xFC, 0xF8, 0xF8, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + +/* Metatile index */ +const unsigned char submarine_tilemap[] = + { + 0x00, 0x02, 0x01, 0x03}; + +// Create the metasprite structure for the character +const metasprite_t submarine_metasprite[] = { + {.dy = -8, .dx = -8, .dtile = 0, .props = 0}, + {.dy = 0, .dx = 8, .dtile = 2, .props = 0}, + {.dy = 8, .dx = -8, .dtile = 1, .props = 0}, + {.dy = 0, .dx = 8, .dtile = 3, .props = 0}, + METASPR_TERM}; + +const metasprite_t submarine_metasprite2[] = { + {.dy = -8, .dx = -8, .dtile = 0, .props = 0}, + {.dy = 0, .dx = 8, .dtile = 2, .props = 0}, + {.dy = 8, .dx = -8, .dtile = 5, .props = 0}, + {.dy = 0, .dx = 8, .dtile = 3, .props = 0}, + METASPR_TERM}; + +/* End of SUBMARINE.C */ diff --git a/res/submarine_sprites.h b/res/submarine_sprites.h new file mode 100644 index 0000000..01ce4fd --- /dev/null +++ b/res/submarine_sprites.h @@ -0,0 +1,36 @@ +/* + + SUBMARINE.H + + Include File. + + Info: + Form : All tiles as one unit. + Format : Gameboy 4 color. + Compression : None. + Counter : None. + Tile size : 8 x 8 + Tiles : 0 to 12 + + Palette colors : None. + SGB Palette : None. + CGB Palette : None. + + Convert to metatiles : No. + + This file was generated by GBTD v2.2 + +*/ +#include +/* Bank of tiles. */ +#define submarineBank 0 +/* Start of tile array. */ +extern const unsigned char submarine_tileset[]; +/* Metatile index */ +extern const unsigned char submarine_tilemap[]; +// Create the metasprite structure for the character +extern const metasprite_t submarine_metasprite[]; + +extern const metasprite_t submarine_metasprite2[]; + +/* End of SUBMARINE.H */ diff --git a/res/underwater_map.c b/res/underwater_map.c new file mode 100644 index 0000000..46fb619 --- /dev/null +++ b/res/underwater_map.c @@ -0,0 +1,64 @@ +/* + + UNDERWATER_MAP.C + + Map Source File. + + Info: + Section : + Bank : 0 + Map size : 20 x 18 + Tile set : C:\users\normanbos\Desktop\underwater-tiles.gbr + Plane count : 1 plane (8 bits) + Plane order : Tiles are continues + Tile offset : 0 + Split data : No + + This file was generated by GBMB v1.8 + +*/ + +#define underwater_mapWidth 20 +#define underwater_mapHeight 18 +#define underwater_mapBank 0 + +unsigned char underwater_map[] = + { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x10, 0x12, 0x10, 0x12, 0x10, 0x12, 0x10, 0x12, 0x10, 0x12, + 0x10, 0x12, 0x10, 0x12, 0x10, 0x12, 0x10, 0x12, 0x10, 0x12, + 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, + 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, + 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, + 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, + 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, + 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x14, 0x16, + 0x14, 0x16, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, + 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x18, 0x18, + 0x18, 0x18, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, + 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x18, 0x18, + 0x18, 0x18, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, + 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x18, 0x18, + 0x18, 0x18, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, + 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x18, 0x18, + 0x18, 0x18, 0x08, 0x1C, 0x1E, 0x08, 0x08, 0x08, 0x08, 0x08, + 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x18, 0x18, + 0x18, 0x18, 0x08, 0x1D, 0x1F, 0x08, 0x08, 0x08, 0x08, 0x08, + 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x18, 0x18, + 0x18, 0x18, 0x08, 0x20, 0x22, 0x08, 0x08, 0x08, 0x08, 0x08, + 0x08, 0x08, 0x08, 0x08, 0x08, 0x1C, 0x1E, 0x08, 0x18, 0x18, + 0x18, 0x18, 0x08, 0x21, 0x23, 0x08, 0x08, 0x08, 0x08, 0x08, + 0x08, 0x08, 0x08, 0x08, 0x08, 0x1D, 0x1F, 0x08, 0x18, 0x18, + 0x18, 0x18, 0x08, 0x24, 0x26, 0x08, 0x08, 0x08, 0x08, 0x08, + 0x08, 0x08, 0x08, 0x08, 0x08, 0x24, 0x26, 0x08, 0x18, 0x18, + 0x18, 0x18, 0x09, 0x25, 0x27, 0x0B, 0x09, 0x0B, 0x09, 0x0B, + 0x09, 0x0B, 0x09, 0x0B, 0x09, 0x25, 0x27, 0x0B, 0x18, 0x18, + 0x04, 0x05, 0x04, 0x05, 0x04, 0x05, 0x04, 0x05, 0x04, 0x05, + 0x04, 0x05, 0x04, 0x05, 0x04, 0x05, 0x04, 0x05, 0x04, 0x05, + 0x06, 0x07, 0x06, 0x07, 0x06, 0x07, 0x06, 0x07, 0x06, 0x07, + 0x06, 0x07, 0x06, 0x07, 0x06, 0x07, 0x06, 0x07, 0x06, 0x07}; + +/* End of UNDERWATER_MAP.C */ diff --git a/res/underwater_map.h b/res/underwater_map.h new file mode 100644 index 0000000..df7f230 --- /dev/null +++ b/res/underwater_map.h @@ -0,0 +1,27 @@ +/* + + UNDERWATER_MAP.H + + Map Include File. + + Info: + Section : + Bank : 0 + Map size : 20 x 18 + Tile set : C:\users\normanbos\Desktop\underwater-tiles.gbr + Plane count : 1 plane (8 bits) + Plane order : Tiles are continues + Tile offset : 0 + Split data : No + + This file was generated by GBMB v1.8 + +*/ + +#define underwater_mapWidth 20 +#define underwater_mapHeight 18 +#define underwater_mapBank 0 + +extern unsigned char underwater_map[]; + +/* End of UNDERWATER_MAP.H */ diff --git a/res/underwater_tiles.c b/res/underwater_tiles.c new file mode 100644 index 0000000..b9dc120 --- /dev/null +++ b/res/underwater_tiles.c @@ -0,0 +1,111 @@ +/* + + UNDERWATER_TILES.C + + Tile Source File. + + Info: + Form : All tiles as one unit. + Format : Gameboy 4 color. + Compression : None. + Counter : None. + Tile size : 8 x 8 + Tiles : 0 to 40 + + Palette colors : None. + SGB Palette : None. + CGB Palette : None. + + Convert to metatiles : No. + + This file was generated by GBTD v2.2 + +*/ + +/* Start of tile array. */ +unsigned char underwater_tiles[] = + { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00, 0x08, + 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x40, 0x00, 0x04, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, + 0x00, 0x20, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x04, 0x00, 0x20, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x04, 0x00, 0x40, + 0x00, 0x00, 0x00, 0x04, 0x00, 0x40, 0x00, 0x00, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0x7E, 0x3C, 0xC3, 0xC3, 0x30, 0x00, 0xC0, 0x00, + 0xE3, 0x00, 0x98, 0x00, 0x6F, 0x00, 0xFF, 0x00, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0x3F, 0x1E, 0xE1, 0xE1, 0x18, 0x00, 0x61, 0x00, + 0x93, 0x00, 0x7F, 0x00, 0x19, 0x00, 0xFF, 0x00, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0xFF, 0xFF, 0x00, 0x00, 0xE9, 0x86, 0x80, 0xFF, + 0xC6, 0xFF, 0xFD, 0xF9, 0xFE, 0x70, 0xFF, 0x80, + 0xFF, 0x90, 0xDF, 0x58, 0xEF, 0x8F, 0xFF, 0x8F, + 0xFF, 0xC4, 0xFD, 0xF8, 0xFE, 0x70, 0xFF, 0x80, + 0xFF, 0xFF, 0x00, 0x00, 0x48, 0x26, 0x01, 0xFE, + 0x01, 0xFF, 0xB7, 0xFF, 0x7F, 0x5E, 0xBF, 0x00, + 0xFF, 0x00, 0xF1, 0x60, 0xEE, 0xC0, 0xFF, 0x20, + 0xFF, 0x33, 0xFF, 0x3F, 0x7F, 0x1E, 0xBF, 0x00, + 0xFF, 0x30, 0xDF, 0x58, 0xEF, 0x8F, 0xFF, 0x8F, + 0xFF, 0xC4, 0xFD, 0xF8, 0xFE, 0x70, 0xFF, 0x80, + 0xFF, 0x90, 0xDF, 0x58, 0xEF, 0x8F, 0xFF, 0x8F, + 0xFF, 0xC4, 0xFD, 0xF8, 0xFE, 0x70, 0xFF, 0x80, + 0xFF, 0x0E, 0xF1, 0xF1, 0xEE, 0xC0, 0xFF, 0x20, + 0xFF, 0x33, 0xFF, 0x3F, 0x7F, 0x1E, 0xBF, 0x00, + 0xFF, 0x00, 0xF1, 0x60, 0xEE, 0xC0, 0xFF, 0x20, + 0xFF, 0x33, 0xFF, 0x3F, 0x7F, 0x1E, 0xBF, 0x00, + 0xCF, 0x30, 0xE3, 0x1C, 0xF1, 0x0E, 0xF0, 0x0F, + 0xF8, 0x07, 0xF8, 0x07, 0xFC, 0x03, 0xF8, 0x07, + 0xF8, 0x07, 0xF1, 0x0E, 0xF1, 0x0E, 0xE2, 0x1D, + 0xE2, 0x1D, 0xC4, 0x3B, 0xC4, 0x3B, 0xC4, 0x3B, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0x7F, 0x80, 0x3F, 0xC0, 0x3F, 0xC0, 0x3F, 0xC0, + 0x1F, 0xE0, 0x1F, 0xE0, 0x1F, 0xE0, 0x1F, 0xE0, + 0x1F, 0xE0, 0x3F, 0xC0, 0x3F, 0xC0, 0x3F, 0xC0, + 0xC0, 0x3F, 0xC0, 0x3F, 0xE0, 0x1F, 0xF0, 0x0F, + 0xF8, 0x07, 0xFD, 0x02, 0xFC, 0x03, 0xFC, 0x03, + 0xF8, 0x07, 0xF1, 0x0E, 0xF1, 0x0E, 0xE2, 0x1D, + 0xE2, 0x1D, 0xC4, 0x3B, 0xC4, 0x3B, 0xC4, 0x3B, + 0x7F, 0x80, 0x7F, 0x80, 0x7F, 0x80, 0x1F, 0xE0, + 0x1F, 0xE0, 0x0F, 0xF0, 0x87, 0x78, 0x87, 0x78, + 0x07, 0xF8, 0x0F, 0xF0, 0x0F, 0xF0, 0x1F, 0xE0, + 0x1F, 0xE0, 0x1F, 0xE0, 0x3F, 0xC0, 0x3F, 0xC0, + 0xE0, 0x1F, 0xE0, 0x1F, 0xF0, 0x0F, 0xF8, 0x07, + 0xFC, 0x03, 0xFC, 0x03, 0xFE, 0x01, 0xFC, 0x03, + 0xF9, 0xFE, 0x00, 0x07, 0x00, 0x03, 0x00, 0x21, + 0x00, 0x01, 0x00, 0x03, 0x00, 0x07, 0x00, 0x0C, + 0x7F, 0x80, 0x7F, 0x80, 0x1F, 0xE0, 0x1F, 0xE0, + 0x0F, 0xF0, 0x0F, 0xF0, 0x0F, 0xF0, 0x8F, 0x70, + 0x1F, 0xFF, 0x00, 0xC0, 0x00, 0x84, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x84, 0x00, 0xC0, 0x00, 0x60, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + +/* End of UNDERWATER_TILES.C */ diff --git a/res/underwater_tiles.h b/res/underwater_tiles.h new file mode 100644 index 0000000..dd68d57 --- /dev/null +++ b/res/underwater_tiles.h @@ -0,0 +1,31 @@ +/* + + UNDERWATER_TILES.H + + Include File. + + Info: + Form : All tiles as one unit. + Format : Gameboy 4 color. + Compression : None. + Counter : None. + Tile size : 8 x 8 + Tiles : 0 to 40 + + Palette colors : None. + SGB Palette : None. + CGB Palette : None. + + Convert to metatiles : No. + + This file was generated by GBTD v2.2 + +*/ + + +/* Bank of tiles. */ +#define underwater_tilesBank 0 +/* Start of tile array. */ +extern unsigned char underwater_tiles[]; + +/* End of UNDERWATER_TILES.H */ diff --git a/src/actor.c b/src/actor.c new file mode 100644 index 0000000..21a9e85 --- /dev/null +++ b/src/actor.c @@ -0,0 +1,238 @@ +#include +#include +#include +#include +#include "collision.h" +#include "actor.h" + +//! Hierher gehören noch weiter Attribute. is_moving, direction, hitpoints, etc. +//! Oder besser: den Actor struct kann ich als Basis nehmen und evtl. extenden für verschiedene types (Player, Enemy, Pickup etc.) + +// A structure of the actor +/* typedef struct Actor +{ + uint8_t sprite_id; // The starting ID of the sprite for this actor. Remaining sprites should follow in sequency + uint8_t sprite_tile_width; // The number of tiles wide this sprite is + uint8_t sprite_tile_height; // The number tiles high this sprite is + uint8_t sprite_frame; // The total number of animated sprites + uint8_t sprite_current_frame; // The current frame the sprite is on + uint8_t tilemap_start; // The start index where the tiles start for this sprite + uint8_t x; // The sprite x position (top left) + uint8_t y; // The sprite y position (top left) + uint8_t next_x; // The future sprite x position (top left) + uint8_t next_y; // The future sprite y position (top left) + int8_t dx; // The sprite x moving direction + int8_t dy; // The sprite y moving direction + uint8_t velocity_x; // The current speed of travel in the X direction + uint8_t velocity_y; // The current speed of travel in the y direction + bool is_facing_right; // The direction the player sprite is facing + bool is_moving; // Is the actor moving or not + const unsigned char *tilemap; // A pointer to the tilemap (may be obsolete with metasprite) + const metasprite_t *metasprite; // A pointer to the metasprite +} Actor; */ + +//! die load_sprite_frame wird mit dem move_metasprite_ex gar nicht mehr benutzt! +/* void load_sprite_frame(Actor *actor, uint8_t frame) +{ + // Set current frame + actor->sprite_current_frame = frame; + + // Get total sprites + uint8_t spriteCount = actor->sprite_tile_width * actor->sprite_tile_height; + + for (uint8_t i = 0; i != spriteCount; i++) + { + set_sprite_tile(actor->sprite_id + i, actor->tilemap[actor->tilemap_start + i + (frame * spriteCount)]); + } +} */ + +void move_actor(Actor *actor, uint8_t x, uint8_t y) // Evtl. sollte is_moving hier mit übergeben werden +{ + + // Set actors new position + // actor->x = x; + // actor->y = y; + + // actor->x = actor->next_x; + // actor->y = actor->next_y; + + // Move the metasprite + if (actor->is_facing_right) + { + move_metasprite_ex(actor->metasprite, 0, 0, 0, x + 8, y + 16); + } + if (!actor->is_facing_right) + { + // flip the metasprite horizontally when is_facing_right is TRUE + move_metasprite_flipx(actor->metasprite, 0, 0, 0, x + 8, y + 16); + } +} + +void scroll_actor(Actor *actor) +{ + + uint8_t playerIsMoving = actor->dx != 0 || actor->dy != 0; + + // If the player is moving at all + // We'll handle horizontall and vertical movement separately + // Handling them separately enables a sliding motion against walls + if (playerIsMoving) + { + + // If we are moving horizontally + if (actor->dx != 0) + { + + // Check the tiles on our side + uint8_t solid = + world_position_is_solid(actor->next_x + actor->dx * PLAYER_HALF_WIDTH, actor->y - PLAYER_HALF_HEIGHT) || + world_position_is_solid(actor->next_x + actor->dx * PLAYER_HALF_WIDTH, actor->y) || + world_position_is_solid(actor->next_x + actor->dx * PLAYER_HALF_WIDTH, actor->y + PLAYER_HALF_HEIGHT); + + // printf("%u\n", world_position_is_solid(actor->x + actor->dx * PLAYER_HALF_WIDTH, actor->y - PLAYER_HALF_HEIGHT)); + + // If none are solid + if (!solid) + // if (solid != 0) + { + + // Update the player's x position + // actor->x += x; + actor->x = actor->next_x; + } + } + + // If we are moving vertically + if (actor->dy != 0) + { + + // Check the tiles above or below us + uint8_t solid = + world_position_is_solid(actor->x + PLAYER_HALF_WIDTH, actor->next_y + actor->dy * PLAYER_HALF_HEIGHT) || + world_position_is_solid(actor->x, actor->next_y + actor->dy * PLAYER_HALF_HEIGHT) || + world_position_is_solid(actor->x - PLAYER_HALF_WIDTH, actor->next_y + actor->dy * PLAYER_HALF_HEIGHT); + + // If none are solid + if (!solid) + // if (solid != 0) + { + + // Update the player's y position + // actor->y += y; + actor->y = actor->next_y; + } + } + + // actor->x += x; + // actor->y += y; + + move_actor(actor, actor->x, actor->y); + } +} + +void move_actor_with_joypad(Actor *actor) +{ + // Read buttons + uint8_t buttons = joypad(); + + bool is_moving_x = FALSE; + bool is_moving_y = FALSE; + + actor->dx = 0; + actor->dy = 0; + + if (buttons & J_LEFT) + { + actor->is_facing_right = FALSE; + is_moving_x = TRUE; + actor->next_x -= 1; + actor->dx = -1; + } + else if (buttons & J_RIGHT) + { + actor->is_facing_right = TRUE; + is_moving_x = TRUE; + actor->next_x += 1; + actor->dx = 1; + } + else + { + is_moving_x = FALSE; + } + + if (buttons & J_UP) + { + is_moving_y = TRUE; + actor->next_y -= 1; + actor->dy = -1; + } + else if (buttons & J_DOWN) + { + is_moving_y = TRUE; + actor->next_y += 1; + actor->dy = 1; + } + else + { + is_moving_y = FALSE; + } + + if (is_moving_x || is_moving_y) + { + actor->is_moving = TRUE; + } + else + { + actor->is_moving = FALSE; + } + + scroll_actor(actor); +} + +void setup_actor(Actor *actor, uint8_t sprite_id, uint8_t tile_width, uint8_t tile_height, uint8_t tilemap_start, uint8_t total_frames, bool is_facing_right, const unsigned char *tilemap, const metasprite_t *metasprite) +{ + + // Set initial X + actor->x = 80; + + // Set initial Y + actor->y = 90; + + // Set initial next X + actor->next_x = 80; + // Set initial next Y + actor->next_y = 90; + + // Set horizontal direction of + actor->is_facing_right = is_facing_right; + + // Set if the actor is moving + actor->is_moving = FALSE; + + // Store pointer to tilemap + actor->tilemap = tilemap; + + // Set tile start position (in tileset) + actor->tilemap_start = tilemap_start; + + // Set player sprite ID + actor->sprite_id = sprite_id; + + // Set size + actor->sprite_tile_width = tile_width; + actor->sprite_tile_height = tile_height; + + // Set number of frames + actor->sprite_frame = total_frames; + + // Make sure to start at frame 1 + actor->sprite_current_frame = 0; + + // Move to built in metasprite methods + // load_sprite_frame(actor, 0); + + // Store pointer to metasprite + actor->metasprite = metasprite; + + move_actor(actor, actor->x, actor->y); +} \ No newline at end of file diff --git a/src/actor.h b/src/actor.h new file mode 100644 index 0000000..7d6497b --- /dev/null +++ b/src/actor.h @@ -0,0 +1,39 @@ +#include +#include +#include +#include +#include "collision.h" + +//! Hierher gehören noch weiter Attribute. is_moving, direction, hitpoints, etc. +//! Oder besser: den Actor struct kann ich als Basis nehmen und evtl. extenden für verschiedene types (Player, Enemy, Pickup etc.) + +// A structure of the actor +typedef struct Actor +{ + uint8_t sprite_id; // The starting ID of the sprite for this actor. Remaining sprites should follow in sequency + uint8_t sprite_tile_width; // The number of tiles wide this sprite is + uint8_t sprite_tile_height; // The number tiles high this sprite is + uint8_t sprite_frame; // The total number of animated sprites + uint8_t sprite_current_frame; // The current frame the sprite is on + uint8_t tilemap_start; // The start index where the tiles start for this sprite + uint8_t x; // The sprite x position (top left) + uint8_t y; // The sprite y position (top left) + uint8_t next_x; // The future sprite x position (top left) + uint8_t next_y; // The future sprite y position (top left) + int8_t dx; // The sprite x moving direction + int8_t dy; // The sprite y moving direction + uint8_t velocity_x; // The current speed of travel in the X direction + uint8_t velocity_y; // The current speed of travel in the y direction + bool is_facing_right; // The direction the player sprite is facing + bool is_moving; // Is the actor moving or not + const unsigned char *tilemap; // A pointer to the tilemap (may be obsolete with metasprite) + const metasprite_t *metasprite; // A pointer to the metasprite +} Actor; + +void move_actor(Actor *actor, uint8_t x, uint8_t y); + +void scroll_actor(Actor *actor); + +void move_actor_with_joypad(Actor *actor); + +void setup_actor(Actor *actor, uint8_t sprite_id, uint8_t tile_width, uint8_t tile_height, uint8_t tilemap_start, uint8_t total_frames, bool is_facing_right, const unsigned char *tilemap, const metasprite_t *metasprite); \ No newline at end of file diff --git a/src/collision.c b/src/collision.c new file mode 100644 index 0000000..88be968 --- /dev/null +++ b/src/collision.c @@ -0,0 +1,49 @@ +#include +#include + +#include "../res/underwater_tiles.h" +#include "../res/underwater_map.h" +#include "../res/collision-test/tileset.h" +#include "../res/collision-test/tilemap.h" + +#define SOLID 1 +#define PLAYER_HALF_WIDTH 8 +#define PLAYER_HALF_HEIGHT 8 +#define GRID_NODE_SIZE 8 +#define NUMBER_OF_SOLID_TILES 9 + +#define TILEMAP_WIDTH_IN_TILES (tilemap_WIDTH >> 3) +#define TILEMAP_HEIGHT_IN_TILES (tilemap_HEIGHT >> 3) + +// uint16_t playerX, playerY; + +uint8_t world_position_is_solid(uint16_t x, uint16_t y) +{ + + // Bit-shifting would be faster here + uint16_t column = x / GRID_NODE_SIZE; + + // Make sure the tile is in proper bounds + if (column >= TILEMAP_WIDTH_IN_TILES) + return TRUE; + + uint16_t row = y / GRID_NODE_SIZE; + + // Make sure the tile is in proper bounds + if (row >= TILEMAP_HEIGHT_IN_TILES) + return TRUE; + + uint16_t tilemapIndex = column + row * TILEMAP_WIDTH_IN_TILES; + + uint8_t tileIsSolid = FALSE; + + // Get the tilset tile in our tilemap + uint8_t tilesetTile = tilemap_map[tilemapIndex]; + + // In our tileset, the solid tiles always come first. + // There are 10 tiles. The first 9 are solid + // this makes it fast & easy to determine if a tile is solid or not + tileIsSolid = tilesetTile < NUMBER_OF_SOLID_TILES; + + return tileIsSolid; +} \ No newline at end of file diff --git a/src/collision.h b/src/collision.h new file mode 100644 index 0000000..b8a70c7 --- /dev/null +++ b/src/collision.h @@ -0,0 +1,13 @@ +#include +#include + +#define SOLID 1 +#define PLAYER_MOVE_SPEED 10 +#define PLAYER_HALF_WIDTH 8 +#define PLAYER_HALF_HEIGHT 8 +#define GRID_NODE_SIZE 8 +#define NUMBER_OF_SOLID_TILES 9 + +// extern uint16_t playerX, playerY; + +uint8_t world_position_is_solid(uint16_t x, uint16_t y); diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..6e399b5 --- /dev/null +++ b/src/main.c @@ -0,0 +1,166 @@ +#include +#include + +#include "../res/alphabet.h" +#include "../res/blankScreen.h" +#include "../res/hud.h" +#include "../res/underwater_tiles.h" +#include "../res/underwater_map.h" +#include "../res/submarine_sprites.h" +#include "../res/collision-test/tileset.h" +#include "../res/collision-test/tilemap.h" + +#include "actor.h" +// #include "input.h" +#include "collision.h" + +Actor submarine; + +uint8_t two_frame_counter = 0; +uint8_t two_frame_real_value = 0; + +#define TILEMAP_WIDTH_IN_TILES (tilemap_WIDTH >> 3) +#define TILEMAP_HEIGHT_IN_TILES (tilemap_HEIGHT >> 3) + +// generic frame counter function +// from https://laroldsjubilantjunkyard.com/tutorial/rpg-style-movement-in-gbdk/ +void update_two_frame_counter(void) +{ + two_frame_counter += 1; + two_frame_real_value = two_frame_counter >> 3; + + // printf("%d\n", two_frame_counter); + // Stop & reset if the value is over 2 + if (two_frame_real_value >= 2) + { + two_frame_real_value = 0; + two_frame_counter = 0; + } +} + +//! Switch metasprite on certain frames. Could be heavily improved to take props for actor->spriteFrames and more +//! Should be called in some UpdateActor(&actor) Function +void animate_actor(Actor *actor, int8_t two_frame_counter) +{ + if (actor->is_moving) + { + if (two_frame_counter == 3) + { + actor->metasprite = submarine_metasprite; + } + + if (two_frame_counter == 9) + { + actor->metasprite = submarine_metasprite2; + } + } + else + { + actor->metasprite = submarine_metasprite; + move_actor(actor, actor->x, actor->y); // Necessary to trigger the metasprite change + } +} + +//! Die HUD Funktion muss ich reparieren, damit die immer in der Lage ist, die richtigen Tiles anzuzeigen +void show_hud(void) +{ + // Load tiles to the window layer + set_win_tiles(0, 0, 20, 1, hud); + + // Move the window layer down to the last tile row. + move_win(7, 136); + SHOW_WIN; +} + +//! This has to be refactored! A function with fixed values makes little sense. +void shiftBGTiles(void) +{ +#define VRAM_OFFSET 48 // Change this to your desired offset + + int map_size = 20 * 18; // Get the size of the map array + + for (int i = 0; i < map_size; i++) + { + underwater_map[i] += VRAM_OFFSET; + } +} + +void init(void) +{ + + // shiftBGTiles(); + + // Load HUD tiles + // set_bkg_data(0, 48, alphabet); + // Load background tiles after HUD tiles + // set_bkg_data(48, 40, underwater_tiles); + + // Use the 'blankScreen' array to write background tiles starting at 0,0 (tile positions) + // and for 20 tiles in width and 18 tiles in height + // set_bkg_tiles(0, 0, 20, 18, blankScreen); // Setting the first tile of alphabet to blank would be more efficient. + + // set_bkg_tiles(0, 0, 20, 18, underwater_map); + + set_bkg_data(0, tileset_TILE_COUNT, tileset_tiles); + + set_bkg_tiles(0, 0, TILEMAP_WIDTH_IN_TILES, TILEMAP_HEIGHT_IN_TILES, tilemap_map); + + // Fill tileset bank 0 with 4 actor tiles + set_sprite_data(0, 8, submarine_tileset); + + //! Prüfen, welche variables für das metasprite überhaupt noch benötigt werden + // Setup player actor + setup_actor( + // player + &submarine, + // Sprite ID: 0 + 0, + // 2x2 meta-sprite + 2, 2, + // Tiles start at 0 + 0, + // Total animated frames + 4, + // Set is_facing_right bool + TRUE, + // pointer to the tilemap + submarine_tilemap, + // pointer to the metasprite + submarine_metasprite); + + // MoveCharacter(&submarine, 80, 90); + + // Show the HUD + // show_hud(); + + SHOW_BKG; + SHOW_SPRITES; + // SPRITES_8x16; + DISPLAY_ON; + + // move_metasprite_ex(submarine_metasprite, 0, 0, 0, 80, 80); +} + +void main(void) +{ + + init(); + + // Main loop + while (1) + { + + update_two_frame_counter(); + animate_actor(&submarine, two_frame_counter); + + // Move the actor with the joypad + move_actor_with_joypad(&submarine); + // joypad_input(&submarine); + + // Wait for next frame + wait_vbl_done(); + + // Done processing, yield CPU and wait for start of next frame + vsync(); + } +} \ No newline at end of file