git.y1.nz

gbdk-2020

GameBoy Development Kit
download: https://git.y1.nz/archives/gbdk.tar.gz
README | Files | Log | Refs | LICENSE

commit 8ae764d236b1507dbcca48372e3bc52a44ad4f63
parent 69da267eb53fb46c94213a374aee499cae2f6136
Author: Larold <laroldsjubilantjunkyard@gmail.com>
Date:   Wed,  8 May 2024 09:42:42 -0400

Platformer template (#627)

* platformer template.
3 levels.
First two levels share a tileset
The third level has a different tileset
Mario can have variable jump height
Mario has a turn animation when changing directions
Collision against the background tilemap

Diffstat:
M.gitignore1+
Agbdk-lib/examples/cross-platform/platformer_template/Makefile128+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Agbdk-lib/examples/cross-platform/platformer_template/Makefile.targets56++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Agbdk-lib/examples/cross-platform/platformer_template/Readme.md50++++++++++++++++++++++++++++++++++++++++++++++++++
Agbdk-lib/examples/cross-platform/platformer_template/res/graphics/map-tileset1.png0
Agbdk-lib/examples/cross-platform/platformer_template/res/graphics/map-tileset2.png0
Agbdk-lib/examples/cross-platform/platformer_template/res/graphics/next-level.png0
Agbdk-lib/examples/cross-platform/platformer_template/res/graphics/player-character-gbapduck-sprites.png0
Agbdk-lib/examples/cross-platform/platformer_template/res/graphics/player-character-gbc-sprites.png0
Agbdk-lib/examples/cross-platform/platformer_template/res/graphics/player-character-ggsms-sprites.png0
Agbdk-lib/examples/cross-platform/platformer_template/res/graphics/player-character-nes-sprites.png0
Agbdk-lib/examples/cross-platform/platformer_template/res/graphics/title-screen.png0
Agbdk-lib/examples/cross-platform/platformer_template/res/graphics/world1-area1.png0
Agbdk-lib/examples/cross-platform/platformer_template/res/graphics/world1-area1.tmx41+++++++++++++++++++++++++++++++++++++++++
Agbdk-lib/examples/cross-platform/platformer_template/res/graphics/world1-area2.png0
Agbdk-lib/examples/cross-platform/platformer_template/res/graphics/world1-area2.tmx41+++++++++++++++++++++++++++++++++++++++++
Agbdk-lib/examples/cross-platform/platformer_template/res/graphics/world1-tileset.png0
Agbdk-lib/examples/cross-platform/platformer_template/res/graphics/world1-tileset.tsx4++++
Agbdk-lib/examples/cross-platform/platformer_template/res/graphics/world2-area1.png0
Agbdk-lib/examples/cross-platform/platformer_template/res/graphics/world2-area1.tmx40++++++++++++++++++++++++++++++++++++++++
Agbdk-lib/examples/cross-platform/platformer_template/res/graphics/world2-tileset.png0
Agbdk-lib/examples/cross-platform/platformer_template/res/graphics/world2-tileset.tsx4++++
Agbdk-lib/examples/cross-platform/platformer_template/src/camera.c83+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Agbdk-lib/examples/cross-platform/platformer_template/src/camera.h14++++++++++++++
Agbdk-lib/examples/cross-platform/platformer_template/src/common.c68++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Agbdk-lib/examples/cross-platform/platformer_template/src/common.h13+++++++++++++
Agbdk-lib/examples/cross-platform/platformer_template/src/level.c166+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Agbdk-lib/examples/cross-platform/platformer_template/src/level.h21+++++++++++++++++++++
Agbdk-lib/examples/cross-platform/platformer_template/src/main.c89+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Agbdk-lib/examples/cross-platform/platformer_template/src/player.c363+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Agbdk-lib/examples/cross-platform/platformer_template/src/player.h12++++++++++++
31 files changed, 1194 insertions(+), 0 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -65,6 +65,7 @@ gbdk-support/png2asset/png2asset gbdk-support/png2asset/testing/out/* gbdk-support/makebin/makebin gbdk-support/makecom/makecom + gbdk-support/png2hicolorgb/png2hicolorgb gbdk-support/romusage/romusage as/bin diff --git a/gbdk-lib/examples/cross-platform/platformer_template/Makefile b/gbdk-lib/examples/cross-platform/platformer_template/Makefile @@ -0,0 +1,128 @@ +# +# 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/" +ifndef GBDK_HOME + GBDK_HOME = ../../../ +endif + + +PNG2ASSET = $(GBDK_HOME)bin/png2asset +LCC = $(GBDK_HOME)bin/lcc + +# Set platforms to build here, spaced separated. (These are in the separate Makefile.targets) +# They can also be built/cleaned individually: "make gg" and "make gg-clean" +# Possible are: gb gbc pocket megaduck sms gg +TARGETS=gb pocket megaduck sms gg nes + +# You can set flags for LCC here +# For example, you can uncomment the line below to turn on debug output +# LCCFLAGS = -debug + +# You can set the name of the .gb ROM file here +PROJECTNAME = platformer_template + +SRCDIR = src +DISTDIR = dist +OBJDIR = obj/$(EXT) +RESDIR = res +GENDIR = gen/$(EXT)/src +BINDIR = build/$(EXT) +MKDIRS = $(GENDIR) $(OBJDIR) $(BINDIR) # See bottom of Makefile for directory auto-creation +BINS = $(OBJDIR)/$(PROJECTNAME).$(EXT) +CSOURCES = $(foreach dir,$(SRCDIR),$(notdir $(wildcard $(dir)/*.c))) +GENSOURCES = $(foreach dir,$(GENDIR), $(wildcard $(dir)/*.c)) +ASMSOURCES = $(foreach dir,$(SRCDIR),$(notdir $(wildcard $(dir)/*.s))) +OBJS = $(CSOURCES:%.c=$(OBJDIR)/%.o) $(ASMSOURCES:%.s=$(OBJDIR)/%.o) + +LCCFLAGS += -Wl-j -Wm-yoA -Wm-ya4 -Wb-ext=.rel $(LCCFLAGS_$(EXT)) # This adds the current platform specific LCC Flags + + +# Configure platform specific LCC flags here: +LCCFLAGS_gb = -Wm-ys -Wl-yt0x1B -autobank # Set an MBC for banking (1B-ROM+MBC5+RAM+BATT) +LCCFLAGS_pocket = -Wm-ys -Wl-yt0x1B -autobank # Usually the same as required for .gb +LCCFLAGS_duck = -Wm-ys -Wl-yt0x1B -autobank # Usually the same as required for .gb +LCCFLAGS_gbc = -Wm-ys -Wl-yt0x1B -Wm-yc -autobank # Same as .gb with: -Wm-yc (gb & gbc) or Wm-yC (gbc exclusive) +LCCFLAGS_sms = -Wm-ys -Wl-yt0x1B -autobank +LCCFLAGS_gg = -Wm-ys -Wl-yt0x1B -autobank +LCCFLAGS_nes = -Wm-ys -Wl-yt0x1B -autobank + +all: $(TARGETS) + +compile.bat: Makefile + @echo "REM Automatically generated from Makefile" > compile.bat + @make -sn | sed y/\\//\\\\/ | grep -v make >> compile.bat + + +# png2asset settings for backgrounds +PNG2ASSET_BKG_SETTINGS_gg=-pack_mode sms -bpp 4 +PNG2ASSET_BKG_SETTINGS_sms=-pack_mode sms -bpp 4 +PNG2ASSET_BKG_SETTINGS_nes=-noflip -bpp 2 -pack_mode nes +PNG2ASSET_BKG_SETTINGS_gb= +PNG2ASSET_BKG_SETTINGS_gbc= +PNG2ASSET_BKG_SETTINGS_duck= +PNG2ASSET_BKG_SETTINGS_pocket= + +# png2asset settings for sprites +PNG2ASSET_SPRITE_SETTINGS_gg=-noflip -pack_mode sms -bpp 4 +PNG2ASSET_SPRITE_SETTINGS_sms=-noflip -pack_mode sms -bpp 4 +PNG2ASSET_SPRITE_SETTINGS_nes= +PNG2ASSET_SPRITE_SETTINGS_gb= +PNG2ASSET_SPRITE_SETTINGS_gbc= +PNG2ASSET_SPRITE_SETTINGS_duck= +PNG2ASSET_SPRITE_SETTINGS_pocket= + + + +png2asset: + $(PNG2ASSET) res/graphics/player-character-$(SPRITES)-sprites.png -c $(GENDIR)/PlayerCharacterSprites.c -px 12 -py 6 -spr8x16 -keep_palette_order -sw 24 -sh 32 $(PNG2ASSET_SPRITE_SETTINGS_$(EXT)) -b 255 + $(PNG2ASSET) res/graphics/world1-tileset.png -c $(GENDIR)/World1Tileset.c -keep_palette_order -noflip -map -keep_duplicate_tiles $(PNG2ASSET_BKG_SETTINGS_$(EXT)) -b 255 + $(PNG2ASSET) res/graphics/world2-tileset.png -c $(GENDIR)/World2Tileset.c -keep_palette_order -noflip -map -keep_duplicate_tiles $(PNG2ASSET_BKG_SETTINGS_$(EXT)) -b 255 + $(PNG2ASSET) res/graphics/world1-area1.png -c $(GENDIR)/World1Area1.c -noflip -map -maps_only -source_tileset res/graphics/world1-tileset.png $(PNG2ASSET_BKG_SETTINGS_$(EXT)) -b 255 + $(PNG2ASSET) res/graphics/world1-area2.png -c $(GENDIR)/World1Area2.c -noflip -map -maps_only -source_tileset res/graphics/world1-tileset.png $(PNG2ASSET_BKG_SETTINGS_$(EXT)) -b 255 + $(PNG2ASSET) res/graphics/world2-area1.png -c $(GENDIR)/World2Area1.c -noflip -map -maps_only -source_tileset res/graphics/world2-tileset.png $(PNG2ASSET_BKG_SETTINGS_$(EXT)) -b 255 + $(PNG2ASSET) res/graphics/title-screen.png -c $(GENDIR)/TitleScreen.c -noflip -map $(PNG2ASSET_BKG_SETTINGS_$(EXT)) -b 255 + $(PNG2ASSET) res/graphics/next-level.png -c $(GENDIR)/NextLevel.c -noflip -map $(PNG2ASSET_BKG_SETTINGS_$(EXT)) -b 255 + + +# Compile .c files in "src/" to .o object files +$(OBJDIR)/%.o: $(SRCDIR)/%.c + $(LCC) $(LCCFLAGS) $(CFLAGS) -I$(GENDIR) -Ires -c -o $@ $< + +# Compile .s assembly files in "src/" to .o object files +$(OBJDIR)/%.o: $(SRCDIR)/%.s + $(LCC) $(LCCFLAGS) $(CFLAGS) -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) $(CFLAGS) -S -o $@ $< + +# Link the compiled object files into a .gb ROM file +$(BINS): $(OBJS) + $(LCC) $(LCCFLAGS) $(CFLAGS) -I$(GENDIR) -o $(BINDIR)/$(PROJECTNAME).$(EXT) $(OBJS) $(GENSOURCES) + + +prepare: + mkdir -p $(OBJDIR) + mkdir -p $(DISTDIR) + mkdir -p $(GENDIR) + +clean: + @echo Cleaning + @for target in $(TARGETS); do \ + $(MAKE) $$target-clean; \ + done + +# Include available build targets +include Makefile.targets + + +# create necessary directories after Makefile is parsed but before build +# info prevents the command from being pasted into the makefile +ifneq ($(strip $(EXT)),) # Only make the directories if EXT has been set by a target +$(info $(shell mkdir -p $(MKDIRS))) +endif diff --git a/gbdk-lib/examples/cross-platform/platformer_template/Makefile.targets b/gbdk-lib/examples/cross-platform/platformer_template/Makefile.targets @@ -0,0 +1,56 @@ + +# Platform specific flags for compiling (only populate if they're both present) +ifneq ($(strip $(PORT)),) +ifneq ($(strip $(PLAT)),) +CFLAGS += -m$(PORT):$(PLAT) +endif +endif + +# Called by the individual targets below to build a ROM +build-target: png2asset $(BINS) + +clean-target: + rm -rf $(OBJDIR) + rm -rf $(DISTDIR) + rm -rf $(GENDIR) + +gb-clean: + ${MAKE} clean-target EXT=gb +gb: + ${MAKE} build-target PORT=sm83 PLAT=gb EXT=gb SPRITES=gbapduck + + +gbc-clean: + ${MAKE} clean-target EXT=gbc +gbc: + ${MAKE} build-target PORT=sm83 PLAT=gb EXT=gbc SPRITES=gbc + + +pocket-clean: + ${MAKE} clean-target EXT=pocket +pocket: + ${MAKE} build-target PORT=sm83 PLAT=ap EXT=pocket SPRITES=gbapduck + + +megaduck-clean: + ${MAKE} clean-target EXT=duck +megaduck: + ${MAKE} build-target PORT=sm83 PLAT=duck EXT=duck SPRITES=gbapduck + + +sms-clean: + ${MAKE} clean-target EXT=sms +sms: + ${MAKE} build-target PORT=z80 PLAT=sms EXT=sms SPRITES=ggsms + + +gg-clean: + ${MAKE} clean-target EXT=gg +gg: + ${MAKE} build-target PORT=z80 PLAT=gg EXT=gg SPRITES=ggsms + + +nes-clean: + ${MAKE} clean-target EXT=nes +nes: + ${MAKE} build-target PORT=mos6502 PLAT=nes EXT=nes SPRITES=nes diff --git a/gbdk-lib/examples/cross-platform/platformer_template/Readme.md b/gbdk-lib/examples/cross-platform/platformer_template/Readme.md @@ -0,0 +1,49 @@ +# GBDK-2020 Platformer Template + +A Basic "Mario-Style" Platformer Template + +The Player can walk, run, and jump on the background of 3 different areas. The Player Character is rendered using metasprites. + +Controls: + - D-pad left/right: Walk Horizontally + - D-pad up: Jump (hold to increase jump height) + - A: Jump (hold to increase jump height) + - B: Sprint + +The "res" folder contains some PNGs that are converted to .c and .h files using [png2asset](https://gbdk-2020.github.io/gbdk-2020/docs/api/docs_toolchain_settings.html#png2asset-settings). + +The level.c file defines a function for changing the level. The code expects all non-solid tiles be first in the tilesets. The amount of non-solid tiles should be specified in "currentLevelNonSolidTileCount" when changing level. + +## How to add levels + +Create a tileset using your favorite graphics editor. Make sure: +- Each tile has no more than 4 colors (For games not targeting Game Boy Family consoles, see the GBDK-2020 documentation) +- You don't have more than 256 unique tiles +- (when scanning per-tile, left-to-right.) **ALL** solid tiles come **BEFORE** non-solid tiles. (The number of solid tiles will later be used in level.c) + +In the makefile, Update the "png2asset" target to convert your tileset to .c and .h files. Make sure: +- For simplicity, you use the following params: `-noflip -map -tileset_only -keep_duplicate_tiles` (This ensures easy compatibility with your tilemap editor at the cost of some VRAM space.) + +> $(PNG2ASSET) res\world1-tileset.png -c res\World1Tileset.c -noflip -map -tileset_only -keep_duplicate_tiles + +You can use your tileset in a tilemap editor like [Tiled](https://www.mapeditor.org/) or [LDtk](https://ldtk.io/). +Make sure you export the level as an **PNG** image. +After exporting the level as an image, use png2asset to generate tilemap .c and .h files from that PNG. Make sure: +- For simplicity use the ` -noflip -map -maps_only` arguments. (Again, at the cost of VRAM space, this makes for easy compatibility with your tilemap editor's output) +- Specify the source tileset using the `-source_tileset` argument +- Make sure the level is at least 20 tiles wide, and 18 tiles high. (For games not targeting Game Boy Family consoles, see the GBDK-2020 documentation) + +> $(PNG2ASSET) res\world1-area1.png -c res\World1Area1.c -noflip -map -maps_only -source_tileset res\world1-tileset.png + +Include the generated .h files in the level.h +Add new levels to the switch statement in level.c's "SetupCurrentLevel" function. + +> This template initially uses the modulus operator to cycle between 3 levels. Change the '3' to however many elements you have. + +Make sure to set their level tile data into vram. + +> If you're tilemap has more tiles than your tileset, you will encounter some display issues. This is one reason for the arguments previously mentioned "for simplicity". Just Make sure your tilemap editor program doesn't use more than one tileset. + +Make sure to set the number of solid tiles. These should always come first. This should include duplicates and flipped tiles. + +> As an optimizatation you could remove adjust your tileset, tilemap, and png2asset to handle duplicates/tile-flipping, but you would loose some DMG compatibility + diff --git a/gbdk-lib/examples/cross-platform/platformer_template/res/graphics/map-tileset1.png b/gbdk-lib/examples/cross-platform/platformer_template/res/graphics/map-tileset1.png Binary files differ. diff --git a/gbdk-lib/examples/cross-platform/platformer_template/res/graphics/map-tileset2.png b/gbdk-lib/examples/cross-platform/platformer_template/res/graphics/map-tileset2.png Binary files differ. diff --git a/gbdk-lib/examples/cross-platform/platformer_template/res/graphics/next-level.png b/gbdk-lib/examples/cross-platform/platformer_template/res/graphics/next-level.png Binary files differ. diff --git a/gbdk-lib/examples/cross-platform/platformer_template/res/graphics/player-character-gbapduck-sprites.png b/gbdk-lib/examples/cross-platform/platformer_template/res/graphics/player-character-gbapduck-sprites.png Binary files differ. diff --git a/gbdk-lib/examples/cross-platform/platformer_template/res/graphics/player-character-gbc-sprites.png b/gbdk-lib/examples/cross-platform/platformer_template/res/graphics/player-character-gbc-sprites.png Binary files differ. diff --git a/gbdk-lib/examples/cross-platform/platformer_template/res/graphics/player-character-ggsms-sprites.png b/gbdk-lib/examples/cross-platform/platformer_template/res/graphics/player-character-ggsms-sprites.png Binary files differ. diff --git a/gbdk-lib/examples/cross-platform/platformer_template/res/graphics/player-character-nes-sprites.png b/gbdk-lib/examples/cross-platform/platformer_template/res/graphics/player-character-nes-sprites.png Binary files differ. diff --git a/gbdk-lib/examples/cross-platform/platformer_template/res/graphics/title-screen.png b/gbdk-lib/examples/cross-platform/platformer_template/res/graphics/title-screen.png Binary files differ. diff --git a/gbdk-lib/examples/cross-platform/platformer_template/res/graphics/world1-area1.png b/gbdk-lib/examples/cross-platform/platformer_template/res/graphics/world1-area1.png Binary files differ. diff --git a/gbdk-lib/examples/cross-platform/platformer_template/res/graphics/world1-area1.tmx b/gbdk-lib/examples/cross-platform/platformer_template/res/graphics/world1-area1.tmx @@ -0,0 +1,41 @@ +<?xml version="1.0" encoding="UTF-8"?> +<map version="1.8" tiledversion="1.8.2" orientation="orthogonal" renderorder="right-down" width="60" height="32" tilewidth="8" tileheight="8" infinite="0" nextlayerid="3" nextobjectid="1"> + <tileset firstgid="1" source="world1-tileset.tsx"/> + <layer id="1" name="Tile Layer 1" width="60" height="32"> + <data encoding="csv"> +18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18, +18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18, +18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18, +18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18, +18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18, +18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18, +18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18, +18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,7,8,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18, +18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,15,16,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18, +18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,7,8,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18, +18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,15,16,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18, +18,18,18,18,18,18,18,18,18,7,8,7,8,7,8,7,8,18,18,18,18,18,7,8,7,8,7,8,7,8,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18, +18,18,18,18,18,18,18,18,18,15,16,15,16,15,16,15,16,18,18,18,18,18,15,16,15,16,15,16,15,16,18,18,18,18,18,18,18,18,18,7,8,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18, +18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,15,16,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18, +18,18,18,18,21,22,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,7,8,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18, +18,18,18,18,19,20,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,15,16,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17, +1,2,3,4,5,2,3,4,5,2,3,4,5,2,3,4,5,2,3,4,5,2,3,4,5,2,3,4,5,2,3,4,5,2,3,4,5,2,3,4,6,23,24,23,24,23,24,23,24,23,24,23,24,23,24,23,24,23,24,23, +9,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,14,25,26,25,26,25,26,25,26,25,26,25,26,25,26,25,26,25,26,25, +9,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,14,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29, +9,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,14,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29, +9,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,14,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29, +9,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,14,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29, +9,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,14,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29, +9,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,14,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29, +9,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,14,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29, +9,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,14,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29, +9,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,14,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29, +9,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,14,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29, +9,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,14,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29, +9,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,14,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29, +9,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,14,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29, +9,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,14,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29,29 +</data> + </layer> + <objectgroup id="2" name="Object Layer 1"/> +</map> diff --git a/gbdk-lib/examples/cross-platform/platformer_template/res/graphics/world1-area2.png b/gbdk-lib/examples/cross-platform/platformer_template/res/graphics/world1-area2.png Binary files differ. diff --git a/gbdk-lib/examples/cross-platform/platformer_template/res/graphics/world1-area2.tmx b/gbdk-lib/examples/cross-platform/platformer_template/res/graphics/world1-area2.tmx @@ -0,0 +1,41 @@ +<?xml version="1.0" encoding="UTF-8"?> +<map version="1.8" tiledversion="1.8.2" orientation="orthogonal" renderorder="right-down" width="60" height="32" tilewidth="8" tileheight="8" infinite="0" nextlayerid="3" nextobjectid="1"> + <tileset firstgid="1" source="world1-tileset.tsx"/> + <layer id="1" name="Tile Layer 1" width="60" height="32"> + <data encoding="csv"> +18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18, +18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18, +18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18, +18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18, +18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18, +18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18, +18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18, +18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18, +18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,7,8,7,8,18,18,18,18,18, +18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,15,16,15,16,18,18,18,18,18, +18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,7,8,7,8,7,8,7,8,7,8,18,18,18,18,18, +18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,15,16,15,16,15,16,15,16,15,16,18,18,18,18,18, +18,18,18,18,18,18,18,18,18,18,18,18,18,18,1,3,2,3,5,6,7,8,7,8,7,8,7,8,7,8,7,8,7,8,18,18,18,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,18,18,18,18,18, +18,18,18,18,18,18,18,18,18,18,18,18,18,18,9,11,10,11,13,14,15,16,15,16,15,16,15,16,15,16,15,16,15,16,18,18,18,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,15,16,18,18,18,18,18, +18,18,18,18,21,22,18,18,18,18,18,1,2,3,11,10,10,11,13,14,18,18,18,18,18,18,18,18,18,18,18,18,7,8,18,18,18,7,8,18,18,18,18,18,18,18,18,18,18,18,18,18,18,7,8,18,18,18,18,18, +18,18,18,18,19,20,18,18,18,18,18,9,10,11,10,11,12,13,13,14,18,18,18,18,18,18,18,18,18,18,18,18,15,16,18,18,18,15,16,18,18,18,18,18,18,18,18,18,18,18,18,18,18,15,16,18,18,18,18,18, +1,2,3,4,5,2,3,4,5,2,3,10,10,11,10,10,10,11,13,10,5,2,3,4,5,2,3,4,5,2,3,4,5,2,3,4,5,2,3,4,6,23,24,23,24,23,24,23,24,23,24,23,24,1,2,3,4,5,2,6, +9,10,11,12,13,10,11,12,13,10,11,10,11,12,13,13,13,13,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,14,25,26,25,26,25,26,25,26,25,26,25,26,9,10,11,12,13,10,14, +9,10,11,12,13,10,11,12,13,10,11,10,11,12,13,13,13,13,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,14,29,29,29,29,29,29,29,29,29,29,29,29,9,10,11,12,13,10,14, +9,10,11,12,13,10,11,12,13,10,11,10,11,12,13,13,13,13,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,14,29,29,29,29,29,29,29,29,29,29,29,29,9,10,11,12,13,10,14, +9,10,11,12,13,10,11,12,13,10,11,10,11,12,13,13,13,13,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,14,29,29,29,29,29,29,29,29,29,29,29,29,9,10,11,12,13,10,14, +9,10,11,12,13,10,11,12,13,10,11,10,11,12,13,13,13,13,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,14,29,29,29,29,29,29,29,29,29,29,29,29,9,10,11,12,13,10,14, +9,10,11,12,13,10,11,12,13,10,11,10,11,12,13,13,13,13,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,14,29,29,29,29,29,29,29,29,29,29,29,29,9,10,11,12,13,10,14, +9,10,11,12,13,10,11,12,13,10,11,10,11,12,13,13,13,13,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,14,29,29,29,29,29,29,29,29,29,29,29,29,9,10,11,12,13,10,14, +9,10,11,12,13,10,11,12,13,10,11,10,11,12,13,13,13,13,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,14,29,29,29,29,29,29,29,29,29,29,29,29,9,10,11,12,13,10,14, +9,10,11,12,13,10,11,12,13,10,11,10,11,12,13,13,13,13,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,14,29,29,29,29,29,29,29,29,29,29,29,29,9,10,11,12,13,10,14, +9,10,11,12,13,10,11,12,13,10,11,10,11,12,13,13,13,13,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,14,29,29,29,29,29,29,29,29,29,29,29,29,9,10,11,12,13,10,14, +9,10,11,12,13,10,11,12,13,10,11,10,11,12,13,13,13,13,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,14,29,29,29,29,29,29,29,29,29,29,29,29,9,10,11,12,13,10,14, +9,10,11,12,13,10,11,12,13,10,11,10,11,12,13,13,13,13,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,14,29,29,29,29,29,29,29,29,29,29,29,29,9,10,11,12,13,10,14, +9,10,11,12,13,10,11,12,13,10,11,10,11,12,13,13,13,13,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,14,29,29,29,29,29,29,29,29,29,29,29,29,9,10,11,12,13,10,14, +9,10,11,12,13,10,11,12,13,10,11,10,11,12,13,13,13,13,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,14,29,29,29,29,29,29,29,29,29,29,29,29,9,10,11,12,13,10,14, +9,10,11,12,13,10,11,12,13,10,11,10,11,12,13,13,13,13,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,13,10,11,12,14,29,29,29,29,29,29,29,29,29,29,29,29,9,10,11,12,13,10,14 +</data> + </layer> + <objectgroup id="2" name="Object Layer 1"/> +</map> diff --git a/gbdk-lib/examples/cross-platform/platformer_template/res/graphics/world1-tileset.png b/gbdk-lib/examples/cross-platform/platformer_template/res/graphics/world1-tileset.png Binary files differ. diff --git a/gbdk-lib/examples/cross-platform/platformer_template/res/graphics/world1-tileset.tsx b/gbdk-lib/examples/cross-platform/platformer_template/res/graphics/world1-tileset.tsx @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="UTF-8"?> +<tileset version="1.8" tiledversion="1.8.2" name="world1" tilewidth="8" tileheight="8" tilecount="160" columns="8"> + <image source="world1-tileset.png" trans="ff00ff" width="64" height="32"/> +</tileset> diff --git a/gbdk-lib/examples/cross-platform/platformer_template/res/graphics/world2-area1.png b/gbdk-lib/examples/cross-platform/platformer_template/res/graphics/world2-area1.png Binary files differ. diff --git a/gbdk-lib/examples/cross-platform/platformer_template/res/graphics/world2-area1.tmx b/gbdk-lib/examples/cross-platform/platformer_template/res/graphics/world2-area1.tmx @@ -0,0 +1,40 @@ +<?xml version="1.0" encoding="UTF-8"?> +<map version="1.8" tiledversion="1.8.2" orientation="orthogonal" renderorder="right-down" width="60" height="32" tilewidth="8" tileheight="8" infinite="0" nextlayerid="2" nextobjectid="1"> + <tileset firstgid="1" source="world2-tileset.tsx"/> + <layer id="1" name="Tile Layer 1" width="60" height="32"> + <data encoding="csv"> +69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69, +69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69, +69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69, +69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69, +69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69, +69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69, +69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69, +69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69, +69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69, +69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69, +69,69,69,69,69,69,69,69,69,69,69,57,58,59,60,61,62,69,69,69,57,58,59,60,61,62,69,69,69,69,69,69,69,69,69,69,69,69,69,57,58,59,60,61,62,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69, +69,69,69,69,69,69,69,69,69,69,69,63,64,65,66,67,68,69,69,69,63,64,65,66,67,68,69,69,69,69,69,69,69,69,69,69,69,69,69,63,64,65,66,67,68,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69, +69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,1,2,9,10,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69, +69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,15,16,23,24,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69, +69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,11,12,13,14,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69, +69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,25,26,27,28,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69,69, +1,2,3,4,5,6,7,8,3,4,5,6,7,8,3,4,5,6,7,8,3,4,5,6,7,8,3,4,5,6,9,10,11,12,13,14,1,2,5,6,7,8,3,4,5,6,7,8,3,4,5,6,7,8,3,4,5,6,9,10, +15,16,17,18,19,20,21,22,17,18,19,20,21,22,17,18,19,20,21,22,17,18,19,20,21,22,17,18,19,20,23,24,25,26,27,28,15,16,19,20,21,22,17,18,19,20,21,22,17,18,19,20,21,22,17,18,19,20,23,24, +15,16,17,18,19,20,21,22,17,18,19,20,21,22,17,18,19,20,21,22,17,18,19,20,21,22,17,18,19,20,23,24,25,26,27,28,15,16,19,20,21,22,17,18,19,20,21,22,17,18,19,20,21,22,17,18,19,20,23,24, +15,16,17,18,19,20,21,22,17,18,19,20,21,22,17,18,19,20,21,22,17,18,19,20,21,22,17,18,19,20,23,24,25,26,27,28,15,16,19,20,21,22,17,18,19,20,21,22,17,18,19,20,21,22,17,18,19,20,23,24, +15,16,17,18,19,20,21,22,17,18,19,20,21,22,17,18,19,20,21,22,17,18,19,20,21,22,17,18,19,20,23,24,25,26,27,28,15,16,19,20,21,22,17,18,19,20,21,22,17,18,19,20,21,22,17,18,19,20,23,24, +15,16,17,18,19,20,21,22,17,18,19,20,21,22,17,18,19,20,21,22,17,18,19,20,21,22,17,18,19,20,23,24,25,26,27,28,15,16,19,20,21,22,17,18,19,20,21,22,17,18,19,20,21,22,17,18,19,20,23,24, +15,16,17,18,19,20,21,22,17,18,19,20,21,22,17,18,19,20,21,22,17,18,19,20,21,22,17,18,19,20,23,24,25,26,27,28,15,16,19,20,21,22,17,18,19,20,21,22,17,18,19,20,21,22,17,18,19,20,23,24, +15,16,17,18,19,20,21,22,17,18,19,20,21,22,17,18,19,20,21,22,17,18,19,20,21,22,17,18,19,20,23,24,25,26,27,28,15,16,19,20,21,22,17,18,19,20,21,22,17,18,19,20,21,22,17,18,19,20,23,24, +15,16,17,18,19,20,21,22,17,18,19,20,21,22,17,18,19,20,21,22,17,18,19,20,21,22,17,18,19,20,23,24,25,26,27,28,15,16,19,20,21,22,17,18,19,20,21,22,17,18,19,20,21,22,17,18,19,20,23,24, +15,16,17,18,19,20,21,22,17,18,19,20,21,22,17,18,19,20,21,22,17,18,19,20,21,22,17,18,19,20,23,24,25,26,27,28,15,16,19,20,21,22,17,18,19,20,21,22,17,18,19,20,21,22,17,18,19,20,23,24, +15,16,17,18,19,20,21,22,17,18,19,20,21,22,17,18,19,20,21,22,17,18,19,20,21,22,17,18,19,20,23,24,25,26,27,28,15,16,19,20,21,22,17,18,19,20,21,22,17,18,19,20,21,22,17,18,19,20,23,24, +15,16,17,18,19,20,21,22,17,18,19,20,21,22,17,18,19,20,21,22,17,18,19,20,21,22,17,18,19,20,23,24,25,26,27,28,15,16,19,20,21,22,17,18,19,20,21,22,17,18,19,20,21,22,17,18,19,20,23,24, +15,16,17,18,19,20,21,22,17,18,19,20,21,22,17,18,19,20,21,22,17,18,19,20,21,22,17,18,19,20,23,24,25,26,27,28,15,16,19,20,21,22,17,18,19,20,21,22,17,18,19,20,21,22,17,18,19,20,23,24, +15,16,17,18,19,20,21,22,17,18,19,20,21,22,17,18,19,20,21,22,17,18,19,20,21,22,17,18,19,20,23,24,25,26,27,28,15,16,19,20,21,22,17,18,19,20,21,22,17,18,19,20,21,22,17,18,19,20,23,24, +15,16,17,18,19,20,21,22,17,18,19,20,21,22,17,18,19,20,21,22,17,18,19,20,21,22,17,18,19,20,23,24,25,26,27,28,15,16,19,20,21,22,17,18,19,20,21,22,17,18,19,20,21,22,17,18,19,20,23,24, +15,16,17,18,19,20,21,22,17,18,19,20,21,22,17,18,19,20,21,22,17,18,19,20,21,22,17,18,19,20,23,24,25,26,27,28,15,16,19,20,21,22,17,18,19,20,21,22,17,18,19,20,21,22,17,18,19,20,23,24 +</data> + </layer> +</map> diff --git a/gbdk-lib/examples/cross-platform/platformer_template/res/graphics/world2-tileset.png b/gbdk-lib/examples/cross-platform/platformer_template/res/graphics/world2-tileset.png Binary files differ. diff --git a/gbdk-lib/examples/cross-platform/platformer_template/res/graphics/world2-tileset.tsx b/gbdk-lib/examples/cross-platform/platformer_template/res/graphics/world2-tileset.tsx @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="UTF-8"?> +<tileset version="1.8" tiledversion="1.8.2" name="world2-tileset" tilewidth="8" tileheight="8" tilecount="112" columns="14"> + <image source="world2-tileset.png" trans="ff00ff" width="112" height="64"/> +</tileset> diff --git a/gbdk-lib/examples/cross-platform/platformer_template/src/camera.c b/gbdk-lib/examples/cross-platform/platformer_template/src/camera.c @@ -0,0 +1,83 @@ +#pragma bank 255 + +#include <stdint.h> +#include <gbdk/platform.h> +#include "level.h" + +#define WRAP_SCROLL_Y(y) ((y) % DEVICE_SCREEN_PX_HEIGHT) + +#if defined(SEGA) + // For SMS, artifacts are already invisible as screen buffer size is larger than screen size + #define SCROLL_Y_OFFSET 0 +#elif defined(NINTENDO) + // For GB, artifacts are already invisible as screen buffer size is larger than screen size + #define SCROLL_Y_OFFSET 0 +#else + // For other systems assume height of 240 and adjust Y-scroll 4 pixels down to partly hide artifacts in NTSC overscan + #define SCROLL_Y_OFFSET 4 +#endif + + +#define MIN(A,B) ((A)<(B)?(A):(B)) + +// current and old positions of the camera in pixels +uint16_t camera_x, old_camera_x; +// current and old position of the map in tiles +uint8_t map_pos_x, old_map_pos_x; +// redraw flag, indicates that camera position was changed +uint8_t redraw; + +void SetCurrentLevelSubmap(uint8_t x, uint8_t y, uint8_t w, uint8_t h) NONBANKED{ + + uint8_t _previous_bank = CURRENT_BANK; + + SWITCH_ROM(currentAreaBank); + + set_bkg_submap(x,y,w, h, currentLevelMap, currentLevelWidthInTiles); + + SWITCH_ROM(_previous_bank); + +} + +inline uint8_t update_column_left(uint8_t map_pos_x) +{ +#if (DEVICE_SCREEN_BUFFER_WIDTH == DEVICE_SCREEN_WIDTH) + return map_pos_x + 1; +#else + return map_pos_x; +#endif +} + +inline uint8_t update_column_right(uint8_t map_pos_x) +{ + return map_pos_x + DEVICE_SCREEN_WIDTH; +} + +void UpdateCamera(void) BANKED { + + // update hardware scroll position + move_bkg(camera_x, 0); + + // left or right + map_pos_x = (uint8_t)(camera_x >> 3u); + if (map_pos_x != old_map_pos_x) { + if (camera_x < old_camera_x) { + SetCurrentLevelSubmap( + update_column_left(map_pos_x), + 0, + 1, + MIN(DEVICE_SCREEN_HEIGHT, currentLevelHeightInTiles )); + } else { + if ((currentLevelWidthInTiles - DEVICE_SCREEN_WIDTH) > map_pos_x) { + SetCurrentLevelSubmap( + update_column_right(map_pos_x), + 0, + 1, + MIN(DEVICE_SCREEN_HEIGHT, currentLevelHeightInTiles)); + } + } + old_map_pos_x = map_pos_x; + } + // set old camera position to current camera position + old_camera_x = camera_x; +} diff --git a/gbdk-lib/examples/cross-platform/platformer_template/src/camera.h b/gbdk-lib/examples/cross-platform/platformer_template/src/camera.h @@ -0,0 +1,13 @@ +#ifndef CAMERA_HEADER +#define CAMERA_HEADER + +#include <stdint.h> +#include <gbdk/platform.h> + +extern uint16_t camera_x, camera_y; + + +void UpdateCamera(void) BANKED; +void SetCurrentLevelSubmap(uint8_t x, uint8_t y, uint8_t w, uint8_t h) NONBANKED; + +#endif + diff --git a/gbdk-lib/examples/cross-platform/platformer_template/src/common.c b/gbdk-lib/examples/cross-platform/platformer_template/src/common.c @@ -0,0 +1,67 @@ + +#include <gbdk/platform.h> +#include <gbdk/metasprites.h> +#include <stdint.h> +#include "common.h" + +uint8_t joypadCurrent=0, joypadPrevious=0; + +void WaitForStartOrA(void){ + while(1){ + + // Get the joypad input + joypadPrevious = joypadCurrent; + joypadCurrent = joypad(); + + if((joypadCurrent & J_START) && !(joypadPrevious & J_START))break; + if((joypadCurrent & J_A) && !(joypadPrevious & J_A))break; + + vsync(); + + } +} + +void setBKGPalettes(uint8_t count, const palette_color_t *palettes) NONBANKED{ + // Set up color palettes + #if defined(SEGA) + //__WRITE_VDP_REG(VDP_R2, R2_MAP_0x3800); + //__WRITE_VDP_REG(VDP_R5, R5_SAT_0x3F00); + set_bkg_palette(0, count, palettes); + #elif defined(GAMEBOY) + if (_cpu == CGB_TYPE) { + set_bkg_palette(OAMF_CGB_PAL0, count, palettes); + } + #elif defined(NINTENDO_NES) + set_bkg_palette(0, count, palettes); + #endif +} + + +void ShowCentered(uint8_t width,uint8_t height,uint8_t bank, uint8_t* tileData, uint8_t tileCount, uint8_t* mapData, const palette_color_t* palettes) NONBANKED{ + + + DISPLAY_OFF; + + uint8_t _previous_bank = CURRENT_BANK; + + + // Hide any remainder sprites + hide_sprites_range(0,MAX_HARDWARE_SPRITES); + + move_bkg(0,0); + + // Make sure the graphic is centered on the screen + uint8_t titleRow = (DEVICE_SCREEN_HEIGHT-(height>>3))/2; + uint8_t titleColumn = (DEVICE_SCREEN_WIDTH-(width>>3))/2; + + SWITCH_ROM(bank); + + setBKGPalettes(1,palettes); + + set_native_tile_data(0,tileCount,tileData); + fill_bkg_rect(0,0,DEVICE_SCREEN_WIDTH,DEVICE_SCREEN_HEIGHT,0); + set_bkg_tiles(titleColumn,titleRow,width>>3,height>>3,mapData); + SWITCH_ROM(_previous_bank); + + DISPLAY_ON; +} + diff --git a/gbdk-lib/examples/cross-platform/platformer_template/src/common.h b/gbdk-lib/examples/cross-platform/platformer_template/src/common.h @@ -0,0 +1,12 @@ +#ifndef COMMON_HEADER +#define COMMON_HEADER + +#include <gbdk/platform.h> +#include <gbdk/metasprites.h> + +extern uint8_t joypadCurrent, joypadPrevious; + +void WaitForStartOrA(void); +void setBKGPalettes(uint8_t count, const palette_color_t *palettes) NONBANKED; +void ShowCentered(uint8_t widthInTiles,uint8_t heightInTiles,uint8_t bank, uint8_t* tileData, uint8_t tileCount, uint8_t* mapData, const palette_color_t* palettes) NONBANKED; +#endif + diff --git a/gbdk-lib/examples/cross-platform/platformer_template/src/level.c b/gbdk-lib/examples/cross-platform/platformer_template/src/level.c @@ -0,0 +1,166 @@ +#include <stdint.h> +#include <gbdk/platform.h> +#include "common.h" +#include "World1Area1.h" +#include "World1Area2.h" +#include "World2Area1.h" +#include "World1Tileset.h" +#include "World2Tileset.h" + +#define WORLD1_SOLID_TILE_COUNT 17 +#define WORLD2_SOLID_TILE_COUNT 68 + +BANKREF_EXTERN(World1Tileset) +BANKREF_EXTERN(World2Tileset) +BANKREF_EXTERN(World1Area1) +BANKREF_EXTERN(World1Area2) +BANKREF_EXTERN(World1Area1) + + +// Instead of directly referencing our map constants, camera and physica code will reference these which can be changed between levels +uint16_t currentLevelWidth; +uint16_t currentLevelWidthInTiles; +uint16_t currentLevelHeight; +uint16_t currentLevelHeightInTiles; +const uint8_t *currentLevelMap; +uint8_t currentLevelNonSolidTileCount; +uint8_t currentAreaBank; + + +// What is the current and next level we are on +// When they differ, we'll change levels +uint8_t currentLevel = 255; +uint8_t nextLevel = 0; + +/** + * @param worldX a (non-scaled) x position in the world + * @param worldY a (non-scaled) y position in the world + * @return uint8_t FALSE (0) if the tile is not solid, TRUE (1) if the tile is solid + */ +uint8_t IsTileSolid(uint16_t worldX,uint16_t worldY) NONBANKED{ + + uint8_t _previous_bank = CURRENT_BANK; + + SWITCH_ROM(currentAreaBank); + + // Get convert the world position to a column and row by dividing by 8 + uint16_t column = worldX>>3; + uint16_t row = worldY>>3; + + uint16_t worldMaxRow = currentLevelHeight>>3; + + // Our y coordinate and row are unsigned integers + // We'll check if the row is larger than the maxium + // if that is the case, the player's unsigned y position has wrapped around (instead of going into negative values) + if(row>worldMaxRow||column>=currentLevelWidthInTiles){ + + SWITCH_ROM(_previous_bank); + return TRUE; + } + + uint16_t index = column + row* currentLevelWidthInTiles; + + uint8_t tile = currentLevelMap[index]; + + SWITCH_ROM(_previous_bank); + + return tile<currentLevelNonSolidTileCount; +} + + + +void SetupCurrentLevel(void) NONBANKED{ + + DISPLAY_OFF; + + + + uint8_t _previous_bank = CURRENT_BANK; + + for(uint8_t i=0;i<DEVICE_SCREEN_BUFFER_WIDTH;i++){ + for(uint8_t j=0;j<DEVICE_SCREEN_BUFFER_HEIGHT;j++){ + set_attribute_xy(i,j,0); + } + } + + + // We only have 3 levels + // This will loop between them + switch(currentLevel % 3){ + case 0: + + + + // Switch to whichever bank our song is in + // Not neccessary if the song is in bank 0 + SWITCH_ROM(( BANK(World1Tileset))); + + set_native_tile_data(0,World1Tileset_TILE_COUNT,World1Tileset_tiles); + setBKGPalettes(World1Tileset_PALETTE_COUNT,World1Tileset_palettes); + + // Switch to whichever bank our song is in + // Not neccessary if the song is in bank 0 + SWITCH_ROM((currentAreaBank = BANK(World1Area1))); + + currentLevelNonSolidTileCount=WORLD1_SOLID_TILE_COUNT; + currentLevelWidth = World1Area1_WIDTH; + currentLevelHeight = World1Area1_HEIGHT; + currentLevelWidthInTiles = World1Area1_WIDTH>>3; + currentLevelHeightInTiles = World1Area1_HEIGHT>>3; + currentLevelMap= World1Area1_map; + + + break; + case 1: + + + // Switch to whichever bank our song is in + // Not neccessary if the song is in bank 0 + SWITCH_ROM((currentAreaBank = BANK(World1Tileset))); + + + set_native_tile_data(0,World1Tileset_TILE_COUNT,World1Tileset_tiles); + setBKGPalettes(World1Tileset_PALETTE_COUNT,World1Tileset_palettes); + + + // Switch to whichever bank our song is in + // Not neccessary if the song is in bank 0 + SWITCH_ROM((currentAreaBank = BANK(World1Area2))); + + currentLevelNonSolidTileCount=WORLD1_SOLID_TILE_COUNT; + currentLevelWidth = World1Area2_WIDTH; + currentLevelHeight = World1Area2_HEIGHT; + currentLevelWidthInTiles = World1Area2_WIDTH>>3; + currentLevelHeightInTiles = World1Area2_HEIGHT>>3; + currentLevelMap= World1Area2_map; + + break; + case 2: + + + // Switch to whichever bank our song is in + // Not neccessary if the song is in bank 0 + SWITCH_ROM((BANK(World2Tileset))); + + set_native_tile_data(0,World2Tileset_TILE_COUNT,World2Tileset_tiles); + setBKGPalettes(World2Tileset_PALETTE_COUNT,World2Tileset_palettes); + + + // Switch to whichever bank our song is in + // Not neccessary if the song is in bank 0 + SWITCH_ROM((currentAreaBank = BANK(World2Area1))); + + currentLevelNonSolidTileCount=WORLD2_SOLID_TILE_COUNT; + currentLevelWidth = World2Area1_WIDTH; + currentLevelHeight = World2Area1_HEIGHT; + currentLevelWidthInTiles = World2Area1_WIDTH>>3; + currentLevelHeightInTiles = World2Area1_HEIGHT>>3; + currentLevelMap= World2Area1_map; + + break; + } + + SWITCH_ROM(_previous_bank); + + DISPLAY_ON; +} diff --git a/gbdk-lib/examples/cross-platform/platformer_template/src/level.h b/gbdk-lib/examples/cross-platform/platformer_template/src/level.h @@ -0,0 +1,20 @@ +#ifndef WORLD_HEADER +#define WORLD_HEADER + +#include <stdint.h> +#include <gbdk/platform.h> + +extern uint16_t currentLevelWidth; +extern uint16_t currentLevelWidthInTiles; +extern uint16_t currentLevelHeight; +extern uint16_t currentLevelHeightInTiles; +extern uint8_t *currentLevelMap; +extern uint8_t currentLevelNonSolidTileCount; + +extern uint8_t currentLevel; +extern uint8_t currentAreaBank; +extern uint8_t nextLevel; + +uint8_t IsTileSolid(uint16_t worldX,uint16_t worldY); +void SetupCurrentLevel(void); +#endif + diff --git a/gbdk-lib/examples/cross-platform/platformer_template/src/main.c b/gbdk-lib/examples/cross-platform/platformer_template/src/main.c @@ -0,0 +1,89 @@ +#include <gbdk/platform.h> +#include <stdint.h> +#include "player.h" +#include "common.h" +#include "level.h" +#include "camera.h" +#include "NextLevel.h" +#include "TitleScreen.h" + +BANKREF_EXTERN(NextLevel) +BANKREF_EXTERN(TitleScreen) + + +void main(void) +{ + + + #ifdef NINTENDO + // init palettes + BGP_REG = DMG_PALETTE(DMG_BLACK, DMG_WHITE, DMG_LITE_GRAY, DMG_DARK_GRAY); + OBP0_REG =OBP1_REG =DMG_PALETTE(DMG_DARK_GRAY, DMG_BLACK, DMG_WHITE, DMG_LITE_GRAY ); + #endif + + // Turn the background map on to make it visible + SHOW_BKG; + SHOW_SPRITES; + SPRITES_8x16; + + ShowCentered(TitleScreen_WIDTH,TitleScreen_HEIGHT,BANK(TitleScreen),TitleScreen_tiles,TitleScreen_TILE_COUNT,TitleScreen_map,TitleScreen_palettes); + + WaitForStartOrA(); + + // Make sure these are initially different so the "setupcurrentLevel" logic is triggered + currentLevel=255; + nextLevel=0; + + // Loop forever + while(1) { + + // yield CPU and wait for start of next frame + vsync(); + + // if we want to change levels + if(nextLevel!=currentLevel){ + + + // if we're not starting the game (where currentLevel = 255) + if(currentLevel!=255){ + + ShowCentered(NextLevel_WIDTH,NextLevel_HEIGHT,BANK(NextLevel),NextLevel_tiles,NextLevel_TILE_COUNT,NextLevel_map,NextLevel_palettes); + + WaitForStartOrA(); + } + + // Update what our current level is + currentLevel=nextLevel; + + // Setup the new level + SetupCurrentLevel(); + + camera_x=0; + + // Draw the initial area + // Draw one extra column to avoid a blank row when first scrolling. + // If scrolling vertically also, you should draw one extra row as well. + // The platformer template will only scroll horizontally + SetCurrentLevelSubmap(0,0,DEVICE_SCREEN_WIDTH+1,DEVICE_SCREEN_HEIGHT); + + #if DEVICE_SCREEN_BUFFER_WIDTH == DEVICE_SCREEN_WIDTH + // On platforms where screen buffer has no more space than physical screen, + // the next map column will be written to the leftmost screen column. + // So we blank the leftmost column to hide visual artifacts where possible. + HIDE_LEFT_COLUMN; + #endif + + // Setup the player + SetupPlayer(); + } + + // Get the joypad input + joypadPrevious = joypadCurrent; + joypadCurrent = joypad(); + + uint8_t spritesUsed = UpdatePlayer(); + hide_sprites_range(spritesUsed,MAX_HARDWARE_SPRITES); + + UpdateCamera(); + } +} diff --git a/gbdk-lib/examples/cross-platform/platformer_template/src/player.c b/gbdk-lib/examples/cross-platform/platformer_template/src/player.c @@ -0,0 +1,362 @@ +#pragma bank 255 + +#include <gbdk/platform.h> +#include <gbdk/metasprites.h> +#include <stdint.h> +#include "common.h" +#include "PlayerCharacterSprites.h" +#include "camera.h" +#include "level.h" + +BANKREF_EXTERN(PlayerCharacterSprites) + + +#define GRAVTY 45 +#define GROUND_FRICTION 15 +#define PLAYER_CHARACTER_INCREASE_JUMP_TIMER_MAX 20 +#define PLAYER_CHARACTER_JUMP_VELOCITY 550 +#define PLAYER_CHARACTER_WALK_VELOCITY 325 +#define PLAYER_CHARACTER_RUN_VELOCITY 425 +#define PLAYER_CHARACTER_WALK_TWO_FRAME_COUNTER 3 +#define PLAYER_CHARACTER_RUN_TWO_FRAME_COUNTER 5 + +#define PLAYER_CHARACTER_METASPRITE_PIVOT_X 12 +#define PLAYER_CHARACTER_METASPRITE_PIVOT_Y 6 +#define PLAYER_CHARACTER_BOUNDING_BOX_HALF_WIDTH 5 +#define PLAYER_CHARACTER_BOUNDING_BOX_HALF_HEIGHT 12 +#define PLAYER_CHARACTER_BOUNDING_BOX_HEIGHT 24 + +uint8_t facingRight =TRUE; + +uint8_t playerJumpIncrease = 0; +uint8_t threeFrameCounter=0; +uint16_t playerX, playerY; +int16_t playerXVelocity, playerYVelocity; + + // Flip horizontally, if we aren't facing right + +#if defined(NINTENDO_NES) + const uint8_t baseProp=4; +#else + const uint8_t baseProp=0; +#endif + +#if defined(SEGA) + #define PLAYER_PALETTES_BANK CURRENT_BANK + #define PLAYER_PALETTES PlayerPalettesGGSMS + #define set_player_sprite_data set_sprite_native_data + +#else + #define PLAYER_PALETTES_BANK BANK(PlayerCharacterSprites) + #define PLAYER_PALETTES PlayerCharacterSprites_palettes + #define set_player_sprite_data set_sprite_data +#endif + + + +const palette_color_t PlayerPalettesGGSMS[16] = { + RGB8(255,128, 64), RGB8(248,248,248), RGB8(168,168,168), RGB8( 0, 0, 0) + , + RGB8(143, 0, 0), RGB8( 6,112, 0), RGB8( 0, 31,173), RGB8(122,134, 0) + , + RGB8( 0,138,111), RGB8( 75, 0, 82), RGB8(255, 0, 0), RGB8( 33,255, 0) + , + RGB8( 0, 46,255), RGB8(255,238, 0), RGB8( 0,225,255), RGB8(253,132,255) + +}; + +/** + * @brief We'll Put the PlayerCharacter's tiles in VRAM. + * Not every platform supports tile-flipping. We want To avoid wasting vram space with both left & right animations. + * we'll keep tiles only for the direction we are facing. + */ +void UpdatePlayerVRAMTiles(void) NONBANKED{ + uint8_t _previous_bank = CURRENT_BANK; + + + SWITCH_ROM(BANK(PlayerCharacterSprites)); + + set_player_sprite_data (0,PlayerCharacterSprites_TILE_COUNT,PlayerCharacterSprites_tiles); + + SWITCH_ROM(_previous_bank); +} + +void SetPlayerPalettes(void) NONBANKED{ + uint8_t _previous_bank = CURRENT_BANK; + + SWITCH_ROM(PLAYER_PALETTES_BANK); + + // Set up color palettes + #if defined(SEGA) + set_sprite_palette(baseProp, 1, PLAYER_PALETTES); + #elif defined(GAMEBOY) + if (_cpu == CGB_TYPE) { + set_sprite_palette(OAMF_CGB_PAL0, 1, PLAYER_PALETTES); + } + #elif defined(NINTENDO_NES) + set_sprite_palette(baseProp, 4, PLAYER_PALETTES); + #endif + + + SWITCH_ROM(_previous_bank); +} + +void SetupPlayer(void) BANKED{ + + // Player will start at 40,40 + // the playerX and playerY variables are scaled, so we shift to the left by 4 + playerX=40<<4; + playerY=40<<4; + + playerXVelocity=0; + playerYVelocity=0; + + UpdatePlayerVRAMTiles(); + + + SetPlayerPalettes(); + + +} + +uint8_t DrawPlayer(uint16_t playerRealX, uint16_t playerRealY, uint8_t frame) NONBANKED{ + + uint8_t spritesUsed=0; + uint8_t _previous_bank = CURRENT_BANK; + + + // Get the player's position relative to the camera's position + uint16_t playerCameraX = (playerRealX-camera_x)+DEVICE_SPRITE_PX_OFFSET_X; + uint16_t playerCameraY= (playerRealY)+DEVICE_SPRITE_PX_OFFSET_Y; + + SWITCH_ROM(BANK(PlayerCharacterSprites)); + + spritesUsed = move_metasprite_ex(PlayerCharacterSprites_metasprites[frame],0,baseProp,0,playerCameraX,playerCameraY); + + SWITCH_ROM(_previous_bank); + + return spritesUsed; +} + +uint8_t UpdatePlayer(void) BANKED{ + + // Use the run velocity if the B button is held + // Animate the threeFrameCounter faster when B is held + int16_t moveSpeed = (joypadCurrent & J_B) ?PLAYER_CHARACTER_RUN_VELOCITY:PLAYER_CHARACTER_WALK_VELOCITY; + uint8_t threeFrameCounterSpeed = (joypadCurrent & J_B) ? PLAYER_CHARACTER_RUN_TWO_FRAME_COUNTER : PLAYER_CHARACTER_WALK_TWO_FRAME_COUNTER; + + threeFrameCounter+=threeFrameCounterSpeed; + uint8_t threeFrameCounterValue = threeFrameCounter>>4; + if(threeFrameCounterValue>=3){ + threeFrameCounter=0; + threeFrameCounterValue=0; + } + + uint8_t turning = FALSE; + + if(joypadCurrent &J_RIGHT){ + + // If we are facing the other direction? + if(playerXVelocity<0){ + + // Just decrease the velocity, and save that we are turning + playerXVelocity+=GROUND_FRICTION; + + // We are turning, IF we didn't just finish changing direction. + if(playerXVelocity<0)turning=TRUE; + else{ + + facingRight=TRUE; + } + }else{ + playerXVelocity=moveSpeed; + + // Switch our vram data for the player + if(!facingRight){ + facingRight=TRUE; + } + + } + }else if(joypadCurrent &J_LEFT){ + + // If we are facing the other direction? + if(playerXVelocity>0){ + + // Just decrease the velocity, and save that we are turning + playerXVelocity-=GROUND_FRICTION; + + // We are turning, IF we didn't just finish changing direction. + if(playerXVelocity>0)turning=TRUE; + else{ + + facingRight=FALSE; + + } + }else{ + playerXVelocity=-moveSpeed; + + // Switch our vram data for the player + if(facingRight){ + facingRight=FALSE; + + } + + } + + }else{ + + // Move the x velocity towards 0 + if (playerXVelocity > 0) { + if (playerXVelocity >= GROUND_FRICTION) playerXVelocity -= GROUND_FRICTION; + else playerXVelocity=0; + } + else if (playerXVelocity < 0) { + if (playerXVelocity <= GROUND_FRICTION) playerXVelocity += GROUND_FRICTION; + else playerXVelocity=0; + } + } + + uint16_t playerRealX = playerX>>4; + uint16_t playerRealY = playerY>>4; + + uint8_t grounded = FALSE; + + // The Player Y is the top of the bounding box. + // If the player starts to go above the top of the screen + // then the unsigned integer will wrap. This will cause this loop + // to fire for a long time until 'playerRealY+PLAYER_CHARACTER_BOUNDING_BOX_HEIGHT-1' wraps around to the bottom of the level. + // For that reason, because we only scroll horizontally, make sure the player's y position isn't higher than the screen is tall + if(playerRealY<DEVICE_SCREEN_PX_HEIGHT){ + + // Prevent getting stuck in the ground + while(IsTileSolid(playerRealX,playerRealY+PLAYER_CHARACTER_BOUNDING_BOX_HEIGHT-1)){ + playerY-=16; + playerRealY = playerY>>4; + } + } + + /** + * @brief Important Note: We need can't use the same x for horizontal collision as we do vertical. + * For the horizontal collisions, we'll use player x + or - 5. + * For the vertical collisions, we'll use player x + or - 3. + * If we use the same offset value for both, you'll see player getting stuck in the ground. + * This would be because both are firing & succeeding, and as a result: player's + * x and y velocities are constantly being set to 0. + */ + + // If the player is moving horizontally + if(playerXVelocity!=0){ + + // If the player is moving to the right + if(playerXVelocity>0){ + + // The player sprite is sort of tall, we need to check in multiple places along the right edge + // Subtract a little from the top & bottom edges so player doesn't get caught in ceilings/floors + if(IsTileSolid(playerRealX+PLAYER_CHARACTER_BOUNDING_BOX_HALF_WIDTH,playerRealY+2)||IsTileSolid(playerRealX+PLAYER_CHARACTER_BOUNDING_BOX_HALF_WIDTH,playerRealY+PLAYER_CHARACTER_BOUNDING_BOX_HALF_HEIGHT)||IsTileSolid(playerRealX+PLAYER_CHARACTER_BOUNDING_BOX_HALF_WIDTH,playerRealY+(PLAYER_CHARACTER_BOUNDING_BOX_HEIGHT-2)))playerXVelocity=0; + + // If the player is moving to the left + }else if(playerXVelocity<0){ + + // The player sprite is sort of tall, we need to check in multiple places along the left edge + // Subtract a little from the top & bottom edges so player doesn't get caught in ceilings/floors + if(IsTileSolid(playerRealX-PLAYER_CHARACTER_BOUNDING_BOX_HALF_WIDTH,playerRealY+2)||IsTileSolid(playerRealX-PLAYER_CHARACTER_BOUNDING_BOX_HALF_WIDTH,playerRealY+PLAYER_CHARACTER_BOUNDING_BOX_HALF_HEIGHT)||IsTileSolid(playerRealX-PLAYER_CHARACTER_BOUNDING_BOX_HALF_WIDTH,playerRealY+(PLAYER_CHARACTER_BOUNDING_BOX_HEIGHT-2)))playerXVelocity=0; + } + } + + // If the player is moving downwards or still + if(playerYVelocity>=0){ + + // Check both sides of player's feet (left and right) + // Subtract a little from the edge so player doesn't get caught in walls + if(IsTileSolid(playerRealX+(PLAYER_CHARACTER_BOUNDING_BOX_HALF_WIDTH-2),playerRealY+PLAYER_CHARACTER_BOUNDING_BOX_HEIGHT)||IsTileSolid(playerRealX-(PLAYER_CHARACTER_BOUNDING_BOX_HALF_WIDTH-2),playerRealY+PLAYER_CHARACTER_BOUNDING_BOX_HEIGHT)){ + playerYVelocity=0; + grounded=TRUE; + } + + // If the player is moving upwards + }else if(playerYVelocity<0){ + + + // Check both sides of player's head (left and right) + // Subtract a little from the edge so player doesn't get caught in walls + // To prevent getting stuck, move the player downward also and loop until there's no overlap + while(IsTileSolid(playerRealX+(PLAYER_CHARACTER_BOUNDING_BOX_HALF_WIDTH-2),playerRealY)||IsTileSolid(playerRealX-(PLAYER_CHARACTER_BOUNDING_BOX_HALF_WIDTH-2),playerRealY)){ + playerYVelocity=0; + playerY+=16; + playerRealY = playerY>>4; + } + + + } + + uint8_t pressedA = (joypadCurrent & J_A && !(joypadPrevious & J_A)); + uint8_t pressedUp = (joypadCurrent & J_UP && !(joypadPrevious & J_UP)); + uint8_t pressedAOrUp = pressedA||pressedUp; + + // If we are grounded, and the A/Up button was JUST pressed + if(grounded && pressedAOrUp){ + playerYVelocity=-PLAYER_CHARACTER_JUMP_VELOCITY; + playerJumpIncrease=PLAYER_CHARACTER_INCREASE_JUMP_TIMER_MAX; + } + + // If the player is in the air + if(!grounded){ + + // If we are in the air, increase the amount of time the player can increase the jump height + if(playerJumpIncrease>0)playerJumpIncrease--; + + // If we are not holding A/Up, or if the amount of time we can increase our jump has ended + if(!((joypadCurrent & J_A||joypadCurrent & J_UP))||playerJumpIncrease==0){ + + // Apply gravity + playerYVelocity+=GRAVTY; + + // Reset to zero here, so the player has to hold initally to increase jump height + playerJumpIncrease=0; + } + + // If the player is grounded, and moving downward + }else if(playerYVelocity>=0){ + + // Stop the velocity now + playerYVelocity=0; + } + + // Apply the players velocity + playerX+=playerXVelocity>>4; + playerY+=playerYVelocity>>4; + + // Get the non-scaled version of the player's position + playerRealX = playerX>>4; + playerRealY = playerY>>4; + + // if we've gone past the half-screen mark + if(playerRealX>=(DEVICE_SCREEN_PX_WIDTH>>1)){ + uint16_t max = currentLevelWidth-DEVICE_SCREEN_PX_WIDTH; + camera_x=playerRealX-(DEVICE_SCREEN_PX_WIDTH>>1); + + // Limit the camera position to avoid drawing offscreen/looping data + if(camera_x>max)camera_x=max; + } + else camera_x=0; + + // Which of the player's metasprite frames should be shown? + // If we are grounded: + // Turning = Frame 5 + // Standing Still = Frame 0 + // Running = Frame 0 - 2 (via threeFrameCounterValue variable) + // If we are in the air: + // Rising = Frame 3 + // Falling = Frame 4 + uint8_t frame = grounded ? (turning ? 5 :((playerXVelocity>>4)==0 ? 0 : threeFrameCounterValue)) : (playerYVelocity<0 ? 3 : 4); + uint8_t directionOffset = facingRight ? 0 : 6; + + uint8_t spritesUsed = DrawPlayer(playerRealX,playerRealY,frame+directionOffset); + + // Increase the level if the player is at the end + if(playerRealX>currentLevelWidth-32){ + nextLevel++; + } + + return spritesUsed; +} + diff --git a/gbdk-lib/examples/cross-platform/platformer_template/src/player.h b/gbdk-lib/examples/cross-platform/platformer_template/src/player.h @@ -0,0 +1,11 @@ +#ifndef PLAYER_HEADER +#define PLAYER_HEADER +#include <gbdk/platform.h> + +extern uint16_t playerX, playerY; +extern int16_t playerXVelocity, playerYVelocity; + +void SetupPlayer(void) BANKED; +uint8_t UpdatePlayer(void) BANKED; + +#endif +

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.