├── .gitattributes ├── Makefile ├── README.md ├── clean.bat ├── compile.bat ├── icon.bmp ├── nflib ├── include │ ├── nf_2d.h │ ├── nf_3d.h │ ├── nf_affinebg.h │ ├── nf_basic.h │ ├── nf_bitmapbg.h │ ├── nf_colision.h │ ├── nf_defines.h │ ├── nf_lib.h │ ├── nf_media.h │ ├── nf_mixedbg.h │ ├── nf_sound.h │ ├── nf_sprite256.h │ ├── nf_sprite3d.h │ ├── nf_text.h │ ├── nf_text16.h │ └── nf_tiledbg.h └── lib │ └── libnflib.a ├── nitrofiles ├── backgrounds │ ├── bg.img │ ├── bg.map │ └── bg.pal ├── fonts │ ├── font.fnt │ └── font.pal ├── palettes │ ├── apple.pal │ ├── apple_dropshadow.pal │ ├── segment.pal │ └── segment_dropshadow.pal └── sprites │ └── tile.img └── source ├── apple.cpp ├── apple.h ├── main.cpp ├── segment.cpp ├── segment.h ├── snake.cpp └── snake.h /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------------- 2 | # Makefile for NightFox's Lib Projects 3 | #--------------------------------------------------------------------------------- 4 | 5 | 6 | 7 | #--------------------------------------------------------------------------------- 8 | .SUFFIXES: 9 | #--------------------------------------------------------------------------------- 10 | ifeq ($(strip $(DEVKITARM)),) 11 | $(error "Please set DEVKITARM in your environment. export DEVKITARM=devkitARM") 12 | endif 13 | 14 | 15 | #--------------------------------------------------------------------------------- 16 | # This part substitutes this include: 17 | # include $(DEVKITARM)/ds_rules 18 | # This allows you to set ROM info and icon easy 19 | # Please update this block from DS_RULES file at every DEVKITARM update 20 | #--------------------------------------------------------------------------------- 21 | include $(DEVKITARM)/base_rules 22 | 23 | LIBNDS := $(DEVKITPRO)/libnds 24 | 25 | GAME_TITLE := Snake 26 | GAME_SUBTITLE1 := PolyMars 27 | #GAME_SUBTITLE2 := Text 3 28 | GAME_ICON := $(CURDIR)/../icon.bmp 29 | 30 | _ADDFILES := -d $(NITRO_FILES) 31 | 32 | 33 | #--------------------------------------------------------------------------------- 34 | %.nds: %.arm9 35 | @ndstool -c $@ -9 $< -b $(GAME_ICON) "$(GAME_TITLE);$(GAME_SUBTITLE1);$(GAME_SUBTITLE2)" $(_ADDFILES) 36 | @echo built ... $(notdir $@) 37 | 38 | #--------------------------------------------------------------------------------- 39 | %.nds: %.elf 40 | @ndstool -c $@ -9 $< -b $(GAME_ICON) "$(GAME_TITLE);$(GAME_SUBTITLE1);$(GAME_SUBTITLE2)" $(_ADDFILES) 41 | @echo built ... $(notdir $@) 42 | 43 | #--------------------------------------------------------------------------------- 44 | %.arm9: %.elf 45 | @$(OBJCOPY) -O binary $< $@ 46 | @echo built ... $(notdir $@) 47 | 48 | #--------------------------------------------------------------------------------- 49 | %.arm7: %.elf 50 | @$(OBJCOPY) -O binary $< $@ 51 | @echo built ... $(notdir $@) 52 | 53 | #--------------------------------------------------------------------------------- 54 | %.elf: 55 | @echo linking $(notdir $@) 56 | @$(LD) $(LDFLAGS) $(OFILES) $(LIBPATHS) $(LIBS) -o $@ 57 | 58 | 59 | #--------------------------------------------------------------------------------- 60 | # TARGET is the name of the output 61 | # BUILD is the directory where object files & intermediate files will be placed 62 | # SOURCES is a list of directories containing source code 63 | # INCLUDES is a list of directories containing extra header files 64 | # DATA is a list of directories containing binary files embedded using bin2o 65 | # NITRODATA is the directory where files for NitroFS will be placed 66 | #--------------------------------------------------------------------------------- 67 | TARGET := $(shell basename $(CURDIR)) 68 | BUILD := build 69 | SOURCES := source 70 | INCLUDES := include 71 | DATA := data 72 | NITRODATA := nitrofiles 73 | 74 | #--------------------------------------------------------------------------------- 75 | # options for code generation 76 | #--------------------------------------------------------------------------------- 77 | ARCH := -mthumb -mthumb-interwork 78 | 79 | CFLAGS := -g -Wall -O2\ 80 | -march=armv5te -mtune=arm946e-s -fomit-frame-pointer\ 81 | -ffast-math \ 82 | $(ARCH) 83 | 84 | CFLAGS += $(INCLUDE) -DARM9 85 | CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions 86 | 87 | ASFLAGS := -g $(ARCH) 88 | LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) 89 | 90 | #--------------------------------------------------------------------------------- 91 | # any extra libraries we wish to link with the project 92 | #--------------------------------------------------------------------------------- 93 | LIBS := -lnflib -lfilesystem -lfat -lnds9 94 | 95 | 96 | #--------------------------------------------------------------------------------- 97 | # list of directories containing libraries, this must be the top level containing 98 | # include and lib 99 | #--------------------------------------------------------------------------------- 100 | LIBDIRS := $(LIBNDS) $(CURDIR)/nflib 101 | 102 | 103 | #--------------------------------------------------------------------------------- 104 | # no real need to edit anything past this point unless you need to add additional 105 | # rules for different file extensions 106 | #--------------------------------------------------------------------------------- 107 | ifneq ($(BUILD),$(notdir $(CURDIR))) 108 | #--------------------------------------------------------------------------------- 109 | 110 | export OUTPUT := $(CURDIR)/$(TARGET) 111 | 112 | export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ 113 | $(foreach dir,$(DATA),$(CURDIR)/$(dir)) 114 | 115 | export DEPSDIR := $(CURDIR)/$(BUILD) 116 | 117 | export NITRO_FILES := $(CURDIR)/$(NITRODATA) 118 | 119 | CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) 120 | CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) 121 | SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) 122 | BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) 123 | 124 | #--------------------------------------------------------------------------------- 125 | # use CXX for linking C++ projects, CC for standard C 126 | #--------------------------------------------------------------------------------- 127 | ifeq ($(strip $(CPPFILES)),) 128 | #--------------------------------------------------------------------------------- 129 | export LD := $(CC) 130 | #--------------------------------------------------------------------------------- 131 | else 132 | #--------------------------------------------------------------------------------- 133 | export LD := $(CXX) 134 | #--------------------------------------------------------------------------------- 135 | endif 136 | #--------------------------------------------------------------------------------- 137 | 138 | export OFILES := $(addsuffix .o,$(BINFILES)) \ 139 | $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) 140 | 141 | export INCLUDE := $(foreach dir,$(INCLUDES),-iquote $(CURDIR)/$(dir)) \ 142 | $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ 143 | -I$(CURDIR)/$(BUILD) 144 | 145 | export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) 146 | 147 | icons := $(wildcard *.bmp) 148 | 149 | ifneq (,$(findstring $(TARGET).bmp,$(icons))) 150 | export GAME_ICON := $(CURDIR)/$(TARGET).bmp 151 | else 152 | ifneq (,$(findstring icon.bmp,$(icons))) 153 | export GAME_ICON := $(CURDIR)/icon.bmp 154 | endif 155 | endif 156 | 157 | .PHONY: $(BUILD) clean 158 | 159 | #--------------------------------------------------------------------------------- 160 | $(BUILD): 161 | @[ -d $@ ] || mkdir -p $@ 162 | @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile 163 | 164 | #--------------------------------------------------------------------------------- 165 | clean: 166 | @echo clean ... 167 | @rm -fr $(BUILD) $(TARGET).elf $(TARGET).nds $(TARGET).arm9 168 | 169 | #--------------------------------------------------------------------------------- 170 | else 171 | 172 | #--------------------------------------------------------------------------------- 173 | # main targets 174 | #--------------------------------------------------------------------------------- 175 | $(OUTPUT).nds : $(OUTPUT).elf 176 | $(OUTPUT).elf : $(OFILES) 177 | 178 | #--------------------------------------------------------------------------------- 179 | %.bin.o : %.bin 180 | #--------------------------------------------------------------------------------- 181 | @echo $(notdir $<) 182 | $(bin2o) 183 | 184 | #--------------------------------------------------------------------------------------- 185 | endif 186 | #--------------------------------------------------------------------------------------- 187 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Snake DS 2 | 3 | Snake DS is simple clone of Snake for the Nintendo DS made with [NightFox's Lib](https://gbatemp.net/threads/nightfoxs-lib-for-libnds-nflib-ds-entry-coding-library.280385/) and libnds. 4 | 5 | ## Screenshots 6 | 7 | ![he's doin a loop](https://gbatemp.net/attachments/loop-gif.199759/?temp_hash=669ae2d2a889e9c698a477077ac6219a) ![a decent player](https://gbatemp.net/attachments/gif-gif.199788/) 8 | ![a god player](https://gbatemp.net/attachments/gif-gif.199787/) 9 | 10 | ## Background 11 | This game was created to be used as a reference for anyone interested in making their own DS homebrew games with NightFox's Lib. I tried to make the code as clean and well-structured as possible, but feel free to ask any questions if you need anything to be clarified. It's also a somewhat fun game on it's own with all the features you'd expect from a Snake clone, so you can grab a build [here](https://github.com/PolyMarsDev/Snake-DS/releases/) if you want to try it out :) 12 | 13 | ## Usage 14 | 15 | NightFox's Lib does not need to be downloaded as it is already integrated into this repository, but to compile this code you'll need to install the libnds libraries with [devkitPro](https://devkitpro.org/wiki/Getting_Started). Then, after downloading and extracting the files in this repository, run the ``compile.bat`` script to compile the code. 16 | 17 | ## Contributing 18 | Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change. Feel free to create a fork of this repository or use the code for any other noncommercial purposes. 19 | -------------------------------------------------------------------------------- /clean.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | cls 3 | make clean 4 | pause 5 | exit -------------------------------------------------------------------------------- /compile.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | cls 3 | make 4 | pause 5 | exit -------------------------------------------------------------------------------- /icon.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PolyMarsDev/Snake-DS/f121e33b2bab17d762f3bfd65ab5022ee365b9e3/icon.bmp -------------------------------------------------------------------------------- /nflib/include/nf_2d.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PolyMarsDev/Snake-DS/f121e33b2bab17d762f3bfd65ab5022ee365b9e3/nflib/include/nf_2d.h -------------------------------------------------------------------------------- /nflib/include/nf_3d.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PolyMarsDev/Snake-DS/f121e33b2bab17d762f3bfd65ab5022ee365b9e3/nflib/include/nf_3d.h -------------------------------------------------------------------------------- /nflib/include/nf_affinebg.h: -------------------------------------------------------------------------------- 1 | #ifdef __cplusplus 2 | extern "C" { 3 | #endif 4 | 5 | #ifndef __NF_AFFINEBG_H__ 6 | #define __NF_AFFINEBG_H__ 7 | 8 | 9 | 10 | 11 | 12 | // NightFox LIB - Includes de Fondos Affine 13 | // Requiere DevkitARM 14 | // Codigo por Cesar Rincon "NightFox" 15 | // http://www.nightfoxandco.com/ 16 | // Version 20140413 17 | 18 | 19 | 20 | 21 | 22 | // Includes devKitPro 23 | #include 24 | 25 | 26 | 27 | 28 | 29 | // Estructura para almacenar los parametros de los fondos Affine 30 | typedef struct { 31 | s32 x; // Posicion X 32 | s32 y; // Posicion Y 33 | s32 x_center; // Centro X 34 | s32 y_center; // Centro Y 35 | s32 x_scale; // Valor Zoom X (PA) 36 | s32 y_scale; // Valor Zoom Y (PD) 37 | s32 x_tilt; // Valor Inclinacion X (PB) 38 | s32 y_tilt; // Valor Inclinacion Y (PC) 39 | s32 angle; // Valor de la rotacion 40 | } NF_TYPE_AFFINE_BG; 41 | extern NF_TYPE_AFFINE_BG NF_AFFINE_BG[2][4]; 42 | 43 | 44 | 45 | 46 | 47 | // Funcion NF_InitTiledBgSys(); 48 | void NF_InitAffineBgSys(u8 screen); 49 | // Inicializa el sistema de fondos Affine. Solo puede usarse en las capas 2 y 3, los fondos en 50 | // la misma pantalla deben de compartir la paleta y no pueden tener mas de 256 tiles. 51 | 52 | 53 | 54 | // Funcion NF_LoadAffineBg(); 55 | void NF_LoadAffineBg(const char* file, const char* name, u16 width, u16 height); 56 | // Carga un fondo tileado desde FAT 57 | // Debes de especificar el archivo que se cargara (sin extension) y el nombre 58 | // que le quieres dar y las medidas en pixeles 59 | // Los buffers para fondos tileados deben estar inicializados antes de usar esta funcion 60 | 61 | 62 | 63 | // Funcion NF_UnloadAffineBg(); 64 | void NF_UnloadAffineBg(const char* name); 65 | // Borra de la RAM el fondo affine especificado. Es una simple llamada a la funcion NF_UnloadTiledBg(); 66 | 67 | 68 | 69 | // Funcion NF_CreateAffineBg(); 70 | void NF_CreateAffineBg(u8 screen, u8 layer, const char* name, u8 wrap); 71 | // Crea un fondo con los parametros dados, indicale la pantalla, capa, nombre y si se activa la opcion 72 | // de WRAP arround (0 desactivado, 1 activado). 73 | 74 | 75 | 76 | // Funcion NF_DeleteAffineBg(); 77 | void NF_DeleteAffineBg(u8 screen, u8 layer); 78 | // Borra el fondo Affine especificado 79 | 80 | 81 | 82 | // Funcion NF_AffineBgTransform(); 83 | void NF_AffineBgTransform(u8 screen, u8 layer, s32 x_scale, s32 y_scale, s32 x_tilt, s32 y_tilt); 84 | // Modifica los parametros de la matriz de transformacion del fondo affine 85 | 86 | 87 | 88 | // Funcion NF_AffineBgMove(); 89 | void NF_AffineBgMove(u8 screen, u8 layer, s32 x, s32 y, s32 angle); 90 | // Desplaza el fondo affine y rotalo (-2048 a 2048) 91 | 92 | 93 | 94 | // Funcion NF_AffineBgCenter(); 95 | void NF_AffineBgCenter(u8 screen, u8 layer, s32 x, s32 y); 96 | // Define el centro de rotacion de un fondo affine 97 | 98 | 99 | 100 | 101 | 102 | #endif 103 | 104 | #ifdef __cplusplus 105 | } 106 | #endif 107 | -------------------------------------------------------------------------------- /nflib/include/nf_basic.h: -------------------------------------------------------------------------------- 1 | #ifdef __cplusplus 2 | extern "C" { 3 | #endif 4 | 5 | #ifndef __NF_BASIC_H__ 6 | #define __NF_BASIC_H__ 7 | 8 | 9 | 10 | 11 | 12 | // NightFox LIB - Include de funciones basicas 13 | // Requiere DevkitARM 14 | // Codigo por Cesar Rincon "NightFox" 15 | // http://www.nightfoxandco.com/ 16 | // Version 20140413 17 | 18 | 19 | 20 | // Includes devKitPro 21 | #include 22 | 23 | 24 | 25 | 26 | 27 | // Define la variable global NF_ROOTFOLDER 28 | extern char NF_ROOTFOLDER[32]; 29 | 30 | 31 | 32 | // Funcion NF_Error(); 33 | void NF_Error(u16 code, const char* text, u32 value); 34 | // Errores para debug. Detiene el sistema e informa del error 35 | // 101: Fichero no encontrado 36 | // 102: Memoria insuficiente 37 | // 103: No quedan Slots libres 38 | // 104: Fondo no encontrado 39 | // 105: Fondo no creado 40 | // 106: Fuera de rango 41 | // 107: Insuficientes bloques contiguos en VRAM (Tiles) 42 | // 108: Insuficientes bloques contiguos en VRAM (Maps) 43 | // 109: Id ocupada (ya esta en uso) 44 | // 110: Id no cargada (en RAM) 45 | // 111: Id no en VRAM 46 | // 112: Sprite no creado 47 | // 113: Memoria VRAM insuficiente 48 | // 114: La capa de Texto no existe 49 | // 115: Medidas del fondo no compatibles (no son multiplos de 256) 50 | // 116: Archivo demasiado grande 51 | // 117: Medidas del fondo affine incorrectas 52 | // 118: Capa de creacion del fondo affine incorrecta 53 | 54 | 55 | 56 | // Funcion NF_SetRootFolder(); 57 | void NF_SetRootFolder(const char* folder); 58 | // Define el nombre de la carpeta que se usara como "root" si se usa la FAT 59 | 60 | 61 | 62 | // Funcion NF_DmaMemCopy(); 63 | void NF_DmaMemCopy(void* destination, const void* source, u32 size); 64 | // Copia un bloque de memoria usando DMA (canal 3, halfwords) y vaciando previamente 65 | // el cache. Con pruebas de bloques grandes (64kb o 128kb) he observado que memcpy(); 66 | // sigue siendo mas rapida. 67 | 68 | 69 | 70 | // Funcion NF_GetLanguage(); 71 | extern u8 NF_GetLanguage(void); 72 | // Devuelve el ID del idioma del usuario 73 | // 0 : Japanese 74 | // 1 : English 75 | // 2 : French 76 | // 3 : German 77 | // 4 : Italian 78 | // 5 : Spanish 79 | // 6 : Chinese 80 | 81 | 82 | 83 | 84 | 85 | #endif 86 | 87 | #ifdef __cplusplus 88 | } 89 | #endif 90 | -------------------------------------------------------------------------------- /nflib/include/nf_bitmapbg.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PolyMarsDev/Snake-DS/f121e33b2bab17d762f3bfd65ab5022ee365b9e3/nflib/include/nf_bitmapbg.h -------------------------------------------------------------------------------- /nflib/include/nf_colision.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PolyMarsDev/Snake-DS/f121e33b2bab17d762f3bfd65ab5022ee365b9e3/nflib/include/nf_colision.h -------------------------------------------------------------------------------- /nflib/include/nf_defines.h: -------------------------------------------------------------------------------- 1 | #ifdef __cplusplus 2 | extern "C" { 3 | #endif 4 | 5 | #ifndef __NF_DEFINES_H__ 6 | #define __NF_DEFINES_H__ 7 | 8 | 9 | 10 | 11 | 12 | // NightFox LIB - Definiciones General 13 | // Requiere DevkitARM 14 | // Codigo por Cesar Rincon "NightFox" 15 | // http://www.nightfoxandco.com/ 16 | // Version 20140413 17 | 18 | 19 | 20 | 21 | 22 | // Definicion de los datos del usuario 23 | // Informacion obtenida de PALIB source code 24 | // Referencias usadas de http://nds.metawiki.com/Firmware 25 | 26 | /* 27 | 28 | FW offset* RAM address Bytes Description 29 | 0x000020 2 user settings offset / 8 (default 0x7FC0 => 0x3FE00) 30 | 0x00002A 2 CRC16 (with initial value 0) of 0x2C with config length 31 | 0x00002C 2 config length (0x138) 32 | 0x000036 6 MAC address 33 | 0x00003C 4 enabled channels 34 | 0x000065 1 ? 35 | 0x000082 1 ? 36 | 0x000100 1 ? 37 | 0x000146 14 ? 38 | 0x000162 1 ? 39 | 0x03Fx00 0x023FFC80 1 version (5) 40 | 0x03Fx02 0x027FFC82 1 favorite color (0-15) 41 | 0x03Fx03 0x027FFC83 1 birthday month (1-12) 42 | 0x03Fx04 0x027FFC84 1 birthday day (1-31) 43 | 0x03Fx06 0x027FFC86 20 name, UTF-16 44 | 0x03Fx1A 0x027FFC9A 1/2 length of name in characters 45 | 0x03Fx1C 0x027FFC9C 52 message, UTF-16 46 | 0x03Fx50 0x027FFCD0 1/2 length of message in characters 47 | 0x03Fx52 0x027FFCD2 1 alarm hour 48 | 0x03Fx53 0x027FFCD3 1 alarm minute 49 | 0x03Fx56 0x027FFCD6 1 0x80=enable alarm, bit 0..6=enable? 50 | 0x027FFCD8 12 touch-screen calibration 51 | 0x027FFCE4 bit 0..2 language 52 | 0x027FFCE4 bit 3 GBA mode screen selection. 0=upper, 1=lower 53 | 0x027FFCE4 bit 6 auto/manual mode. 0=manual, 1=auto 54 | WIFI power calibration 55 | 0x03Fx70 1/2 update counter (used to check latest) 56 | 0x03Fx72 CRC16 of 0x03FF00, 0x70 bytes 57 | 58 | */ 59 | 60 | #define NF_UDATA_COLOR *(u8*)(0x027FFC82) 61 | #define NF_UDATA_BDAY_MONTH *(u8*)(0x027FFC83) 62 | #define NF_UDATA_BDAY_DAY *(u8*)(0x027FFC84) 63 | #define NF_UDATA_ALARM_HOUR *(u8*)(0x027FFCD2) 64 | #define NF_UDATA_ALARM_MINUTE *(u8*)(0x027FFCD3) 65 | #define NF_UDATA_NAME *(u8*)(0x027FFC86) 66 | #define NF_UDATA_NAME_SIZE *(u8*)(0x027FFC9A) 67 | #define NF_UDATA_MSG *(u8*)(0x027FFC9C) 68 | #define NF_UDATA_MSG_SIZE *(u8*)(0x027FFCD0) 69 | #define NF_UDATA_LANG *(u8*)(0x027FFCE4) 70 | 71 | 72 | 73 | 74 | 75 | #endif 76 | 77 | #ifdef __cplusplus 78 | } 79 | #endif 80 | -------------------------------------------------------------------------------- /nflib/include/nf_lib.h: -------------------------------------------------------------------------------- 1 | #ifdef __cplusplus 2 | extern "C" { 3 | #endif 4 | 5 | #ifndef __NF_LIB_H__ 6 | #define __NF_LIB_H__ 7 | 8 | 9 | 10 | 11 | 12 | // NightFox LIB - Include General 13 | // Requiere DevkitARM 14 | // Codigo por Cesar Rincon "NightFox" 15 | // http://www.nightfoxandco.com/ 16 | // Version 20140413 17 | 18 | 19 | 20 | /* 21 | 22 | Notas sobre BITSHIFT 23 | 24 | (n >> x) Divide n / x 25 | (n << x) Multiplica n * x 26 | 27 | Valores de X 28 | 2 = 1 29 | 4 = 2 30 | 8 = 3 31 | 16 = 4 32 | 32 = 5 33 | 64 = 6 34 | 128 = 7 35 | 256 = 8 36 | 512 = 9 37 | 1024 = 10 38 | 2048 = 11 39 | 4096 = 12 40 | 8192 = 13 41 | 16384 = 14 42 | 32768 = 15 43 | 65536 = 16 44 | 45 | Dado que la DS no tiene unidad de coma flotante, siempre que dividas o 46 | multipliques por numeros de base 2, usa el bitshift 47 | Por ejemplo: 48 | a = (512 / 8); 49 | seria equivalente a 50 | a = (512 >> 3); 51 | Multiplicando 52 | b = (3 * 2048); 53 | seria con bitshift 54 | b = (3 << 11); 55 | 56 | */ 57 | 58 | 59 | 60 | 61 | // Definiciones comunes 62 | #include "nf_defines.h" 63 | 64 | // Libreria de funciones basicas y comunes 65 | #include "nf_basic.h" 66 | 67 | // Libreria de funciones 2D comunes 68 | #include "nf_2d.h" 69 | 70 | // Libreria de fondos con Tiles 71 | #include "nf_tiledbg.h" 72 | 73 | // Libreria de fondos Affine 74 | #include "nf_affinebg.h" 75 | 76 | // Libreria de fondos en modo Bitmap 77 | #include "nf_bitmapbg.h" 78 | 79 | // Libreria de fondos en modo mixto (Tiled / Bitmap 8 bits) 80 | #include "nf_mixedbg.h" 81 | 82 | // Libreria de sprites de 256 colores 83 | #include "nf_sprite256.h" 84 | 85 | // Libreria de textos 86 | #include "nf_text.h" 87 | 88 | // Libreria de textos de 16 pixeles 89 | #include "nf_text16.h" 90 | 91 | // Libreria de colisiones 92 | #include "nf_colision.h" 93 | 94 | // Libreria de sonido 95 | #include "nf_sound.h" 96 | 97 | // Libreria de archivos multimedia 98 | #include "nf_media.h" 99 | 100 | // Libreria 3D, funciones comunes 101 | #include "nf_3d.h" 102 | 103 | // Libreria 3D, Sprites 104 | #include "nf_sprite3d.h" 105 | 106 | 107 | 108 | 109 | 110 | #endif 111 | 112 | #ifdef __cplusplus 113 | } 114 | #endif 115 | -------------------------------------------------------------------------------- /nflib/include/nf_media.h: -------------------------------------------------------------------------------- 1 | #ifdef __cplusplus 2 | extern "C" { 3 | #endif 4 | 5 | #ifndef __NF_MEDIA_H__ 6 | #define __NF_MEDIA_H__ 7 | 8 | 9 | 10 | 11 | 12 | // NightFox LIB - Include de funciones de carga de archivos multimedia 13 | // Requiere DevkitARM 14 | // Codigo por Cesar Rincon "NightFox" 15 | // http://www.nightfoxandco.com/ 16 | // Version 20140413 17 | 18 | 19 | 20 | // Includes devKitPro 21 | #include 22 | 23 | 24 | 25 | 26 | 27 | // Funcion NF_LoadBMP(); 28 | void NF_LoadBMP(const char* file, u8 slot); 29 | // Carga un archivo BMP de 8, 16 o 24 bits en un slot de imagenes de 16 bits. 30 | // Debes inicializar el modo 16 bits, el backbuffer y usar la funcion NF_Draw16bitsImage(); 31 | // para mostrarlo. 32 | 33 | 34 | 35 | 36 | 37 | #endif 38 | 39 | #ifdef __cplusplus 40 | } 41 | #endif 42 | -------------------------------------------------------------------------------- /nflib/include/nf_mixedbg.h: -------------------------------------------------------------------------------- 1 | #ifdef __cplusplus 2 | extern "C" { 3 | #endif 4 | 5 | #ifndef __NF_MIXEDBG_H__ 6 | #define __NF_MIXEDBG_H__ 7 | 8 | 9 | 10 | 11 | 12 | // NightFox LIB - Include de Fondos mixtos (Tiled / Bitmap 8 bits) 13 | // Requiere DevkitARM 14 | // Codigo por Cesar Rincon "NightFox" 15 | // http://www.nightfoxandco.com/ 16 | // Version 20140413 17 | 18 | 19 | 20 | 21 | 22 | // Includes devKitPro 23 | #include 24 | 25 | 26 | 27 | // Funcion NF_InitMixedBgSys(); 28 | void NF_InitMixedBgSys(u8 screen); 29 | // Inicializa el modo mixto para fondo (Tiled BG + Bitmap 8 bits) 30 | // Capas 0 a 2 - Tiled 31 | // Capa 3 - Bitmap 8 bits 32 | 33 | 34 | 35 | 36 | 37 | #endif 38 | 39 | #ifdef __cplusplus 40 | } 41 | #endif 42 | -------------------------------------------------------------------------------- /nflib/include/nf_sound.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PolyMarsDev/Snake-DS/f121e33b2bab17d762f3bfd65ab5022ee365b9e3/nflib/include/nf_sound.h -------------------------------------------------------------------------------- /nflib/include/nf_sprite256.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PolyMarsDev/Snake-DS/f121e33b2bab17d762f3bfd65ab5022ee365b9e3/nflib/include/nf_sprite256.h -------------------------------------------------------------------------------- /nflib/include/nf_sprite3d.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PolyMarsDev/Snake-DS/f121e33b2bab17d762f3bfd65ab5022ee365b9e3/nflib/include/nf_sprite3d.h -------------------------------------------------------------------------------- /nflib/include/nf_text.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PolyMarsDev/Snake-DS/f121e33b2bab17d762f3bfd65ab5022ee365b9e3/nflib/include/nf_text.h -------------------------------------------------------------------------------- /nflib/include/nf_text16.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PolyMarsDev/Snake-DS/f121e33b2bab17d762f3bfd65ab5022ee365b9e3/nflib/include/nf_text16.h -------------------------------------------------------------------------------- /nflib/include/nf_tiledbg.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PolyMarsDev/Snake-DS/f121e33b2bab17d762f3bfd65ab5022ee365b9e3/nflib/include/nf_tiledbg.h -------------------------------------------------------------------------------- /nflib/lib/libnflib.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PolyMarsDev/Snake-DS/f121e33b2bab17d762f3bfd65ab5022ee365b9e3/nflib/lib/libnflib.a -------------------------------------------------------------------------------- /nitrofiles/backgrounds/bg.img: -------------------------------------------------------------------------------- 1 |  -------------------------------------------------------------------------------- /nitrofiles/backgrounds/bg.map: -------------------------------------------------------------------------------- 1 |  -------------------------------------------------------------------------------- /nitrofiles/backgrounds/bg.pal: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PolyMarsDev/Snake-DS/f121e33b2bab17d762f3bfd65ab5022ee365b9e3/nitrofiles/backgrounds/bg.pal -------------------------------------------------------------------------------- /nitrofiles/fonts/font.fnt: -------------------------------------------------------------------------------- 1 | GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG -------------------------------------------------------------------------------- /nitrofiles/fonts/font.pal: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PolyMarsDev/Snake-DS/f121e33b2bab17d762f3bfd65ab5022ee365b9e3/nitrofiles/fonts/font.pal -------------------------------------------------------------------------------- /nitrofiles/palettes/apple.pal: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PolyMarsDev/Snake-DS/f121e33b2bab17d762f3bfd65ab5022ee365b9e3/nitrofiles/palettes/apple.pal -------------------------------------------------------------------------------- /nitrofiles/palettes/apple_dropshadow.pal: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PolyMarsDev/Snake-DS/f121e33b2bab17d762f3bfd65ab5022ee365b9e3/nitrofiles/palettes/apple_dropshadow.pal -------------------------------------------------------------------------------- /nitrofiles/palettes/segment.pal: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PolyMarsDev/Snake-DS/f121e33b2bab17d762f3bfd65ab5022ee365b9e3/nitrofiles/palettes/segment.pal -------------------------------------------------------------------------------- /nitrofiles/palettes/segment_dropshadow.pal: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PolyMarsDev/Snake-DS/f121e33b2bab17d762f3bfd65ab5022ee365b9e3/nitrofiles/palettes/segment_dropshadow.pal -------------------------------------------------------------------------------- /nitrofiles/sprites/tile.img: -------------------------------------------------------------------------------- 1 |  -------------------------------------------------------------------------------- /source/apple.cpp: -------------------------------------------------------------------------------- 1 | #include "apple.h" 2 | #include 3 | #include 4 | Apple::Apple() 5 | { 6 | srand(time(NULL)); 7 | x = rand() % 32*8; 8 | y = rand() % 24*8; 9 | } 10 | 11 | int Apple::getX() 12 | { 13 | return x; 14 | } 15 | 16 | int Apple::getY() 17 | { 18 | return y; 19 | } 20 | 21 | void Apple::randomizePos() 22 | { 23 | x = rand() % 32*8; 24 | y = rand() % 24*8; 25 | } -------------------------------------------------------------------------------- /source/apple.h: -------------------------------------------------------------------------------- 1 | #ifndef APPLE_H 2 | #define APPLE_H 3 | 4 | class Apple 5 | { 6 | private: 7 | int x; 8 | int y; 9 | 10 | public: 11 | Apple(); 12 | int getX(); 13 | int getY(); 14 | void randomizePos(); 15 | }; 16 | 17 | #endif -------------------------------------------------------------------------------- /source/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "segment.h" 5 | #include "snake.h" 6 | 7 | const int up = 0; 8 | const int down = 1; 9 | const int left = 2; 10 | const int right = 3; 11 | 12 | Snake snake(4); 13 | int timer = 0; 14 | int direction = right; 15 | char score[32]; 16 | 17 | void updateScore() 18 | { 19 | sprintf(score, "SCORE: %d", snake.getScore()); 20 | NF_ClearTextLayer(0, 0); 21 | NF_WriteText(0, 0, 2, 2, score); 22 | NF_UpdateTextLayers(); 23 | } 24 | 25 | void reset() 26 | { 27 | for (int i = 0; i < snake.getSize()*2 + 2; i++) 28 | { 29 | NF_DeleteSprite(0, i); 30 | } 31 | snake = Snake(4); 32 | snake.randomizeApple(); 33 | timer = 0; 34 | direction = right; 35 | updateScore(); 36 | } 37 | 38 | int main(int argc, char **argv) 39 | { 40 | 41 | consoleDemoInit(); 42 | consoleClear(); 43 | NF_Set2D(0,0); 44 | NF_SetRootFolder("NITROFS"); 45 | 46 | NF_InitTiledBgBuffers(); 47 | NF_InitTiledBgSys(0); 48 | 49 | NF_LoadTiledBg("backgrounds/bg", "bg", 256, 256); 50 | NF_CreateTiledBg(0, 3, "bg"); 51 | 52 | NF_InitSpriteBuffers(); 53 | NF_InitSpriteSys(0); 54 | 55 | NF_LoadSpriteGfx("sprites/tile", 0, 8, 8); 56 | NF_LoadSpritePal("palettes/segment", 0); 57 | NF_LoadSpritePal("palettes/apple", 1); 58 | NF_LoadSpritePal("palettes/segment_dropshadow", 2); 59 | NF_LoadSpritePal("palettes/apple_dropshadow", 3); 60 | 61 | NF_VramSpriteGfx(0, 0, 0, true); 62 | NF_VramSpritePal(0, 0, 0); 63 | NF_VramSpritePal(0, 1, 1); 64 | NF_VramSpritePal(0, 2, 2); 65 | NF_VramSpritePal(0, 3, 3); 66 | 67 | NF_InitTextSys(0); 68 | 69 | NF_LoadTextFont("fonts/font", "default", 256, 256, 0); 70 | NF_CreateTextLayer(0, 0, 0, "default"); 71 | 72 | NF_WriteText(0, 0, 2, 2, "SCORE: 0"); 73 | NF_UpdateTextLayers(); 74 | 75 | while(1) 76 | { 77 | scanKeys(); 78 | 79 | if (keysHeld() & KEY_START) 80 | { 81 | break; 82 | } 83 | 84 | NF_CreateSprite(0, 0, 0, 1, snake.getApple().getX(), snake.getApple().getY()); 85 | for (int i = 0; i < snake.getSize(); i++) 86 | { 87 | NF_CreateSprite(0, i + 1, 0, 0, snake.getSegment(i).getX(), snake.getSegment(i).getY()); 88 | NF_CreateSprite(0, i + snake.getSize() + 1, 0, 2, snake.getSegment(i).getX(), snake.getSegment(i).getY() + 3); 89 | } 90 | NF_CreateSprite(0, snake.getSize()*2+1, 0, 3, snake.getApple().getX(), snake.getApple().getY() + 3); 91 | 92 | 93 | if (keysHeld() & KEY_UP) 94 | { 95 | if (direction != down) 96 | { 97 | direction = up; 98 | } 99 | } 100 | else if (keysHeld() & KEY_DOWN) 101 | { 102 | if (direction != up) 103 | { 104 | direction = down; 105 | } 106 | } 107 | else if (keysHeld() & KEY_LEFT) 108 | { 109 | if (direction != right) 110 | { 111 | direction = left; 112 | } 113 | } 114 | else if (keysHeld() & KEY_RIGHT) 115 | { 116 | if (direction != left) 117 | { 118 | direction = right; 119 | } 120 | } 121 | 122 | if (timer >= snake.getDelay()) 123 | { 124 | if (!snake.move(direction)) 125 | { 126 | reset(); 127 | } 128 | updateScore(); 129 | timer = 0; 130 | } 131 | else 132 | { 133 | timer += 1; 134 | } 135 | 136 | NF_SpriteOamSet(0); 137 | swiWaitForVBlank(); 138 | oamUpdate(&oamMain); 139 | } 140 | 141 | return 0; 142 | 143 | } 144 | -------------------------------------------------------------------------------- /source/segment.cpp: -------------------------------------------------------------------------------- 1 | #include "segment.h" 2 | Segment::Segment() 3 | { 4 | this->x = -8; 5 | this->y = -8; 6 | } 7 | 8 | int Segment::getX() 9 | { 10 | return x; 11 | } 12 | 13 | int Segment::getY() 14 | { 15 | return y; 16 | } 17 | 18 | void Segment::setPos(int x, int y) 19 | { 20 | this->x = x; 21 | this->y = y; 22 | } 23 | 24 | void Segment::move(int direction) 25 | { 26 | if (direction == up) 27 | { 28 | y -= 8; 29 | } 30 | else if (direction == down) 31 | { 32 | y += 8; 33 | } 34 | else if (direction == left) 35 | { 36 | x -= 8; 37 | } 38 | else if (direction == right) 39 | { 40 | x += 8; 41 | } 42 | } -------------------------------------------------------------------------------- /source/segment.h: -------------------------------------------------------------------------------- 1 | #ifndef SEGMENT_H 2 | #define SEGMENT_H 3 | class Segment 4 | { 5 | private: 6 | const int up = 0; 7 | const int down = 1; 8 | const int left = 2; 9 | const int right = 3; 10 | int x; 11 | int y; 12 | 13 | 14 | public: 15 | Segment(); 16 | int getX(); 17 | int getY(); 18 | void setPos(int x, int y); 19 | void move(int direction); 20 | }; 21 | #endif -------------------------------------------------------------------------------- /source/snake.cpp: -------------------------------------------------------------------------------- 1 | #include "snake.h" 2 | #include "segment.h" 3 | #include "apple.h" 4 | #include 5 | Snake::Snake(int size) 6 | { 7 | segments.push_back(Segment()); 8 | segments[0].setPos(8, 8); 9 | this->size = 1; 10 | score = 0; 11 | delay = 5; 12 | while (this->size < size) 13 | { 14 | grow(); 15 | } 16 | } 17 | 18 | int Snake::getX() 19 | { 20 | return segments[0].getX(); 21 | } 22 | 23 | int Snake::getY() 24 | { 25 | return segments[0].getY(); 26 | } 27 | 28 | int Snake::getSize() 29 | { 30 | return size; 31 | } 32 | 33 | int Snake::getScore() 34 | { 35 | return score; 36 | } 37 | 38 | int Snake::getDelay() 39 | { 40 | return delay; 41 | } 42 | 43 | bool Snake::hasApple() 44 | { 45 | return getX() == apple.getX() && getY() == apple.getY(); 46 | } 47 | 48 | void Snake::grow() 49 | { 50 | size += 1; 51 | segments.resize(size); 52 | } 53 | 54 | bool Snake::hasSegment(int x, int y, bool includeHead) 55 | { 56 | int startIndex = 1; 57 | if (includeHead) 58 | { 59 | startIndex = 0; 60 | } 61 | for (int i = startIndex; i < size; i++) 62 | { 63 | if (x == segments[i].getX() && y == segments[i].getY()) 64 | { 65 | return true; 66 | } 67 | } 68 | return false; 69 | } 70 | 71 | Segment Snake::getSegment(int index) 72 | { 73 | return segments[index]; 74 | } 75 | 76 | Apple Snake::getApple() 77 | { 78 | return apple; 79 | } 80 | 81 | void Snake::randomizeApple() 82 | { 83 | apple.randomizePos(); 84 | while (hasSegment(apple.getX(), apple.getY(), true)) 85 | { 86 | apple.randomizePos(); 87 | } 88 | } 89 | 90 | bool Snake::move(int direction) 91 | { 92 | for (int i = size - 1; i >= 1; i--) 93 | { 94 | segments[i].setPos(segments[i - 1].getX(), segments[i - 1].getY()); 95 | } 96 | segments[0].move(direction); 97 | if (hasSegment(getX(), getY(), false) || getX() < 0 || getX() + 8 > 256 || getY() < 0 || getY() + 8 > 192) 98 | { 99 | return false; 100 | } 101 | if (hasApple()) 102 | { 103 | if (size < 62) 104 | { 105 | grow(); 106 | } 107 | score += 1; 108 | if (delay > 3) 109 | { 110 | delay -= .25; 111 | } 112 | randomizeApple(); 113 | } 114 | return true; 115 | } -------------------------------------------------------------------------------- /source/snake.h: -------------------------------------------------------------------------------- 1 | #ifndef SNAKE_H 2 | #define SNAKE_H 3 | 4 | #include "segment.h" 5 | #include "apple.h" 6 | #include 7 | class Snake 8 | { 9 | private: 10 | int size; 11 | int score; 12 | int delay; 13 | std::vector segments; 14 | Apple apple; 15 | 16 | public: 17 | Snake(int size); 18 | int getX(); 19 | int getY(); 20 | int getSize(); 21 | int getScore(); 22 | int getDelay(); 23 | bool hasApple(); 24 | void grow(); 25 | bool hasSegment(int x, int y, bool includeHead); 26 | Segment getSegment(int index); 27 | Apple getApple(); 28 | void randomizeApple(); 29 | bool move(int direction); 30 | }; 31 | #endif --------------------------------------------------------------------------------