From b6e7e454ed6242475163dcd534051897d3c9158c Mon Sep 17 00:00:00 2001 From: lamp Date: Sun, 5 Mar 2023 21:25:03 +0000 Subject: init --- src/backgrounds/background.c | 42 ++++++ src/backgrounds/game_over.c | 44 ++++++ src/backgrounds/game_over_map.c | 63 ++++++++ src/backgrounds/map.c | 75 ++++++++++ src/backgrounds/numerals.c | 65 +++++++++ src/main.c | 312 ++++++++++++++++++++++++++++++++++++++++ src/metasprite.c | 52 +++++++ src/pipe.c | 84 +++++++++++ src/sprites/bird.c | 39 +++++ src/sprites/button.c | 39 +++++ src/sprites/pipe.c | 34 +++++ 11 files changed, 849 insertions(+) create mode 100644 src/backgrounds/background.c create mode 100644 src/backgrounds/game_over.c create mode 100644 src/backgrounds/game_over_map.c create mode 100644 src/backgrounds/map.c create mode 100644 src/backgrounds/numerals.c create mode 100644 src/main.c create mode 100644 src/metasprite.c create mode 100644 src/pipe.c create mode 100644 src/sprites/bird.c create mode 100644 src/sprites/button.c create mode 100644 src/sprites/pipe.c (limited to 'src') diff --git a/src/backgrounds/background.c b/src/backgrounds/background.c new file mode 100644 index 0000000..35bb0ea --- /dev/null +++ b/src/backgrounds/background.c @@ -0,0 +1,42 @@ +/* + + EXPORT.C + + Tile Source File. + + Info: + Form : All tiles as one unit. + Format : Gameboy 4 color. + Compression : None. + Counter : None. + Tile size : 8 x 8 + Tiles : 0 to 8 + + Palette colors : None. + SGB Palette : None. + CGB Palette : None. + + Convert to metatiles : No. + + This file was generated by GBTD v2.2 + +*/ + +/* Start of tile array. */ +const unsigned char BG_TILE_DATA[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xF8, 0x07, 0xF1, 0x0E, + 0xE3, 0x1C, 0xC7, 0x38, 0x8F, 0x70, 0x1F, 0xE0, 0xFF, 0xFF, 0x00, 0xFF, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x3F, 0xC0, 0xCF, 0x30, 0xF7, 0x08, + 0xF6, 0x09, 0xF9, 0x06, 0xFB, 0x04, 0xFF, 0x00, 0x7F, 0x80, 0xBC, 0x43, + 0xB3, 0x4C, 0x87, 0x78, 0x79, 0x86, 0xFE, 0x01, 0xFF, 0x00, 0xFF, 0x00, + 0x00, 0x99, 0x18, 0xE7, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x7F, 0x80, + 0xBF, 0x40, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x70, 0x70, 0x8F, 0xFC, 0x03, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0x0C, 0xFC, 0x03, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01}; + +/* End of EXPORT.C */ diff --git a/src/backgrounds/game_over.c b/src/backgrounds/game_over.c new file mode 100644 index 0000000..b1ddac3 --- /dev/null +++ b/src/backgrounds/game_over.c @@ -0,0 +1,44 @@ +/* + + EXPORT.C + + Tile Source File. + + Info: + Form : All tiles as one unit. + Format : Gameboy 4 color. + Compression : None. + Counter : None. + Tile size : 8 x 8 + Tiles : 0 to 10 + + Palette colors : None. + SGB Palette : None. + CGB Palette : None. + + Convert to metatiles : No. + + This file was generated by GBTD v2.2 + +*/ + +/* Start of tile array. */ +const unsigned char GAME_OVER_TILE_DATA[] = { + 0x7E, 0x7E, 0x7E, 0x7E, 0x60, 0x60, 0x6E, 0x6E, 0x6E, 0x6E, 0x62, 0x62, + 0x7E, 0x7E, 0x7E, 0x7E, 0x18, 0x18, 0x3C, 0x3C, 0x66, 0x66, 0x66, 0x66, + 0x7E, 0x7E, 0x7E, 0x7E, 0x66, 0x66, 0x66, 0x66, 0x7F, 0x7F, 0x7F, 0x7F, + 0x6B, 0x6B, 0x6B, 0x6B, 0x6B, 0x6B, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, + 0x7E, 0x7E, 0x7E, 0x7E, 0x60, 0x60, 0x7E, 0x7E, 0x7E, 0x7E, 0x60, 0x60, + 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x66, 0x66, 0x66, 0x66, + 0x66, 0x66, 0x66, 0x66, 0x7E, 0x7E, 0x7E, 0x7E, 0x66, 0x66, 0x66, 0x66, + 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x3C, 0x3C, 0x18, 0x18, + 0x7C, 0x7C, 0x7E, 0x7E, 0x66, 0x66, 0x66, 0x66, 0x7E, 0x7E, 0x7C, 0x7C, + 0x6E, 0x6E, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x7E, 0x7E, + 0x7E, 0x7E, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x7E, 0x7E, 0x7E, 0x7E, + 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x7E, 0x7E, 0x7E, 0x7E, + 0x7E, 0x7E, 0x7E, 0x7E, 0x60, 0x60, 0x7E, 0x7E, 0x7E, 0x7E, 0x06, 0x06, + 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x7E, 0x60, 0x60, 0x60, 0x60, + 0x60, 0x60, 0x60, 0x60, 0x7E, 0x7E, 0x7E, 0x7E, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + +/* End of EXPORT.C */ diff --git a/src/backgrounds/game_over_map.c b/src/backgrounds/game_over_map.c new file mode 100644 index 0000000..53febab --- /dev/null +++ b/src/backgrounds/game_over_map.c @@ -0,0 +1,63 @@ +/* + + GAME_OVER_MAP.C + + Map Source File. + + Info: + Section : + Bank : 0 + Map size : 10 x 7 + Tile set : + Z:\var\home\matthew\Documents\Projects\flappy-gb\res\game_over.gbr Plane count + : 1 plane (8 bits) Plane order : Tiles are continues Tile offset : 0 Split + data : No + + This file was generated by GBMB v1.8 + +*/ + +#include "backgrounds/game_over_map.h" + +#define GAME_OVER_MAPWidth 10 +#define GAME_OVER_MAPHeight 7 +#define GAME_OVER_MAPBank 0 + +const unsigned char GAME_OVER_MAP[] = { + GAME_OVER_TILE_START + 0x00, GAME_OVER_TILE_START + 0x01, + GAME_OVER_TILE_START + 0x02, GAME_OVER_TILE_START + 0x03, + GAME_OVER_TILE_START + 0x0B, GAME_OVER_TILE_START + 0x04, + GAME_OVER_TILE_START + 0x05, GAME_OVER_TILE_START + 0x03, + GAME_OVER_TILE_START + 0x06, GAME_OVER_TILE_START + 0x0B, + GAME_OVER_TILE_START + 0x0B, GAME_OVER_TILE_START + 0x0B, + GAME_OVER_TILE_START + 0x0B, GAME_OVER_TILE_START + 0x0B, + GAME_OVER_TILE_START + 0x0B, GAME_OVER_TILE_START + 0x0B, + GAME_OVER_TILE_START + 0x0B, GAME_OVER_TILE_START + 0x0B, + GAME_OVER_TILE_START + 0x0B, GAME_OVER_TILE_START + 0x0B, + GAME_OVER_TILE_START + 0x09, GAME_OVER_TILE_START + 0x0A, + GAME_OVER_TILE_START + 0x04, GAME_OVER_TILE_START + 0x06, + GAME_OVER_TILE_START + 0x03, GAME_OVER_TILE_START + 0x0B, + GAME_OVER_TILE_START + 0x0B, GAME_OVER_TILE_START + 0x0B, + GAME_OVER_TILE_START + 0x0B, GAME_OVER_TILE_START + 0x0B, + GAME_OVER_TILE_START + 0x0B, GAME_OVER_TILE_START + 0x0B, + GAME_OVER_TILE_START + 0x0B, GAME_OVER_TILE_START + 0x0B, + GAME_OVER_TILE_START + 0x0B, GAME_OVER_TILE_START + 0x0B, + GAME_OVER_TILE_START + 0x0B, GAME_OVER_TILE_START + 0x0B, + GAME_OVER_TILE_START + 0x0B, GAME_OVER_TILE_START + 0x0B, + GAME_OVER_TILE_START + 0x0B, GAME_OVER_TILE_START + 0x0B, + GAME_OVER_TILE_START + 0x0B, GAME_OVER_TILE_START + 0x0B, + GAME_OVER_TILE_START + 0x0B, GAME_OVER_TILE_START + 0x0B, + GAME_OVER_TILE_START + 0x0B, GAME_OVER_TILE_START + 0x0B, + GAME_OVER_TILE_START + 0x0B, GAME_OVER_TILE_START + 0x0B, + GAME_OVER_TILE_START + 0x0B, GAME_OVER_TILE_START + 0x0B, + GAME_OVER_TILE_START + 0x0B, GAME_OVER_TILE_START + 0x0B, + GAME_OVER_TILE_START + 0x0B, GAME_OVER_TILE_START + 0x0B, + GAME_OVER_TILE_START + 0x0B, GAME_OVER_TILE_START + 0x0B, + GAME_OVER_TILE_START + 0x0B, GAME_OVER_TILE_START + 0x0B, + GAME_OVER_TILE_START + 0x07, GAME_OVER_TILE_START + 0x08, + GAME_OVER_TILE_START + 0x00, GAME_OVER_TILE_START + 0x07, + GAME_OVER_TILE_START + 0x0B, GAME_OVER_TILE_START + 0x09, + GAME_OVER_TILE_START + 0x0A, GAME_OVER_TILE_START + 0x04, + GAME_OVER_TILE_START + 0x06, GAME_OVER_TILE_START + 0x03}; + +/* End of GAME_OVER_MAP.C */ diff --git a/src/backgrounds/map.c b/src/backgrounds/map.c new file mode 100644 index 0000000..9f6a660 --- /dev/null +++ b/src/backgrounds/map.c @@ -0,0 +1,75 @@ +/* + + MAP.C + + Map Source File. + + Info: + Section : + Bank : 0 + Map size : 31 x 17 + Tile set : Z:\var\home\matthew\Documents\Projects\flappy-gb\res\bg.gbr + Plane count : 1 plane (8 bits) + Plane order : Tiles are continues + Tile offset : 0 + Split data : No + + This file was generated by GBMB v1.8 + +*/ + +#define BG_TILE_MAPWidth 32 +#define BG_TILE_MAPHeight 18 +#define BG_TILE_MAPBank 0 + +const unsigned char BG_TILE_MAP[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x07, 0x08, 0x09, 0x07, 0x08, 0x09, 0x07, 0x08, 0x09, 0x07, 0x08, 0x09, + 0x07, 0x08, 0x09, 0x07, 0x08, 0x09, 0x07, 0x08, 0x09, 0x07, 0x08, 0x09, + 0x07, 0x08, 0x09, 0x07, 0x08, 0x09, 0x07, 0x08, 0x04, 0x05, 0x06, 0x04, + 0x05, 0x06, 0x04, 0x05, 0x06, 0x04, 0x05, 0x06, 0x04, 0x05, 0x06, 0x04, + 0x05, 0x06, 0x04, 0x05, 0x06, 0x04, 0x05, 0x06, 0x04, 0x05, 0x06, 0x04, + 0x05, 0x06, 0x04, 0x05, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, + 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, + 0x02, 0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03}; + +/* End of MAP.C */ diff --git a/src/backgrounds/numerals.c b/src/backgrounds/numerals.c new file mode 100644 index 0000000..c8aa6a7 --- /dev/null +++ b/src/backgrounds/numerals.c @@ -0,0 +1,65 @@ +/* + + EXPORT.C + + Tile Source File. + + Info: + Form : All tiles as one unit. + Format : Gameboy 4 color. + Compression : None. + Counter : None. + Tile size : 8 x 8 + Tiles : 0 to 10 + + Palette colors : None. + SGB Palette : None. + CGB Palette : None. + + Convert to metatiles : No. + + This file was generated by GBTD v2.2 + +*/ + +#include "backgrounds/numerals.h" + +/* Start of tile array. */ +const unsigned char NUMERALS_TILE_DATA[] = { + 0xFF, 0x7E, 0xFF, 0x7E, 0xFF, 0x66, 0xFF, 0x66, 0xFF, 0x66, 0xFF, 0x66, + 0xFF, 0x7E, 0xFF, 0x7E, 0xFF, 0x1C, 0xFF, 0x3C, 0xFF, 0x7C, 0xFF, 0x0C, + 0xFF, 0x0C, 0xFF, 0x0C, 0xFF, 0x7E, 0xFF, 0x7E, 0xFF, 0x7E, 0xFF, 0x7E, + 0xFF, 0x06, 0xFF, 0x7E, 0xFF, 0x7E, 0xFF, 0x60, 0xFF, 0x7E, 0xFF, 0x7E, + 0xFF, 0x7E, 0xFF, 0x7E, 0xFF, 0x06, 0xFF, 0x7E, 0xFF, 0x7E, 0xFF, 0x06, + 0xFF, 0x7E, 0xFF, 0x7E, 0xFF, 0x60, 0xFF, 0x60, 0xFF, 0x60, 0xFF, 0x6C, + 0xFF, 0x6C, 0xFF, 0x7E, 0xFF, 0x7E, 0xFF, 0x0C, 0xFF, 0x7E, 0xFF, 0x7E, + 0xFF, 0x60, 0xFF, 0x7C, 0xFF, 0x7E, 0xFF, 0x06, 0xFF, 0x7E, 0xFF, 0x7C, + 0xFF, 0x7E, 0xFF, 0x7E, 0xFF, 0x60, 0xFF, 0x7E, 0xFF, 0x7E, 0xFF, 0x66, + 0xFF, 0x7E, 0xFF, 0x7E, 0xFF, 0x7E, 0xFF, 0x7E, 0xFF, 0x06, 0xFF, 0x0E, + 0xFF, 0x1C, 0xFF, 0x38, 0xFF, 0x30, 0xFF, 0x30, 0xFF, 0x7E, 0xFF, 0x7E, + 0xFF, 0x66, 0xFF, 0x7E, 0xFF, 0x7E, 0xFF, 0x66, 0xFF, 0x7E, 0xFF, 0x7E, + 0xFF, 0x7E, 0xFF, 0x7E, 0xFF, 0x66, 0xFF, 0x7E, 0xFF, 0x7E, 0xFF, 0x06, + 0xFF, 0x06, 0xFF, 0x06, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00}; + +const unsigned char NUMERALS_TILE_MAP[] = { + BLANK_NUMERAL_TILE, BLANK_NUMERAL_TILE, BLANK_NUMERAL_TILE, + BLANK_NUMERAL_TILE, BLANK_NUMERAL_TILE, BLANK_NUMERAL_TILE, + BLANK_NUMERAL_TILE, BLANK_NUMERAL_TILE, BLANK_NUMERAL_TILE, + BLANK_NUMERAL_TILE, BLANK_NUMERAL_TILE, BLANK_NUMERAL_TILE, + BLANK_NUMERAL_TILE, BLANK_NUMERAL_TILE, BLANK_NUMERAL_TILE, + BLANK_NUMERAL_TILE, BLANK_NUMERAL_TILE, BLANK_NUMERAL_TILE, + BLANK_NUMERAL_TILE, BLANK_NUMERAL_TILE, BLANK_NUMERAL_TILE, + BLANK_NUMERAL_TILE, BLANK_NUMERAL_TILE, BLANK_NUMERAL_TILE, + BLANK_NUMERAL_TILE, BLANK_NUMERAL_TILE, BLANK_NUMERAL_TILE, + BLANK_NUMERAL_TILE, BLANK_NUMERAL_TILE, BLANK_NUMERAL_TILE, + BLANK_NUMERAL_TILE, BLANK_NUMERAL_TILE, BLANK_NUMERAL_TILE, + BLANK_NUMERAL_TILE, BLANK_NUMERAL_TILE, BLANK_NUMERAL_TILE, + BLANK_NUMERAL_TILE, BLANK_NUMERAL_TILE, BLANK_NUMERAL_TILE, + BLANK_NUMERAL_TILE}; + +const unsigned char NUMERALS_TILE_CLEAR[] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + +/* End of EXPORT.C */ diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..ad92978 --- /dev/null +++ b/src/main.c @@ -0,0 +1,312 @@ +#include +#include +#include +#include + +#include "backgrounds/background.h" +#include "backgrounds/game_over.h" +#include "backgrounds/game_over_map.h" +#include "backgrounds/map.h" +#include "backgrounds/numerals.h" +#include "defines.h" +#include "metasprite.h" +#include "pipe.h" +#include "sprites/bird.h" +#include "sprites/button.h" +#include "sprites/pipe.h" + +UINT8 g_background_position = 0; +UINT8 g_foreground_position = 0; +BCD g_player_score = 0; +BCD g_player_high_score = 0; +UINT8 g_foreground_scroll_speed = FOREGROUND_SCROLL_SPEED; +Metasprite g_bird = { + .x = 30, + .y = 70, + .width = BIRD_WIDTH, + .height = BIRD_HEIGHT, + .velocity_x = 0, + .velocity_y = 0, + .sprite_ids = {0, 1, 2, 3}, + .tile_ids = {0, 1, 2, 3}, +}; + +Metasprite g_button = {.x = 80, + .y = 68, + .width = 16, + .height = 16, + .velocity_x = 0, + .velocity_y = 0, + .sprite_ids = {4, 5, 6, 7}, + .tile_ids = {BUTTON_TILE_START, BUTTON_TILE_START + 1, + BUTTON_TILE_START + 2, + BUTTON_TILE_START + 3}}; + +void on_hbl_interrupt() { + switch (LYC_REG) { + case 0x00: + move_bkg(g_background_position, 0); + LYC_REG = 0x78; + break; + case 0x78: + move_bkg(g_foreground_position, 0); + LYC_REG = 0x00; + break; + } +} + +static inline void wait_frames(UINT8 frames) { + static UINT8 wait_counter = 0; + for (wait_counter = frames; wait_counter != 0; wait_counter--) { + wait_vbl_done(); + } +} + +inline void wait_for_button_press(UINT8 mask) { + while (!(joypad() & mask)) { + wait_vbl_done(); + } +} + +static inline void display_score() { + static UINT8 text_buffer[9]; + bcd2text(&g_player_score, NUMERALS_TILE_START, text_buffer); + static UINT8 count; + for (count = 0; count < 7; count++) { + if (text_buffer[count] == NUMERALS_TILE_START) { + text_buffer[count] = NUMERALS_TILE_START + 10; + } else { + break; + } + } + move_win(WINDOW_CENTERING_OFFSET + (((7 - count) * TILE_SIZE) / 2), 133); + set_win_tiles(0, 0, 8, 1, text_buffer); +} + +static inline void update_bird_animation_state() { + static UINT8 current_animation_frame = 0; + switch (current_animation_frame) { + case 0: + g_bird.tile_ids[0] = 0; + g_bird.tile_ids[1] = 1; + current_animation_frame = 1; + break; + case 1: + g_bird.tile_ids[0] = 4; + g_bird.tile_ids[1] = 5; + current_animation_frame = 2; + break; + case 2: + g_bird.tile_ids[0] = 6; + g_bird.tile_ids[1] = 7; + current_animation_frame = 0; + break; + } + metasprite_update_tiles(&g_bird); +} + +static inline void update_button_animation_state() { + static UINT8 current_animation_frame = 0; + switch (current_animation_frame) { + case 0: + g_button.tile_ids[0] = BUTTON_TILE_START + 4; + g_button.tile_ids[1] = BUTTON_TILE_START + 5; + g_button.tile_ids[2] = BUTTON_TILE_START + 6; + g_button.tile_ids[3] = BUTTON_TILE_START + 7; + current_animation_frame = 1; + break; + case 1: + g_button.tile_ids[0] = BUTTON_TILE_START; + g_button.tile_ids[1] = BUTTON_TILE_START + 1; + g_button.tile_ids[2] = BUTTON_TILE_START + 2; + g_button.tile_ids[3] = BUTTON_TILE_START + 3; + current_animation_frame = 0; + break; + } + metasprite_update_tiles(&g_button); +} + +inline void play_death_flash() { + BGP_REG = 0x90; + OBP0_REG = 0x90; + wait_frames(3); + BGP_REG = 0x40; + OBP0_REG = 0x40; + wait_frames(3); + BGP_REG = 0x00; + OBP0_REG = 0x00; + wait_frames(3); + BGP_REG = 0x40; + OBP0_REG = 0x40; + wait_frames(3); + BGP_REG = 0x90; + OBP0_REG = 0x90; + wait_frames(3); + BGP_REG = 0xE4; + OBP0_REG = 0xE4; +} + +inline void play_jump_sound() { + NR10_REG = 0x16; + NR11_REG = 0x40; + NR12_REG = 0x73; + NR13_REG = 0x00; + NR14_REG = 0xC3; +} + +void main(void) { + // Init sound + NR52_REG = 0x80; + NR50_REG = 0x77; + NR51_REG = 0xFF; + // Load Background + set_bkg_data(0, 10, BG_TILE_DATA); + set_bkg_data(NUMERALS_TILE_START, NUMERALS_TILE_START + 10, + NUMERALS_TILE_DATA); + set_bkg_data(GAME_OVER_TILE_START, GAME_OVER_TILE_START + 10, + GAME_OVER_TILE_DATA); + set_bkg_tiles(0, 0, BG_TILE_MAPWidth, BG_TILE_MAPHeight, BG_TILE_MAP); + // Load tiles into VRAM + set_sprite_data(0, 8, BIRD_TILE_DATA); + set_sprite_data(PIPE_TILE_START, PIPE_TILE_START + 4, PIPE_TILE_DATA); + set_sprite_data(BUTTON_TILE_START, BUTTON_TILE_START + 7, BUTTON_TILE_DATA); + + STAT_REG = 0x45; // Enable H-Blank Interrupt + LYC_REG = 0x00; + + disable_interrupts(); + add_LCD(on_hbl_interrupt); + enable_interrupts(); + + set_interrupts(VBL_IFLAG | LCD_IFLAG); + + metasprite_init(&g_bird); + + SHOW_BKG; + SHOW_SPRITES; + SHOW_WIN; + DISPLAY_ON; + + while (true) { + + metasprite_move_to(&g_bird, 30, 70); + set_win_tiles(0, 0, 20, 2, NUMERALS_TILE_MAP); + g_player_score = 0; + display_score(); + metasprite_init(&g_button); + + static UINT8 last_button_state; + static UINT8 button_state; + static UINT8 frame_count = 0; + while (true) { + button_state = joypad(); + if (button_state & J_A) { + play_jump_sound(); + metasprite_jump(&g_bird); + last_button_state = button_state; + break; + } + if (frame_count % CYCLE_ANIMATION_N_FRAMES == 0) { + update_bird_animation_state(); + } + if (frame_count % CYCLE_BUTTON_N_FRAMES == 0) { + update_button_animation_state(); + } + frame_count += 1; + g_background_position += BACKGROUND_SCROLL_SPEED; + g_foreground_position += g_foreground_scroll_speed; + wait_vbl_done(); + } + + initrand(DIV_REG); + + static Pipe pipe; + pipe.x = 200; + pipe.gap_skip = 8; + for (UINT8 i = 0; i < 36; i++) { + pipe.sprite_ids[i] = i + 4; + } + pipe_init(&pipe); + pipe_move_gap_height(&pipe, 2 + (((UINT8)rand()) % (15 - pipe.gap_skip))); + + while (true) { + pipe_scroll_horizontal(&pipe, -1 * g_foreground_scroll_speed); + if (pipe.x == 0xF0) { + static const BCD score_per_pipe = 1; + static BCD *const spp_ref = &score_per_pipe; + + bcd_add(&g_player_score, spp_ref); + display_score(); + switch (g_player_score) { + case 0x20: + pipe.gap_skip = 7; + break; + case 0x35: + pipe.gap_skip = 6; + break; + case 0x50: + g_foreground_scroll_speed = 3; + break; + } + pipe_move_gap_height(&pipe, + 2 + (((UINT8)rand()) % (15 - pipe.gap_skip))); + pipe_scroll_horizontal(&pipe, -78); + } + button_state = joypad(); + if ((button_state & J_A) && !(last_button_state & J_A)) { + play_jump_sound(); + metasprite_jump(&g_bird); + } + if (frame_count % APPLY_GRAVITY_N_FRAMES == 0) { + metasprite_apply_gravity(&g_bird); + } + if (frame_count % CYCLE_ANIMATION_N_FRAMES == 0) { + update_bird_animation_state(); + } + frame_count += 1; + g_background_position += BACKGROUND_SCROLL_SPEED; + g_foreground_position += g_foreground_scroll_speed; + metasprite_update_position_using_velocity(&g_bird); + if (g_bird.y < 0x05) { + g_bird.y = 0x05; + g_bird.velocity_y = 0x00; + } + if (g_bird.y + g_bird.height > 0x85) { + break; + } + if (g_bird.x > (pipe.x - g_bird.width) && + g_bird.x < pipe.x + PIPE_WIDTH) { + if (g_bird.y < ((pipe.height_of_gap + 1) * TILE_SIZE) || + g_bird.y + g_bird.height > ((pipe.height_of_gap * TILE_SIZE) + + (pipe.gap_skip * TILE_SIZE))) { + break; + } + } + last_button_state = button_state; + wait_vbl_done(); + } + play_death_flash(); + pipe_hide(&pipe); + metasprite_hide(&g_bird); + set_sprite_prop(g_button.sprite_ids[0], 0); + set_sprite_prop(g_button.sprite_ids[1], 0); + set_sprite_prop(g_button.sprite_ids[2], 0); + set_sprite_prop(g_button.sprite_ids[3], 0); + g_foreground_scroll_speed = FOREGROUND_SCROLL_SPEED; + if (g_player_score > g_player_high_score) { + g_player_high_score = g_player_score; + } + static UINT8 score_buffer[9]; + static UINT8 high_score_buffer[9]; + bcd2text(&g_player_score, NUMERALS_TILE_START, score_buffer); + bcd2text(&g_player_high_score, NUMERALS_TILE_START, high_score_buffer); + BGP_REG = 0xC0; + set_win_tiles(0, 0, 20, 2, NUMERALS_TILE_CLEAR); + set_win_tiles(6, 4, GAME_OVER_MAPWidth, GAME_OVER_MAPHeight, GAME_OVER_MAP); + set_win_tiles(6, 8, 8, 1, score_buffer); + set_win_tiles(6, 12, 8, 1, high_score_buffer); + move_win(0, 0); + wait_frames(180); + BGP_REG = 0xE4; + } +} diff --git a/src/metasprite.c b/src/metasprite.c new file mode 100644 index 0000000..262d1c4 --- /dev/null +++ b/src/metasprite.c @@ -0,0 +1,52 @@ +#include "metasprite.h" + +inline void metasprite_init(Metasprite *metasprite) { + metasprite_update_tiles(metasprite); + metasprite_move_to(metasprite, metasprite->x, metasprite->y); +} + +inline void metasprite_move_offset(Metasprite *metasprite, + ScreenCoordinate offset_x, + ScreenCoordinate offset_y) { + metasprite_move_to(metasprite, metasprite->x + offset_x, + metasprite->y + offset_y); +} + +// TODO: consider height and width +inline void metasprite_move_to(Metasprite *metasprite, ScreenCoordinate new_x, + ScreenCoordinate new_y) { + metasprite->x = new_x; + metasprite->y = new_y; + move_sprite(metasprite->sprite_ids[0], new_x, new_y); + move_sprite(metasprite->sprite_ids[1], new_x, new_y + TILE_SIZE); + move_sprite(metasprite->sprite_ids[2], new_x + TILE_SIZE, new_y); + move_sprite(metasprite->sprite_ids[3], new_x + TILE_SIZE, new_y + TILE_SIZE); +} + +inline void metasprite_apply_gravity(Metasprite *metasprite) { + metasprite->velocity_y += GRAVITY_ACCELERATION; +} + +inline void metasprite_update_position_using_velocity(Metasprite *metasprite) { + metasprite->x += metasprite->velocity_x; + metasprite->y += metasprite->velocity_y; + metasprite_move_to(metasprite, metasprite->x, metasprite->y); +} + +inline void metasprite_jump(Metasprite *metasprite) { + metasprite->velocity_y = JUMP_VELOCITY; +} + +inline void metasprite_update_tiles(Metasprite *metasprite) { + set_sprite_tile(metasprite->sprite_ids[0], metasprite->tile_ids[0]); + set_sprite_tile(metasprite->sprite_ids[1], metasprite->tile_ids[1]); + set_sprite_tile(metasprite->sprite_ids[2], metasprite->tile_ids[2]); + set_sprite_tile(metasprite->sprite_ids[3], metasprite->tile_ids[3]); +} + +inline void metasprite_hide(Metasprite *metasprite) { + move_sprite(metasprite->sprite_ids[0], 0, 0); + move_sprite(metasprite->sprite_ids[1], 0, 0); + move_sprite(metasprite->sprite_ids[2], 0, 0); + move_sprite(metasprite->sprite_ids[3], 0, 0); +} diff --git a/src/pipe.c b/src/pipe.c new file mode 100644 index 0000000..ff9656d --- /dev/null +++ b/src/pipe.c @@ -0,0 +1,84 @@ +#include "pipe.h" +#include "defines.h" + +inline void pipe_init(Pipe *pipe) { + set_sprite_tile(pipe->sprite_ids[PIPE_TILE_TOP_LEFT], + PIPE_TILE_START + CAP_LEFT); + set_sprite_prop(pipe->sprite_ids[PIPE_TILE_TOP_LEFT], S_FLIPY); + + set_sprite_tile(pipe->sprite_ids[PIPE_TILE_TOP_MIDDLE], + PIPE_TILE_START + CAP_MIDDLE); + set_sprite_prop(pipe->sprite_ids[PIPE_TILE_TOP_MIDDLE], S_FLIPY); + + set_sprite_tile(pipe->sprite_ids[PIPE_TILE_TOP_RIGHT], + PIPE_TILE_START + CAP_LEFT); + set_sprite_prop(pipe->sprite_ids[PIPE_TILE_TOP_RIGHT], S_FLIPX | S_FLIPY); + + set_sprite_tile(pipe->sprite_ids[PIPE_TILE_BOTTOM_LEFT], + PIPE_TILE_START + CAP_LEFT); + + set_sprite_tile(pipe->sprite_ids[PIPE_TILE_BOTTOM_MIDDLE], + PIPE_TILE_START + CAP_MIDDLE); + + set_sprite_tile(pipe->sprite_ids[PIPE_TILE_BOTTOM_RIGHT], + PIPE_TILE_START + CAP_LEFT); + set_sprite_prop(pipe->sprite_ids[PIPE_TILE_BOTTOM_RIGHT], S_FLIPX); + + for (UINT8 i = 6; i < 16; i++) { + set_sprite_tile(pipe->sprite_ids[i], PIPE_TILE_START + MAIN_LEFT); + } + for (UINT8 i = 16; i < 26; i++) { + set_sprite_tile(pipe->sprite_ids[i], PIPE_TILE_START + MAIN_MIDDLE); + } + for (UINT8 i = 26; i < 36; i++) { + set_sprite_tile(pipe->sprite_ids[i], PIPE_TILE_START + MAIN_LEFT); + set_sprite_prop(pipe->sprite_ids[i], S_FLIPX); + } +} + +inline void pipe_scroll_horizontal(Pipe *pipe, ScreenCoordinate x) { + pipe->x += x; + for (UINT8 i = 36; i != 0; i--) { + scroll_sprite(pipe->sprite_ids[i - 1], x, 0); + } +} + +inline void pipe_move_gap_height(Pipe *pipe, UINT8 gap_height) { + pipe->height_of_gap = gap_height; + for (UINT8 i = 0; i < gap_height; i++) { + move_sprite(pipe->sprite_ids[i + 4], pipe->x, i * TILE_SIZE); + move_sprite(pipe->sprite_ids[i + 14], pipe->x + TILE_SIZE, i * TILE_SIZE); + move_sprite(pipe->sprite_ids[i + 24], pipe->x + TILE_SIZE + TILE_SIZE, + i * TILE_SIZE); + } + move_sprite(pipe->sprite_ids[PIPE_TILE_TOP_LEFT], pipe->x, + gap_height * TILE_SIZE); + move_sprite(pipe->sprite_ids[PIPE_TILE_TOP_MIDDLE], pipe->x + TILE_SIZE, + gap_height * TILE_SIZE); + move_sprite(pipe->sprite_ids[PIPE_TILE_TOP_RIGHT], + pipe->x + TILE_SIZE + TILE_SIZE, gap_height * TILE_SIZE); + + move_sprite(pipe->sprite_ids[PIPE_TILE_BOTTOM_LEFT], pipe->x, + (gap_height + pipe->gap_skip) * TILE_SIZE); + move_sprite(pipe->sprite_ids[PIPE_TILE_BOTTOM_MIDDLE], pipe->x + TILE_SIZE, + (gap_height + pipe->gap_skip) * TILE_SIZE); + move_sprite(pipe->sprite_ids[PIPE_TILE_BOTTOM_RIGHT], + pipe->x + TILE_SIZE + TILE_SIZE, + (gap_height + pipe->gap_skip) * TILE_SIZE); + + for (UINT8 i = gap_height; i < (16 - pipe->gap_skip); i++) { + move_sprite(pipe->sprite_ids[i + 4], pipe->x, + (i + pipe->gap_skip + 1) * TILE_SIZE); + move_sprite(pipe->sprite_ids[i + 14], pipe->x + TILE_SIZE, + (i + pipe->gap_skip + 1) * TILE_SIZE); + move_sprite(pipe->sprite_ids[i + 24], pipe->x + TILE_SIZE + TILE_SIZE, + (i + pipe->gap_skip + 1) * TILE_SIZE); + } +} + +inline void pipe_hide(Pipe *pipe) { + pipe->x += 0; + for (UINT8 i = 36; i != 0; i--) { + move_sprite(pipe->sprite_ids[i - 1], 0, 0); + } +} diff --git a/src/sprites/bird.c b/src/sprites/bird.c new file mode 100644 index 0000000..3d7bc20 --- /dev/null +++ b/src/sprites/bird.c @@ -0,0 +1,39 @@ +/* + + BIRD.C + + Tile Source File. + + Info: + Form : All tiles as one unit. + Format : Gameboy 4 color. + Compression : None. + Counter : None. + Tile size : 8 x 8 + Tiles : 0 to 3 + + Palette colors : None. + SGB Palette : None. + CGB Palette : None. + + Convert to metatiles : No. + + This file was generated by GBTD v2.2 + +*/ + +/* Start of tile array. */ +const unsigned char BIRD_TILE_DATA[] = { + 0x03, 0x03, 0x0C, 0x0F, 0x10, 0x1F, 0x78, 0x7F, 0x84, 0xFF, 0x82, 0xFF, + 0xC6, 0xFF, 0x7C, 0x7F, 0x38, 0x3F, 0x20, 0x3F, 0x18, 0x1F, 0x07, 0x07, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0xF0, 0x78, 0xC8, + 0xFC, 0x84, 0xFE, 0x8A, 0xFE, 0x8A, 0x7E, 0xC2, 0x3F, 0xFF, 0x40, 0xFF, + 0xBF, 0xFF, 0x41, 0xFF, 0x3E, 0xFE, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x03, 0x03, 0x0C, 0x0F, 0x10, 0x1F, 0x20, 0x3F, + 0x40, 0x7F, 0x7C, 0x7F, 0x82, 0xFF, 0xC6, 0xFF, 0x7C, 0x7F, 0x20, 0x3F, + 0x18, 0x1F, 0x07, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x03, 0x03, 0x0C, 0x0F, 0x10, 0x1F, 0x20, 0x3F, 0x40, 0x7F, 0x40, 0x7F, + 0x7C, 0x7F, 0xC6, 0xFF, 0x84, 0xFF, 0x98, 0xFF, 0x78, 0x7F, 0x07, 0x07, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + +/* End of BIRD.C */ diff --git a/src/sprites/button.c b/src/sprites/button.c new file mode 100644 index 0000000..c17576e --- /dev/null +++ b/src/sprites/button.c @@ -0,0 +1,39 @@ +/* + + EXPORT.C + + Tile Source File. + + Info: + Form : All tiles as one unit. + Format : Gameboy 4 color. + Compression : None. + Counter : None. + Tile size : 8 x 8 + Tiles : 0 to 7 + + Palette colors : None. + SGB Palette : None. + CGB Palette : None. + + Convert to metatiles : No. + + This file was generated by GBTD v2.2 + +*/ + +/* Start of tile array. */ +const unsigned char BUTTON_TILE_DATA[] = { + 0x07, 0x07, 0x1F, 0x1C, 0x3F, 0x31, 0x7F, 0x63, 0x7F, 0x47, 0xFF, 0xCE, + 0xFF, 0x8C, 0xFF, 0x8F, 0xFF, 0x8F, 0xFF, 0x8C, 0xFF, 0xCC, 0x7F, 0x4C, + 0x7F, 0x60, 0x3F, 0x30, 0x1C, 0x1F, 0x07, 0x07, 0xE0, 0xE0, 0xF8, 0x38, + 0xFC, 0x8C, 0xFE, 0xC6, 0xFE, 0xE2, 0xFF, 0x73, 0xFD, 0x33, 0xFD, 0xF3, + 0xFD, 0xF3, 0xF9, 0x37, 0xFB, 0x37, 0xF2, 0x3E, 0xE6, 0x1E, 0x8C, 0x7C, + 0x38, 0xF8, 0xE0, 0xE0, 0x07, 0x07, 0x1C, 0x1F, 0x31, 0x3E, 0x67, 0x79, + 0x4F, 0x73, 0xDF, 0xE7, 0x9F, 0xEE, 0xBF, 0xCC, 0xBF, 0xCF, 0xBF, 0xCF, + 0xFF, 0xCC, 0x7F, 0x4C, 0x7F, 0x6C, 0x3F, 0x30, 0x1F, 0x1C, 0x07, 0x07, + 0xE0, 0xE0, 0x38, 0xF8, 0xFC, 0x0C, 0xFE, 0x86, 0xFE, 0xC2, 0xFF, 0xE3, + 0xFF, 0x71, 0xFF, 0x31, 0xFF, 0xF1, 0xFF, 0xF1, 0xFF, 0x33, 0xFE, 0x32, + 0xFE, 0x36, 0xFC, 0x0C, 0xF8, 0x38, 0xE0, 0xE0}; + +/* End of EXPORT.C */ diff --git a/src/sprites/pipe.c b/src/sprites/pipe.c new file mode 100644 index 0000000..918cae0 --- /dev/null +++ b/src/sprites/pipe.c @@ -0,0 +1,34 @@ +/* + + EXPORT.C + + Tile Source File. + + Info: + Form : All tiles as one unit. + Format : Gameboy 4 color. + Compression : None. + Counter : None. + Tile size : 8 x 8 + Tiles : 0 to 0 + + Palette colors : None. + SGB Palette : None. + CGB Palette : None. + + Convert to metatiles : No. + + This file was generated by GBTD v2.2 + +*/ + +/* Start of tile array. */ +const unsigned char PIPE_TILE_DATA[] = { + 0xFF, 0xFF, 0xE8, 0x97, 0xE8, 0x97, 0xE8, 0x97, 0xE8, 0x97, 0xE8, + 0x97, 0xE8, 0x97, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0x00, 0xFF, + 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0x74, + 0x4B, 0x74, 0x4B, 0x74, 0x4B, 0x74, 0x4B, 0x74, 0x4B, 0x74, 0x4B, + 0x74, 0x4B, 0x74, 0x4B, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF}; + +/* End of EXPORT.C */ -- cgit v1.2.3