initial commit

This commit is contained in:
2020-01-21 01:38:34 +01:00
commit 204e0047e8
32 changed files with 9111 additions and 0 deletions
+8
View File
@@ -0,0 +1,8 @@
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace
*.elf
*.nds
+27
View File
@@ -0,0 +1,27 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "enter program name, for example ${workspaceFolder}/a.out",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
+5
View File
@@ -0,0 +1,5 @@
{
"files.associations": {
"array": "cpp"
}
}
+39
View File
@@ -0,0 +1,39 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Run new build",
"type": "shell",
"command": "cd ${workspaceFolder} && pwd && make run",
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "dedicated",
"showReuseMessage": true,
"clear": true
}
},
{
"label": "Copy new build to SD",
"type": "shell",
"command": "cd ${workspaceFolder} && pwd && make install",
"problemMatcher": [],
"presentation": {
"echo": true,
"reveal": "silent",
"focus": false,
"panel": "dedicated",
"showReuseMessage": true,
"clear": false
}
}
]
}
+209
View File
@@ -0,0 +1,209 @@
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITARM)),)
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
endif
include $(DEVKITARM)/ds_rules
#---------------------------------------------------------------------------------
# TARGET is the name of the output
# BUILD is the directory where object files & intermediate files will be placed
# SOURCES is a list of directories containing source code
# INCLUDES is a list of directories containing extra header files
# DATA is a list of directories containing binary files embedded using bin2o
# GRAPHICS is a list of directories containing image files to be converted with grit
# AUDIO is a list of directories containing audio to be converted by maxmod
# ICON is the image used to create the game icon, leave blank to use default rule
# NITRO is a directory that will be accessible via NitroFS
#---------------------------------------------------------------------------------
TARGET := $(shell basename $(CURDIR))
BUILD := build
SOURCES := source
INCLUDES := include build
DATA :=
GRAPHICS := gfx
AUDIO := sounds
GAME_TITLE := Snake Plus
GAME_SUBTITLE1:= Snake with a twist
GAME_SUBTITLE2:= Phillip Kuehne
ICON := icon.bmp
# specify a directory which contains the nitro filesystem
# this is relative to the Makefile
NITRO :=
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
ARCH := -marm -mthumb-interwork -march=armv5te -mtune=arm946e-s
CFLAGS := -g -Wall -O3\
$(ARCH) $(INCLUDE) -DARM9
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
ASFLAGS := -g $(ARCH)
LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project (order is important)
#---------------------------------------------------------------------------------
LIBS := -lnds9
# automatigically add libraries for NitroFS
ifneq ($(strip $(NITRO)),)
LIBS := -lfilesystem -lfat $(LIBS)
endif
# automagically add maxmod library
ifneq ($(strip $(AUDIO)),)
LIBS := -lmm9 $(LIBS)
endif
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS := $(LIBNDS) $(PORTLIBS)
#---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional
# rules for different file extensions
#---------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
#---------------------------------------------------------------------------------
export OUTPUT := $(CURDIR)/$(TARGET)
export VPATH := $(CURDIR)/$(subst /,,$(dir $(ICON)))\
$(foreach dir,$(SOURCES),$(CURDIR)/$(dir))\
$(foreach dir,$(DATA),$(CURDIR)/$(dir))\
$(foreach dir,$(GRAPHICS),$(CURDIR)/$(dir))
export DEPSDIR := $(CURDIR)/$(BUILD)
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
PNGFILES := $(foreach dir,$(GRAPHICS),$(notdir $(wildcard $(dir)/*.png)))
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
# prepare NitroFS directory
ifneq ($(strip $(NITRO)),)
export NITRO_FILES := $(CURDIR)/$(NITRO)
endif
# get audio list for maxmod
ifneq ($(strip $(AUDIO)),)
export MODFILES := $(foreach dir,$(notdir $(wildcard $(AUDIO)/*.*)),$(CURDIR)/$(AUDIO)/$(dir))
# place the soundbank file in NitroFS if using it
ifneq ($(strip $(NITRO)),)
export SOUNDBANK := $(NITRO_FILES)/soundbank.bin
# otherwise, needs to be loaded from memory
else
export SOUNDBANK := soundbank.bin
BINFILES += $(SOUNDBANK)
endif
endif
#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),)
#---------------------------------------------------------------------------------
export LD := $(CC)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
export LD := $(CXX)
#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------
export OFILES := $(addsuffix .o,$(BINFILES))\
$(PNGFILES:.png=.o)\
$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
-I$(CURDIR)/$(BUILD)
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
icons = $(wildcard *.bmp)
ifneq (,$(findstring $(TARGET).bmp,$(icons)))
export GAME_ICON := $(CURDIR)/$(TARGET).bmp
else
ifneq (,$(findstring icon.bmp,$(icons)))
export GAME_ICON := $(CURDIR)/icon.bmp
endif
endif
.PHONY: $(BUILD) clean
#---------------------------------------------------------------------------------
$(BUILD):
@mkdir -p $@
@make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
#---------------------------------------------------------------------------------
clean:
@echo clean ...
@rm -fr $(BUILD) $(TARGET).elf $(TARGET).nds $(SOUNDBANK)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
$(OUTPUT).nds: $(OUTPUT).elf $(GAME_ICON)
$(OUTPUT).elf: $(OFILES)
# need to build soundbank first
$(OFILES): $(SOUNDBANK)
#---------------------------------------------------------------------------------
# rule to build solution from music files
#---------------------------------------------------------------------------------
$(SOUNDBANK) : $(MODFILES)
#---------------------------------------------------------------------------------
mmutil $^ -d -o$@ -hsoundbank.h
#---------------------------------------------------------------------------------
%.bin.o: %.bin
#---------------------------------------------------------------------------------
@echo $(notdir $<)
$(bin2o)
#---------------------------------------------------------------------------------
# This rule creates assembly source files using grit
# grit takes an image file and a .grit describing how the file is to be processed
# add additional rules like this for each image extension
# you use in the graphics folders
#---------------------------------------------------------------------------------
%.s %.h: %.png %.grit
#---------------------------------------------------------------------------------
grit $< -fts -o$*
#---------------------------------------------------------------------------------
# Convert non-GRF game icon to GRF if needed
#---------------------------------------------------------------------------------
#$(GAME_ICON): $(notdir $(ICON))
#---------------------------------------------------------------------------------
# @echo convert $(notdir $<)
# @grit $< -g -gt -gB4 -gT FF00FF -m! -p -pe 16 -fh! -ftr
#
#-include $(DEPSDIR)/*.d
#---------------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------------
run: build $(OUTPUT).nds
melonDS $(OUTPUT).nds
install: build $(OUTPUT).nds
cp $(OUTPUT).nds /run/media/phillipk/9016-4EF8/devel/
BIN
View File
Binary file not shown.
+199
View File
@@ -0,0 +1,199 @@
main.o: /home/phillipk/Projekte/nds/snakePlus/source/main.cpp \
/opt/devkitpro/libnds/include/nds.h \
/opt/devkitpro/libnds/include/nds/libversion.h \
/opt/devkitpro/libnds/include/nds/ndstypes.h \
/opt/devkitpro/libnds/include/nds/bios.h \
/opt/devkitpro/libnds/include/nds/ndstypes.h \
/opt/devkitpro/libnds/include/nds/card.h \
/opt/devkitpro/libnds/include/nds/ndstypes.h \
/opt/devkitpro/libnds/include/nds/debug.h \
/opt/devkitpro/libnds/include/nds/dma.h \
/opt/devkitpro/libnds/include/nds/interrupts.h \
/opt/devkitpro/libnds/include/nds/ipc.h \
/opt/devkitpro/libnds/include/nds/memory.h \
/opt/devkitpro/libnds/include/nds/system.h \
/opt/devkitpro/libnds/include/nds/timers.h \
/opt/devkitpro/libnds/include/nds/fifocommon.h \
/opt/devkitpro/libnds/include/nds/interrupts.h \
/opt/devkitpro/libnds/include/nds/touch.h \
/opt/devkitpro/libnds/include/nds/input.h \
/opt/devkitpro/libnds/include/nds/sha1.h \
/opt/devkitpro/libnds/include/nds/arm9/dynamicArray.h \
/opt/devkitpro/libnds/include/nds/arm9/linkedlist.h \
/opt/devkitpro/libnds/include/nds/arm9/background.h \
/opt/devkitpro/libnds/include/nds/arm9/video.h \
/opt/devkitpro/libnds/include/nds/arm9/sassert.h \
/opt/devkitpro/libnds/include/nds/memory.h \
/opt/devkitpro/libnds/include/nds/dma.h \
/opt/devkitpro/libnds/include/nds/arm9/boxtest.h \
/opt/devkitpro/libnds/include/nds/arm9/videoGL.h \
/opt/devkitpro/libnds/include/nds/arm9/cache.h \
/opt/devkitpro/libnds/include/nds/arm9/trig_lut.h \
/opt/devkitpro/libnds/include/nds/arm9/math.h \
/opt/devkitpro/libnds/include/nds/arm9/dynamicArray.h \
/opt/devkitpro/libnds/include/nds/arm9/cache.h \
/opt/devkitpro/libnds/include/nds/arm9/console.h \
/opt/devkitpro/libnds/include/nds/arm9/background.h \
/opt/devkitpro/libnds/include/nds/arm9/decompress.h \
/opt/devkitpro/libnds/include/nds/bios.h \
/opt/devkitpro/libnds/include/nds/arm9/exceptions.h \
/opt/devkitpro/libnds/include/nds/arm9/guitarGrip.h \
/opt/devkitpro/libnds/include/nds/arm9/image.h \
/opt/devkitpro/libnds/include/nds/arm9/pcx.h \
/opt/devkitpro/libnds/include/nds/arm9/input.h \
/opt/devkitpro/libnds/include/nds/touch.h \
/opt/devkitpro/libnds/include/nds/input.h \
/opt/devkitpro/libnds/include/nds/arm9/keyboard.h \
/opt/devkitpro/libnds/include/nds/arm9/math.h \
/opt/devkitpro/libnds/include/nds/arm9/paddle.h \
/opt/devkitpro/libnds/include/nds/arm9/pcx.h \
/opt/devkitpro/libnds/include/nds/arm9/piano.h \
/opt/devkitpro/libnds/include/nds/arm9/rumble.h \
/opt/devkitpro/libnds/include/nds/arm9/sassert.h \
/opt/devkitpro/libnds/include/nds/arm9/sound.h \
/opt/devkitpro/libnds/include/nds/arm9/sprite.h \
/opt/devkitpro/libnds/include/nds/system.h \
/opt/devkitpro/libnds/include/nds/arm9/window.h \
/opt/devkitpro/libnds/include/nds/arm9/sprite.h \
/opt/devkitpro/libnds/include/nds/arm9/trig_lut.h \
/opt/devkitpro/libnds/include/nds/arm9/video.h \
/opt/devkitpro/libnds/include/nds/arm9/videoGL.h \
/opt/devkitpro/libnds/include/nds/arm9/nand.h \
/home/phillipk/Projekte/nds/snakePlus/include/consts.h \
/opt/devkitpro/libnds/include/maxmod9.h \
/opt/devkitpro/libnds/include/mm_types.h \
/home/phillipk/Projekte/nds/snakePlus/build/soundbank.h \
/home/phillipk/Projekte/nds/snakePlus/build/soundbank_bin.h \
/home/phillipk/Projekte/nds/snakePlus/build/tilemap.h
/opt/devkitpro/libnds/include/nds.h:
/opt/devkitpro/libnds/include/nds/libversion.h:
/opt/devkitpro/libnds/include/nds/ndstypes.h:
/opt/devkitpro/libnds/include/nds/bios.h:
/opt/devkitpro/libnds/include/nds/ndstypes.h:
/opt/devkitpro/libnds/include/nds/card.h:
/opt/devkitpro/libnds/include/nds/ndstypes.h:
/opt/devkitpro/libnds/include/nds/debug.h:
/opt/devkitpro/libnds/include/nds/dma.h:
/opt/devkitpro/libnds/include/nds/interrupts.h:
/opt/devkitpro/libnds/include/nds/ipc.h:
/opt/devkitpro/libnds/include/nds/memory.h:
/opt/devkitpro/libnds/include/nds/system.h:
/opt/devkitpro/libnds/include/nds/timers.h:
/opt/devkitpro/libnds/include/nds/fifocommon.h:
/opt/devkitpro/libnds/include/nds/interrupts.h:
/opt/devkitpro/libnds/include/nds/touch.h:
/opt/devkitpro/libnds/include/nds/input.h:
/opt/devkitpro/libnds/include/nds/sha1.h:
/opt/devkitpro/libnds/include/nds/arm9/dynamicArray.h:
/opt/devkitpro/libnds/include/nds/arm9/linkedlist.h:
/opt/devkitpro/libnds/include/nds/arm9/background.h:
/opt/devkitpro/libnds/include/nds/arm9/video.h:
/opt/devkitpro/libnds/include/nds/arm9/sassert.h:
/opt/devkitpro/libnds/include/nds/memory.h:
/opt/devkitpro/libnds/include/nds/dma.h:
/opt/devkitpro/libnds/include/nds/arm9/boxtest.h:
/opt/devkitpro/libnds/include/nds/arm9/videoGL.h:
/opt/devkitpro/libnds/include/nds/arm9/cache.h:
/opt/devkitpro/libnds/include/nds/arm9/trig_lut.h:
/opt/devkitpro/libnds/include/nds/arm9/math.h:
/opt/devkitpro/libnds/include/nds/arm9/dynamicArray.h:
/opt/devkitpro/libnds/include/nds/arm9/cache.h:
/opt/devkitpro/libnds/include/nds/arm9/console.h:
/opt/devkitpro/libnds/include/nds/arm9/background.h:
/opt/devkitpro/libnds/include/nds/arm9/decompress.h:
/opt/devkitpro/libnds/include/nds/bios.h:
/opt/devkitpro/libnds/include/nds/arm9/exceptions.h:
/opt/devkitpro/libnds/include/nds/arm9/guitarGrip.h:
/opt/devkitpro/libnds/include/nds/arm9/image.h:
/opt/devkitpro/libnds/include/nds/arm9/pcx.h:
/opt/devkitpro/libnds/include/nds/arm9/input.h:
/opt/devkitpro/libnds/include/nds/touch.h:
/opt/devkitpro/libnds/include/nds/input.h:
/opt/devkitpro/libnds/include/nds/arm9/keyboard.h:
/opt/devkitpro/libnds/include/nds/arm9/math.h:
/opt/devkitpro/libnds/include/nds/arm9/paddle.h:
/opt/devkitpro/libnds/include/nds/arm9/pcx.h:
/opt/devkitpro/libnds/include/nds/arm9/piano.h:
/opt/devkitpro/libnds/include/nds/arm9/rumble.h:
/opt/devkitpro/libnds/include/nds/arm9/sassert.h:
/opt/devkitpro/libnds/include/nds/arm9/sound.h:
/opt/devkitpro/libnds/include/nds/arm9/sprite.h:
/opt/devkitpro/libnds/include/nds/system.h:
/opt/devkitpro/libnds/include/nds/arm9/window.h:
/opt/devkitpro/libnds/include/nds/arm9/sprite.h:
/opt/devkitpro/libnds/include/nds/arm9/trig_lut.h:
/opt/devkitpro/libnds/include/nds/arm9/video.h:
/opt/devkitpro/libnds/include/nds/arm9/videoGL.h:
/opt/devkitpro/libnds/include/nds/arm9/nand.h:
/home/phillipk/Projekte/nds/snakePlus/include/consts.h:
/opt/devkitpro/libnds/include/maxmod9.h:
/opt/devkitpro/libnds/include/mm_types.h:
/home/phillipk/Projekte/nds/snakePlus/build/soundbank.h:
/home/phillipk/Projekte/nds/snakePlus/build/soundbank_bin.h:
/home/phillipk/Projekte/nds/snakePlus/build/tilemap.h:
BIN
View File
Binary file not shown.
+7461
View File
File diff suppressed because it is too large Load Diff
Binary file not shown.
Binary file not shown.
+10
View File
@@ -0,0 +1,10 @@
#define SFX_273792__PACOMAV__PLOP 0
#define SFX_167127__CRISSTANZA__PAUSE 1
#define SFX_167126__CRISSTANZA__UNPAUSE 2
#define MOD_0RIGIN 0
#define SFX_BOOM 38
#define SFX_332629__TREASURESOUNDS__ITEM_PICKUP 39
#define SFX_73750__TIMBRE__REMIX_OF_BENBONCAN_SAD_TROMBONE_MORE_WAH_BRIGHT_DE_CLICKED 40
#define MSL_NSONGS 1
#define MSL_NSAMPS 41
#define MSL_BANKSIZE 42
+3
View File
@@ -0,0 +1,3 @@
extern const u8 soundbank_bin_end[];
extern const u8 soundbank_bin[];
extern const u32 soundbank_bin_size;
+1
View File
@@ -0,0 +1 @@
tilemap.o: tilemap.s
+32
View File
@@ -0,0 +1,32 @@
//{{BLOCK(tilemap)
//======================================================================
//
// tilemap, 256x256@8,
// + palette 256 entries, not compressed
// + 12 tiles (t|f reduced) not compressed
// + regular map (in SBBs), not compressed, 32x32
// Total size: 512 + 768 + 2048 = 3328
//
// Time-stamp: 2018-12-28, 03:06:39
// Exported by Cearn's GBA Image Transmogrifier, v0.8.15
// ( http://www.coranac.com/projects/#grit )
//
//======================================================================
#ifndef GRIT_TILEMAP_H
#define GRIT_TILEMAP_H
#define tilemapTilesLen 768
extern const unsigned int tilemapTiles[192];
#define tilemapMapLen 2048
extern const unsigned short tilemapMap[1024];
#define tilemapPalLen 512
extern const unsigned short tilemapPal[256];
#endif // GRIT_TILEMAP_H
//}}BLOCK(tilemap)
BIN
View File
Binary file not shown.
+240
View File
@@ -0,0 +1,240 @@
@{{BLOCK(tilemap)
@=======================================================================
@
@ tilemap, 256x256@8,
@ + palette 256 entries, not compressed
@ + 12 tiles (t|f reduced) not compressed
@ + regular map (in SBBs), not compressed, 32x32
@ Total size: 512 + 768 + 2048 = 3328
@
@ Time-stamp: 2018-12-28, 03:06:39
@ Exported by Cearn's GBA Image Transmogrifier, v0.8.15
@ ( http://www.coranac.com/projects/#grit )
@
@=======================================================================
.section .rodata
.align 2
.global tilemapTiles @ 768 unsigned chars
.hidden tilemapTiles
tilemapTiles:
.word 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000
.word 0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000,0x00000000
.word 0x09090900,0x00090909,0x02020209,0x09020202,0x02020209,0x09020202,0x02020209,0x09020202
.word 0x02020209,0x09020202,0x02020209,0x09020202,0x02020209,0x09020202,0x09090900,0x00090909
.word 0x09090900,0x00090909,0x0B0B0B09,0x090B0B0B,0x0B0B0B09,0x090B0B0B,0x0B0B0B09,0x090B0B0B
.word 0x0B0B0B09,0x090B0B0B,0x0B0B0B09,0x090B0B0B,0x0B0B0B09,0x090B0B0B,0x09090900,0x00090909
.word 0x09090900,0x00000009,0x02020209,0x00090902,0x02010209,0x09020202,0x02020209,0x0A0A0602
.word 0x02020209,0x0A0A0602,0x02010209,0x09020202,0x02020209,0x00090902,0x09090900,0x00000009
.word 0x0A090000,0x0000090A,0x0A020900,0x0009020A,0x06020900,0x00090206,0x02020209,0x09020202
.word 0x02020209,0x09020202,0x02010209,0x09020102,0x02020209,0x09020202,0x09090900,0x00090909
.word 0x07000000,0x00000007,0x070A0A00,0x000A0909,0x0A0A0A00,0x00090909,0x0A0A0A0A,0x0A0A0A0A
.word 0x0A0A0A0A,0x0A0A040A,0x0A0A0A00,0x000A040A,0x0A0A0A00,0x000A0A0A,0x0A000000,0x0000000A
.word 0x07000000,0x00000007,0x07030300,0x00030909,0x03030300,0x00090909,0x03030303,0x03030303
.word 0x03030303,0x03030403,0x03030300,0x00030403,0x03030300,0x00030303,0x03000000,0x00000003
.word 0x00000000,0x00000000,0x00000909,0x00000000,0x09090209,0x00000009,0x02020209,0x09090902
.word 0x02020209,0x09090902,0x09090209,0x00000009,0x00000909,0x00000000,0x00000000,0x00000000
.word 0x00000000,0x00000000,0x00000909,0x00000000,0x09090B09,0x00000009,0x0B0B0B09,0x0909090B
.word 0x0B0B0B09,0x0909090B,0x09090B09,0x00000009,0x00000909,0x00000000,0x00000000,0x00000000
.word 0x09000000,0x00000009,0x09000000,0x00000009,0x09000000,0x00000009,0x02090000,0x00000902
.word 0x02090000,0x00000902,0x02090000,0x00000902,0x02020900,0x00090202,0x09090900,0x00090909
.word 0x09000000,0x00000009,0x09000000,0x00000009,0x09000000,0x00000009,0x0B090000,0x0000090B
.word 0x0B090000,0x0000090B,0x0B090000,0x0000090B,0x0B0B0900,0x00090B0B,0x09090900,0x00090909
.word 0x07000000,0x00000007,0x070A0A00,0x000A0C0C,0x0A0A0A00,0x000C0C0C,0x0A0A050A,0x0A0A0A0A
.word 0x0A0A0A0A,0x0C0C0C05,0x0A0A0A00,0x000C0C05,0x0C0C0C00,0x00070C0C,0x07000000,0x0000000C
.section .rodata
.align 2
.global tilemapMap @ 2048 unsigned chars
.hidden tilemapMap
tilemapMap:
.hword 0x0000,0x0001,0x0002,0x0003,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0004,0x0005,0x0006,0x0007,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0008,0x0009,0x000A,0x000B,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.section .rodata
.align 2
.global tilemapPal @ 512 unsigned chars
.hidden tilemapPal
tilemapPal:
.hword 0x7C1F,0x7C00,0x03E0,0x001F,0x7FFF,0x2529,0x1084,0x00EE
.hword 0x0000,0x01A0,0x0016,0x37ED,0x01AE,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
.hword 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000
@}}BLOCK(tilemap)
+23
View File
@@ -0,0 +1,23 @@
#-------------------------------------------------------
# graphics in tile format
#-------------------------------------------------------
-gt
#-------------------------------------------------------
# tile reduction by tiles, palette and hflip/vflip
#-------------------------------------------------------
-mRtf
#-------------------------------------------------------
# graphics bit depth is 8 (256 color)
#-------------------------------------------------------
-gB8
-p
#-------------------------------------------------------
# map layout standard bg format
#-------------------------------------------------------
-mLs
-aw 32 -ah 32
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

+57
View File
@@ -0,0 +1,57 @@
#ifndef CONSTS_H
#define CONSTS_H
#endif
const int START_LENGTH = 4;
const int START_LENGTH_HARD =2;
const int APPLE_SCORE = 10;
//Screen size
const int X_MAX = 31;
const int Y_MAX = 23;
//*barf* Dont try this at home...
const char BITMAP_APPLE[] = {
0,0,0,2,2,0,0,0,
0,2,2,2,2,2,2,0,
0,2,2,2,2,2,2,0,
2,2,2,2,2,2,2,2,
2,2,2,2,2,1,2,2,
0,2,2,2,2,1,2,0,
0,2,2,2,2,2,2,0,
0,0,0,2,2,0,0,0
};
const char BITMAP_HEAD_RIGHT[] = {
0,3,3,3,3,3,3,0,
3,4,4,4,4,4,4,3,
3,4,7,4,7,4,4,3,
3,4,4,4,4,7,4,3,
3,4,4,4,4,7,4,3,
3,4,7,4,7,4,4,3,
3,4,4,4,4,4,4,3,
0,3,3,3,3,3,3,0
};
const char BITMAP_HEAD_UP[] = {
0,3,3,3,3,3,3,0,
3,4,4,4,4,4,4,3,
3,4,4,7,7,4,4,3,
3,4,7,4,4,7,4,3,
3,4,4,4,4,4,4,3,
3,4,7,4,4,7,4,3,
3,4,4,4,4,4,4,3,
0,3,3,3,3,3,3,0
};
const char BITMAP_SEGMENT[] = {
0,5,5,5,5,5,5,0,
5,6,6,6,6,6,6,5,
5,6,6,6,6,6,6,5,
5,6,6,6,6,6,6,5,
5,6,6,6,6,6,6,5,
5,6,6,6,6,6,6,5,
5,6,6,6,6,6,6,5,
0,5,5,5,5,5,5,0
};
+62
View File
@@ -0,0 +1,62 @@
3DRenderer=1
Threaded3D=1
GL_ScaleFactor=1
GL_Antialias=0
Key_A=32
Key_B=31
Key_Select=57
Key_Start=28
Key_Right=333
Key_Left=331
Key_Up=328
Key_Down=336
Key_R=54
Key_L=86
Key_X=17
Key_Y=30
Joy_A=1
Joy_B=0
Joy_Select=6
Joy_Start=7
Joy_Right=258
Joy_Left=264
Joy_Up=257
Joy_Down=260
Joy_R=5
Joy_L=4
Joy_X=3
Joy_Y=2
HKKey_Lid=14
HKKey_Mic=53
HKKey_Pause=-1
HKKey_Reset=-1
HKKey_FastForward=15
HKKey_FastForwardToggle=-1
HKJoy_Lid=-1
HKJoy_Mic=-1
HKJoy_Pause=-1
HKJoy_Reset=-1
HKJoy_FastForward=-1
HKJoy_FastForwardToggle=-1
JoystickID=0
WindowWidth=479
WindowHeight=718
WindowMax=0
ScreenRotation=0
ScreenGap=0
ScreenLayout=0
ScreenSizing=0
ScreenFilter=1
ScreenUseGL=1
ScreenRatio=0
LimitFPS=1
ShowOSD=1
DirectBoot=0
SockBindAnyAddr=1
LANDevice=
DirectLAN=0
SavStaRelocSRAM=1
AudioVolume=256
MicInputType=1
MicWavPath=
LastROMFolder=/home/phillipk/ROMS/NDS
+25
View File
@@ -0,0 +1,25 @@
Failed to set format: Invalid argument
Using 4 threads for video filter.
Microphone init failed.
DeSmuME 0.9.11 svn0 x64-JIT
WIFI: SoftAP: PCap library not available on your system.
Found 1 joysticks
Joystick 0 Microsoft X-Box 360 pad
Axes: 6
Buttons: 11
Trackballs: 0
Hats: 1
SoftRast Initialized with cores=4
ROM game code: ####
ROM serial: TWL-####-???
ROM chipID: FFFFFFC2
ROM internal name: HOMEBREW
ROM DSi Enhanced
ROM developer: Unknown
Slot1 auto-selected device type: Retail MC+ROM
Slot2 auto-selected device type: None (0xFF)
CPU mode: Interpreter
File doesn't appear to have a secure area.
BIN
View File
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
+710
View File
@@ -0,0 +1,710 @@
#include <nds.h>
#include <bitset>
#include <stdio.h>
#include <vector>
#include <deque>
#include <array>
#include <consts.h>
#include <maxmod9.h>
#include <nds/ndstypes.h>
#include "soundbank.h"
#include "soundbank_bin.h"
#include "tilemap.h"
volatile uint frame = 0;
volatile uint ticks = 0;
volatile bool internals = false;
std::deque<std::array<int, 3>> snake;
std::vector<std::array<int, 2>> apples;
std::vector<std::array<int, 2>> bad_apples;
volatile uint snakelength;
/***
* 0 = up
* 1 = right
* 2 = down
* 3 = left
***/
volatile uint snakeDirection;
volatile uint score;
bool gameOver = false;
bool paused = false;
bool musicEnabled = true;
bool hardMode = false;
// 31x23
PrintConsole topScreen;
PrintConsole bottomScreen;
int sound;
mm_sound_effect sfx_pickup;
mm_sound_effect sfx_boom;
mm_sound_effect sfx_pause;
mm_sound_effect sfx_unpause;
mm_sound_effect sfx_plop;
mm_sound_effect sfx_fail;
//Sprites
u16* gfx_segment;
u16* gfx_segment_small;
u16* gfx_head;
u16* gfx_apple;
u16* gfx_tail;
u16* gfx_apple_rotten;
const void * get_sprite_pointer(uint spriteIndex) {
return &tilemapTiles[spriteIndex*16];
}
void setup() {
// Set up screens
videoSetMode(MODE_0_2D);
videoSetModeSub(MODE_0_2D);
vramSetBankC(VRAM_C_SUB_BG);
vramSetBankD(VRAM_D_SUB_SPRITE);
consoleInit(&topScreen, 3,BgType_Text4bpp, BgSize_T_256x256, X_MAX, 0, true, true);
consoleInit(&bottomScreen, 3,BgType_Text4bpp, BgSize_T_256x256, X_MAX, 0, false, true);
oamInit(&oamSub, SpriteMapping_1D_32, false);
gfx_segment = oamAllocateGfx(&oamSub, SpriteSize_8x8, SpriteColorFormat_256Color);
gfx_segment_small = oamAllocateGfx(&oamSub, SpriteSize_8x8, SpriteColorFormat_256Color);
gfx_head = oamAllocateGfx(&oamSub, SpriteSize_8x8, SpriteColorFormat_256Color);
gfx_apple = oamAllocateGfx(&oamSub, SpriteSize_8x8, SpriteColorFormat_256Color);
gfx_apple_rotten = oamAllocateGfx(&oamSub, SpriteSize_8x8, SpriteColorFormat_256Color);
gfx_tail = oamAllocateGfx(&oamSub, SpriteSize_8x8, SpriteColorFormat_256Color);
dmaCopy(get_sprite_pointer(1),gfx_segment,64);
dmaCopy(get_sprite_pointer(2),gfx_segment_small,64);
dmaCopy(get_sprite_pointer(3),gfx_head,64);
dmaCopy(get_sprite_pointer(5),gfx_apple,64);
dmaCopy(get_sprite_pointer(11),gfx_apple_rotten,64);
consoleSelect(&topScreen);
dmaCopy(tilemapPal,SPRITE_PALETTE_SUB,tilemapPalLen);
mmInitDefaultMem((mm_addr)soundbank_bin);
// Background Music
mmLoad( MOD_0RIGIN );
// Load SFX
mmLoadEffect( SFX_332629__TREASURESOUNDS__ITEM_PICKUP );
mmLoadEffect( SFX_BOOM );
mmLoadEffect( SFX_167127__CRISSTANZA__PAUSE );
mmLoadEffect( SFX_167126__CRISSTANZA__UNPAUSE );
mmLoadEffect( SFX_273792__PACOMAV__PLOP );
mmLoadEffect( SFX_73750__TIMBRE__REMIX_OF_BENBONCAN_SAD_TROMBONE_MORE_WAH_BRIGHT_DE_CLICKED );
sfx_pickup = {
{ SFX_332629__TREASURESOUNDS__ITEM_PICKUP } , // id
(int)(1.0f * (1<<10)), // rate
0, // handle
255, // volume
128, // panning
};
sfx_boom = {
{ SFX_BOOM } ,
(int)(1.0f * (1<<10)),
1,
255,
128,
};
sfx_pause = {
{ SFX_167127__CRISSTANZA__PAUSE } ,
(int)(1.0f * (1<<10)),
2,
255,
128,
};
sfx_unpause = {
{ SFX_167126__CRISSTANZA__UNPAUSE } ,
(int)(1.0f * (1<<10)),
3,
255,
128,
};
sfx_plop = {
{ SFX_273792__PACOMAV__PLOP } ,
(int)(1.0f * (1<<10)),
4,
128,
128,
};
sfx_fail = {
{ SFX_73750__TIMBRE__REMIX_OF_BENBONCAN_SAD_TROMBONE_MORE_WAH_BRIGHT_DE_CLICKED } ,
(int)(1.0f * (1<<10)),
4,
255,
128,
};
}
void check_collision_self() {
std::array<int, 3> headpos = snake.front();
std::deque<std::array<int, 3>>::iterator testit = snake.begin();
testit++; //skip head, no collision here
for(testit; testit != snake.end(); testit++)
{
std::array<int, 3> dot = *testit;
if ((dot[0] == headpos[0] && dot[1] == headpos[1] ) && !gameOver) {
gameOver = true;
mmStop();
mmEffectEx(&sfx_fail);
consoleSelect(&topScreen);
iprintf("\x1b[10;13HGAME OVER!");
}
}
}
void check_collision_apples() {
std::array<int, 3> headpos = snake.front();
std::vector<std::array<int, 2>>::iterator testit = apples.begin();
for(testit; testit <= apples.end(); testit++)
{
std::array<int, 2> apple = *testit;
if ((apple[0] == headpos[0] && apple[1] == headpos[1] )) {
score += 10;
snakelength++;
apples.erase(testit);
mmEffectEx(&sfx_pickup);
}
}
}
void check_collision_apples_rotten() {
std::array<int, 3> headpos = snake.front();
std::vector<std::array<int, 2>>::iterator testit = bad_apples.begin();
for(testit; testit <= bad_apples.end(); testit++)
{
std::array<int, 2> apple = *testit;
if ((apple[0] == headpos[0] && apple[1] == headpos[1] )) {
snakelength--;
bad_apples.erase(testit);
mmEffectEx(&sfx_boom);
if (snakelength < 2) {
gameOver = true;
}
}
}
}
void draw_snake_head(uint &oamId) {
std::array<int, 3> dot = snake.front();
bool hflip = false;
bool vflip = false;
switch (snakeDirection)
{
case 0: //going up
dmaCopy(&tilemapTiles[64],gfx_head,64);
break;
case 1: //going right
dmaCopy(&tilemapTiles[48],gfx_head,64);
break;
case 2: //going down
dmaCopy(&tilemapTiles[64],gfx_head,64);
vflip = true;
break;
case 3: //going left
/*for(int i = 0; i < 8 * 8; i=i+2)
{
gfx_head[i/2] = ((BITMAP_HEAD_RIGHT[i+1]<<8) | BITMAP_HEAD_RIGHT[i]);
}*/
dmaCopy(&tilemapTiles[48],gfx_head,64);
hflip = true;
break;
default:
break;
}
oamSet(&oamSub, // oam
oamId, //id
dot[0]*8, // x
dot[1]*8, // y
0, // priority
0, // palette_alpha
SpriteSize_8x8, // size
SpriteColorFormat_256Color, // color format
gfx_head, // gfxoffset
-1, // affineIndex
false, // sizeDouble
false, // hide
hflip, // hflip
vflip, // vflip
false // mosaic
);
oamId++;
}
void draw_snake_tail(uint &oamId) {
std::array<int, 3> dot = snake.back();
bool hflip = false;
bool vflip = false;
switch (snake.at(snake.size()-2).at(2))
{
case 0: //going up
dmaCopy(get_sprite_pointer(9+((snake.size()-1)%2)),gfx_tail,64);
vflip = true;
break;
case 1: //going right
dmaCopy(get_sprite_pointer(7+((snake.size()-1)%2)),gfx_tail,64);
hflip = true;
break;
case 2: //going down
dmaCopy(get_sprite_pointer(9+((snake.size()-1)%2)),gfx_tail,64);
break;
case 3: //going left
/*for(int i = 0; i < 8 * 8; i=i+2)
{
gfx_tail[i/2] = ((BITMAP_tail_RIGHT[i+1]<<8) | BITMAP_tail_RIGHT[i]);
}*/
dmaCopy(get_sprite_pointer(7+((snake.size()-1)%2)),gfx_tail,64);
break;
default:
break;
}
oamSet(&oamSub, // oam
oamId, //id
dot[0]*8, // x
dot[1]*8, // y
0, // priority
0, // palette_alpha
SpriteSize_8x8, // size
SpriteColorFormat_256Color, // color format
gfx_tail, // gfxoffset
-1, // affineIndex
false, // sizeDouble
false, // hide
hflip, // hflip
vflip, // vflip
false // mosaic
);
oamId++;
}
void draw_snake(uint &oamId) {
draw_snake_head(oamId);
for(size_t i = 1; i < snake.size()-1; i++)
{
if(i%2) {
oamSet(&oamSub, // oam
oamId, //id
snake[i][0]*8, // x
snake[i][1]*8, // y
0, // priority
0, // palette_alpha
SpriteSize_8x8, // size
SpriteColorFormat_256Color, // color format
gfx_segment_small, // gfxoffset
-1, // affineIndex
false, // sizeDouble
false, // hide
false, // hflip
false, // vflip
false // mosaic
);
} else {
oamSet(&oamSub, // oam
oamId, //id
snake[i][0]*8, // x
snake[i][1]*8, // y
0, // priority
0, // palette_alpha
SpriteSize_8x8, // size
SpriteColorFormat_256Color, // color format
gfx_segment, // gfxoffset
-1, // affineIndex
false, // sizeDouble
false, // hide
false, // hflip
false, // vflip
false // mosaic
);
}
oamId++;
}
draw_snake_tail(oamId);
}
void draw_apples(uint &oamId) {
for(std::array<int, 2> apple : apples)
{
oamSet(&oamSub, // oam
oamId, //id
apple[0]*8, // x
apple[1]*8, // y
0, // priority
0, // palette_alpha
SpriteSize_8x8, // size
SpriteColorFormat_256Color, // color format
gfx_apple, // gfxoffset
-1, // affineIndex
false, // sizeDouble
false, // hide
false, // hflip
false, // vflip
false // mosaic
);
oamId++;
}
}
void draw_apples_rotten(uint &oamId) {
for(std::array<int, 2> apple : bad_apples)
{
oamSet(&oamSub, // oam
oamId, //id
apple[0]*8, // x
apple[1]*8, // y
0, // priority
0, // palette_alpha
SpriteSize_8x8, // size
SpriteColorFormat_256Color, // color format
gfx_apple_rotten, // gfxoffset
-1, // affineIndex
false, // sizeDouble
false, // hide
false, // hflip
false, // vflip
false // mosaic
);
oamId++;
}
}
void draw_game() {
uint oamid = 0;
if (!gameOver) {
draw_apples(oamid);
draw_apples_rotten(oamid);
draw_snake(oamid);
}
else
{
iprintf("\x1b[11;12HGAME OVER!");
}
iprintf("\x1b[7;0HoamIDmax=%i",oamid);
}
void draw_stats() {
if ( internals ) {
iprintf("\x1b[0;0HFrame = %i\nTick = %i\ndir = %i", frame, ticks, snakeDirection);
iprintf("\x1b[3;0HLength: %i", snakelength);
iprintf("\x1b[4;0Hx=%i\ny=%i",snake.front()[0], snake.front()[1]);
}
iprintf("\x1b[10;12HScore: %i", score);
if (paused) {
if (musicEnabled) {
iprintf("\x1b[23;0HX = Disable Music");
} else {
iprintf("\x1b[23;0HX = Enable Music ");
}
if (hardMode) {
iprintf("\x1b[22;0HY = Restart in normal mode");
} else {
iprintf("\x1b[22;0HY = Restart in Hard mode");
}
}
}
void handle_vblank() {
frame++;
consoleSelect(&topScreen);
draw_stats();
oamUpdate(&oamSub);
//flashy_colors();
}
void update_snake() {
std::array<int, 3> headpos = snake.front();
std::array<int, 3> newHead;
if (snakeDirection == 0) {
newHead = { headpos[0], headpos[1]-1, snakeDirection };
}
else if (snakeDirection == 1)
{
newHead = { headpos[0]+1, headpos[1], snakeDirection };
}
else if (snakeDirection == 2)
{
newHead = { headpos[0], headpos[1]+1, snakeDirection };
}
else if (snakeDirection == 3)
{
newHead = { headpos[0]-1, headpos[1], snakeDirection };
}
if (newHead[0] > X_MAX) {
newHead[0] = 0;
}
if (newHead[1] > Y_MAX) {
newHead[1] = 0;
}
if (newHead[0] < 0) {
newHead[0] = X_MAX;
}
if (newHead[1] < 0) {
newHead[1] = Y_MAX;
}
snake.push_front(newHead);
snake.resize(snakelength);
}
void spawn_apples() {
if (apples.size() < 1 ) {
std::array<int,2> apple;
apple[0] = rand() % (X_MAX+1);
apple[1] = rand() % (Y_MAX+1);
apples.push_back(apple);
}
}
void spawn_apples_rotten() {
if ( (ticks%10==0) && hardMode && ((rand() % 10)<10) && (bad_apples.size()<20)) {
std::array<int,2> badApple;
badApple[0] = rand() % (X_MAX+1);
badApple[1] = rand() % (Y_MAX+1);
bad_apples.push_back(badApple);
}
}
void blink_apples() {
if (ticks % 4) {
dmaCopy(get_sprite_pointer(5),gfx_apple,64);
} else {
dmaCopy(get_sprite_pointer(6),gfx_apple,64);
}
}
void do_tick() {
if (!paused) {
ticks++;
if (!gameOver){
/*if (hardMode) {
timerStop(0);
timerStart(0, ClockDivider_1024, TIMER_FREQ_1024(ticks+5), do_tick);
}*/
update_snake();
mmEffectEx(&sfx_plop);
check_collision_self();
check_collision_apples();
check_collision_apples_rotten();
spawn_apples();
spawn_apples_rotten();
blink_apples();
//consoleSelect(&bottomScreen);
draw_game();
}
}
}
void init_game() {
if (hardMode) {
timerStart(0, ClockDivider_1024, TIMER_FREQ_1024(9), do_tick);
setBackdropColorSub(RGB15(10,5,5));
score = 0;
snakelength = START_LENGTH_HARD;
snake = { {2,1,1}, {1,1,1} };
apples.clear();
bad_apples.clear();
snakeDirection = 1;
ticks = 0;
gameOver=false;
consoleSelect(&topScreen);
consoleClear();
consoleSelect(&bottomScreen);
consoleClear();
oamClear(&oamSub,0,0);
mmStart( MOD_0RIGIN, MM_PLAY_LOOP );
if (!musicEnabled) {
mmPause();
}
}
else
{
timerStart(0, ClockDivider_1024, TIMER_FREQ_1024(5), do_tick);
setBackdropColorSub(RGB15(5,5,5));
score = 0;
snakelength = START_LENGTH;
snake = { {4,1,1}, {3,1,1}, {2,1,1}, {1,1,1} };
snakeDirection = 1;
ticks = 0;
gameOver=false;
consoleSelect(&topScreen);
consoleClear();
consoleSelect(&bottomScreen);
consoleClear();
oamClear(&oamSub,0,0);
mmStart( MOD_0RIGIN, MM_PLAY_LOOP );
if (!musicEnabled) {
mmPause();
}
}
}
int main(void) {
// Set up VBlank handler
irqSet(IRQ_VBLANK, handle_vblank);
setup();
init_game();
// Start timer for game ticks
while(1) {
scanKeys();
int keys = keysDown();
if (keys && internals) {
consoleSelect(&topScreen);
iprintf("\x1b[6;0Hkeys = %s", std::bitset<16>(keys).to_string().c_str());
}
if ((keys & KEY_START) && (keys & KEY_L) ) break;
if (keys & KEY_SELECT) {
internals = !internals;
if (internals) {
setBackdropColor(RGB15(0,0,7));
} else {
setBackdropColor(RGB15(0,0,0));
consoleSelect(&topScreen);
consoleClear();
}
}
if (!paused && !gameOver) {
if (keys & KEY_UP) {
snakeDirection = 0;
draw_game();
}
if (keys & KEY_RIGHT) {
snakeDirection = 1;
draw_game();
}
if (keys & KEY_DOWN) {
snakeDirection = 2;
draw_game();
}
if (keys & KEY_LEFT) {
snakeDirection = 3;
draw_game();
}
}
if (paused) {
if (keys & KEY_X) {
musicEnabled = !musicEnabled;
}
if (keys & KEY_Y) {
hardMode = !hardMode;
init_game();
draw_game();
}
}
if (keys & KEY_R) {
lcdSwap();
}
if (keys & (KEY_START)) {
if (!gameOver) {
paused = !paused;
if (paused) {
consoleSelect(&topScreen);
mmEffectEx(&sfx_pause);
if ( musicEnabled ) {
mmPause();
}
iprintf("\x1b[11;12HPaused");
}
else
{
if (musicEnabled) {
mmResume();
}
mmEffectEx(&sfx_unpause);
consoleSelect(&topScreen);
consoleClear();
}
}
else
{
init_game();
}
}
}
return 0;
}