diff options
author | lamp | 2023-03-05 21:25:03 +0000 |
---|---|---|
committer | lamp | 2023-03-05 21:25:03 +0000 |
commit | b6e7e454ed6242475163dcd534051897d3c9158c (patch) | |
tree | 8e923fed21eac6190999de9f4adee76d0f75c10f |
initmain
36 files changed, 1450 insertions, 0 deletions
diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..03ce0b4 --- /dev/null +++ b/.clang-format @@ -0,0 +1,149 @@ +--- +Language: Cpp +# BasedOnStyle: LLVM +AccessModifierOffset: -2 +AlignAfterOpenBracket: Align +AlignConsecutiveMacros: false +AlignConsecutiveAssignments: false +AlignConsecutiveBitFields: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlines: Right +AlignOperands: Align +AlignTrailingComments: true +AllowAllArgumentsOnNextLine: true +AllowAllConstructorInitializersOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortEnumsOnASingleLine: true +AllowShortBlocksOnASingleLine: Never +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: All +AllowShortLambdasOnASingleLine: All +AllowShortIfStatementsOnASingleLine: Never +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: MultiLine +BinPackArguments: true +BinPackParameters: true +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: Never + AfterEnum: false + AfterFunction: false + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + BeforeLambdaBody: false + BeforeWhile: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBinaryOperators: None +BreakBeforeBraces: Attach +BreakBeforeInheritanceComma: false +BreakInheritanceList: BeforeColon +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializers: BeforeColon +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: true +ColumnLimit: 80 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DeriveLineEnding: true +DerivePointerAlignment: false +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: true +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + SortPriority: 0 + - Regex: '^(<|"(gtest|gmock|isl|json)/)' + Priority: 3 + SortPriority: 0 + - Regex: '.*' + Priority: 1 + SortPriority: 0 +IncludeIsMainRegex: '(Test)?$' +IncludeIsMainSourceRegex: '' +IndentCaseLabels: false +IndentCaseBlocks: false +IndentGotoLabels: true +IndentPPDirectives: None +IndentExternBlock: AfterExternBlock +IndentWidth: 2 +IndentWrappedFunctionNames: false +InsertTrailingCommas: None +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: true +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBinPackProtocolList: Auto +ObjCBlockIndentWidth: 2 +ObjCBreakBeforeNestedBlockParam: true +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 60 +PointerAlignment: Right +ReflowComments: true +SortIncludes: true +SortUsingDeclarations: true +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyBlock: false +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInConditionalStatement: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +SpaceBeforeSquareBrackets: false +Standard: Latest +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +TabWidth: 8 +UseCRLF: false +UseTab: Never +WhitespaceSensitiveMacros: + - STRINGIZE + - PP_STRINGIZE + - BOOST_PP_STRINGIZE +... + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fcb2462 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +compile_flags.txt +out.gb @@ -0,0 +1,13 @@ + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + Version 2, December 2004 + + Copyright (C) 2004 Sam Hocevar <sam@hocevar.net> + + Everyone is permitted to copy and distribute verbatim or modified + copies of this license document, and changing it is allowed as long + as the name is changed. + + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. You just DO WHAT THE FUCK YOU WANT TO. diff --git a/README.md b/README.md new file mode 100644 index 0000000..fe6d268 --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# flappy-gb + +A simple flappy bird clone for the Gameboy, written in C using the [GBDK](https://github.com/gbdk-2020/gbdk-2020). +To compile, run `build.sh`. Alternatively, a build is available in the releases section. +Thanks to GamingMonsters for their [tutorials](https://www.youtube.com/playlist?list=PLeEj4c2zF7PaFv5MPYhNAkBGrkx4iPGJo), the excellent [GBDK documentation](https://bbbbbr.github.io/gbdk-2020/docs/api/index.html), and the [Pandocs](https://gbdev.io/pandocs/). diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..1f56aec --- /dev/null +++ b/build.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +shopt -s globstar + +CC="lcc" +OUT_NAME="out.gb" + +if $CC -o "$OUT_NAME" -Iinclude src/**/*.c; then + echo "Emitted: $OUT_NAME" +else + echo "Build Failed" +fi diff --git a/format.sh b/format.sh new file mode 100755 index 0000000..645c3ce --- /dev/null +++ b/format.sh @@ -0,0 +1,84 @@ +#!/bin/bash +# +# clang-format-all: a tool to run clang-format on an entire project +# Copyright (C) 2016 Evan Klitzke <evan@eklitzke.org> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +function usage { + echo "Usage: $0 DIR..." + exit 1 +} + +if [ $# -eq 0 ]; then + usage +fi + +# Variable that will hold the name of the clang-format command +FMT="" + +# Some distros just call it clang-format. Others (e.g. Ubuntu) are insistent +# that the version number be part of the command. We prefer clang-format if +# that's present, otherwise we work backwards from highest version to lowest +# version. +for clangfmt in clang-format{,-{4,3}.{9,8,7,6,5,4,3,2,1,0}}; do + if which "$clangfmt" &>/dev/null; then + FMT="$clangfmt" + break + fi +done + +# Check if we found a working clang-format +if [ -z "$FMT" ]; then + echo "failed to find clang-format" + exit 1 +fi + +# Check all of the arguments first to make sure they're all directories +for dir in "$@"; do + if [ ! -d "${dir}" ]; then + echo "${dir} is not a directory" + usage + fi +done + +# Find a dominating file, starting from a given directory and going up. +find-dominating-file() { + if [ -r "$1"/"$2" ]; then + return 0 + fi + if [ "$1" = "/" ]; then + return 1 + fi + find-dominating-file "$(realpath "$1"/..)" "$2" + return $? +} + +# Run clang-format -i on all of the things +for dir in "$@"; do + pushd "${dir}" &>/dev/null + if ! find-dominating-file . .clang-format; then + echo "Failed to find dominating .clang-format starting at $PWD" + continue + fi + find . \ + \( -name '*.c' \ + -o -name '*.cc' \ + -o -name '*.cpp' \ + -o -name '*.h' \ + -o -name '*.hh' \ + -o -name '*.hpp' \) \ + -exec "${FMT}" -i '{}' \; + popd &>/dev/null +done diff --git a/include/backgrounds/background.h b/include/backgrounds/background.h new file mode 100644 index 0000000..d9385be --- /dev/null +++ b/include/backgrounds/background.h @@ -0,0 +1,32 @@ +/*
+
+ EXPORT.H
+
+ Include File.
+
+ Info:
+ Form : All tiles as one unit.
+ Format : Gameboy 4 color.
+ Compression : None.
+ Counter : None.
+ Tile size : 8 x 8
+ Tiles : 0 to 8
+
+ Palette colors : None.
+ SGB Palette : None.
+ CGB Palette : None.
+
+ Convert to metatiles : No.
+
+ This file was generated by GBTD v2.2
+
+*/
+
+#pragma once
+
+/* Bank of tiles. */
+#define BG_TILE_DATABank 0
+/* Start of tile array. */
+extern const unsigned char BG_TILE_DATA[];
+
+/* End of EXPORT.H */
diff --git a/include/backgrounds/game_over.h b/include/backgrounds/game_over.h new file mode 100644 index 0000000..19a1c1a --- /dev/null +++ b/include/backgrounds/game_over.h @@ -0,0 +1,32 @@ +/*
+
+ EXPORT.H
+
+ Include File.
+
+ Info:
+ Form : All tiles as one unit.
+ Format : Gameboy 4 color.
+ Compression : None.
+ Counter : None.
+ Tile size : 8 x 8
+ Tiles : 0 to 10
+
+ Palette colors : None.
+ SGB Palette : None.
+ CGB Palette : None.
+
+ Convert to metatiles : No.
+
+ This file was generated by GBTD v2.2
+
+*/
+
+#pragma once
+
+/* Bank of tiles. */
+#define GAME_OVER_TILE_DATABank 0
+/* Start of tile array. */
+extern const unsigned char GAME_OVER_TILE_DATA[];
+
+/* End of EXPORT.H */
diff --git a/include/backgrounds/game_over_map.h b/include/backgrounds/game_over_map.h new file mode 100644 index 0000000..6e861f8 --- /dev/null +++ b/include/backgrounds/game_over_map.h @@ -0,0 +1,30 @@ +/*
+
+ GAME_OVER_MAP.H
+
+ Map Include 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
+
+*/
+
+#pragma once
+
+#include "defines.h"
+
+#define GAME_OVER_MAPWidth 10
+#define GAME_OVER_MAPHeight 7
+#define GAME_OVER_MAPBank 0
+
+extern const unsigned char GAME_OVER_MAP[];
+
+/* End of GAME_OVER_MAP.H */
diff --git a/include/backgrounds/map.h b/include/backgrounds/map.h new file mode 100644 index 0000000..03c1eb5 --- /dev/null +++ b/include/backgrounds/map.h @@ -0,0 +1,29 @@ +/*
+
+ MAP.H
+
+ Map Include 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
+
+*/
+
+#pragma once
+
+#define BG_TILE_MAPWidth 32
+#define BG_TILE_MAPHeight 18
+#define BG_TILE_MAPBank 0
+
+extern const unsigned char BG_TILE_MAP[];
+
+/* End of MAP.H */
diff --git a/include/backgrounds/numerals.h b/include/backgrounds/numerals.h new file mode 100644 index 0000000..f171edd --- /dev/null +++ b/include/backgrounds/numerals.h @@ -0,0 +1,34 @@ +/*
+
+ EXPORT.H
+
+ Include File.
+
+ Info:
+ Form : All tiles as one unit.
+ Format : Gameboy 4 color.
+ Compression : None.
+ Counter : None.
+ Tile size : 8 x 8
+ Tiles : 0 to 10
+
+ Palette colors : None.
+ SGB Palette : None.
+ CGB Palette : None.
+
+ Convert to metatiles : No.
+
+ This file was generated by GBTD v2.2
+
+*/
+
+#pragma once
+#include "defines.h"
+
+/* Bank of tiles. */
+#define NUMERALS_TILE_DATABank 0
+/* Start of tile array. */
+extern const unsigned char NUMERALS_TILE_DATA[];
+extern const unsigned char NUMERALS_TILE_MAP[];
+extern const unsigned char NUMERALS_TILE_CLEAR[];
+/* End of EXPORT.H */
diff --git a/include/defines.h b/include/defines.h new file mode 100644 index 0000000..765ecde --- /dev/null +++ b/include/defines.h @@ -0,0 +1,23 @@ +#pragma once +#include <gb/gb.h> + +#define TILE_SIZE 8 +#define GRAVITY_ACCELERATION 1 +#define APPLY_GRAVITY_N_FRAMES 4 +#define CYCLE_ANIMATION_N_FRAMES 8 +#define JUMP_VELOCITY -4 +#define BACKGROUND_SCROLL_SPEED 1 +#define FOREGROUND_SCROLL_SPEED 2 +#define PIPE_TILE_START 9 +#define NUMERALS_TILE_START 10 +#define BLANK_NUMERAL_TILE 20 +#define PIPE_WIDTH 24 +#define BUTTON_TILE_START 14 +#define CYCLE_BUTTON_N_FRAMES 16 +#define WINDOW_CENTERING_OFFSET 23 +#define GAME_OVER_TILE_START 21 + +#define BIRD_WIDTH 16 +#define BIRD_HEIGHT 12 + +typedef INT8 ScreenCoordinate; diff --git a/include/metasprite.h b/include/metasprite.h new file mode 100644 index 0000000..f4a15e7 --- /dev/null +++ b/include/metasprite.h @@ -0,0 +1,27 @@ +#pragma once +#include <gb/gb.h> + +#include "defines.h" + +typedef struct Metasprite { + ScreenCoordinate x; + ScreenCoordinate y; + UINT8 width; + UINT8 height; + INT8 velocity_x; + INT8 velocity_y; + UINT8 sprite_ids[4]; // A metasprite is four sprites. + UINT8 tile_ids[4]; // A metasprite is four sprites. +} Metasprite; + +inline void metasprite_init(Metasprite *metasprite); +inline void metasprite_move_to(Metasprite *metasprite, ScreenCoordinate new_x, + ScreenCoordinate new_y); +inline void metasprite_move_offset(Metasprite *metasprite, + ScreenCoordinate offset_x, + ScreenCoordinate offset_y); +inline void metasprite_apply_gravity(Metasprite *metasprite); +inline void metasprite_update_position_using_velocity(Metasprite *metasprite); +inline void metasprite_jump(Metasprite *metasprite); +inline void metasprite_update_tiles(Metasprite *metasprite); +inline void metasprite_hide(Metasprite *metasprite); diff --git a/include/pipe.h b/include/pipe.h new file mode 100644 index 0000000..2602614 --- /dev/null +++ b/include/pipe.h @@ -0,0 +1,33 @@ +#pragma once +#include <gb/gb.h> +#include <stdbool.h> + +#include "defines.h" + +enum SPECIAL_SPRITES { + PIPE_TILE_TOP_LEFT, + PIPE_TILE_TOP_MIDDLE, + PIPE_TILE_TOP_RIGHT, + PIPE_TILE_BOTTOM_LEFT, + PIPE_TILE_BOTTOM_MIDDLE, + PIPE_TILE_BOTTOM_RIGHT, +}; + +enum PIPE_TILES { + CAP_LEFT, + CAP_MIDDLE, + MAIN_LEFT, + MAIN_MIDDLE, +}; + +typedef struct Pipe { + UINT8 x; + UINT8 height_of_gap; + UINT8 gap_skip; + UINT8 sprite_ids[36]; // 15 high, minus 3 tile gap, times 3 wide = 36 +} Pipe; + +inline void pipe_init(Pipe *pipe); +inline void pipe_scroll_horizontal(Pipe *pipe, ScreenCoordinate x); +inline void pipe_move_gap_height(Pipe *pipe, UINT8 gap_height); +inline void pipe_hide(Pipe *pipe); diff --git a/include/sprites/bird.h b/include/sprites/bird.h new file mode 100644 index 0000000..1964266 --- /dev/null +++ b/include/sprites/bird.h @@ -0,0 +1,32 @@ +/*
+
+ BIRD.H
+
+ Include File.
+
+ Info:
+ Form : All tiles as one unit.
+ Format : Gameboy 4 color.
+ Compression : None.
+ Counter : None.
+ Tile size : 8 x 8
+ Tiles : 0 to 3
+
+ Palette colors : None.
+ SGB Palette : None.
+ CGB Palette : None.
+
+ Convert to metatiles : No.
+
+ This file was generated by GBTD v2.2
+
+*/
+#pragma once
+
+/* Bank of tiles. */
+#define TileLabelBank 0
+
+/* Start of tile array. */
+extern const unsigned char BIRD_TILE_DATA[];
+
+/* End of BIRD.H */
diff --git a/include/sprites/button.h b/include/sprites/button.h new file mode 100644 index 0000000..74650c4 --- /dev/null +++ b/include/sprites/button.h @@ -0,0 +1,32 @@ +/*
+
+ EXPORT.H
+
+ Include File.
+
+ Info:
+ Form : All tiles as one unit.
+ Format : Gameboy 4 color.
+ Compression : None.
+ Counter : None.
+ Tile size : 8 x 8
+ Tiles : 0 to 7
+
+ Palette colors : None.
+ SGB Palette : None.
+ CGB Palette : None.
+
+ Convert to metatiles : No.
+
+ This file was generated by GBTD v2.2
+
+*/
+
+#pragma once
+
+/* Bank of tiles. */
+#define BUTTON_TILE_DATABank 0
+/* Start of tile array. */
+extern const unsigned char BUTTON_TILE_DATA[];
+
+/* End of EXPORT.H */
diff --git a/include/sprites/pipe.h b/include/sprites/pipe.h new file mode 100644 index 0000000..30ea5a0 --- /dev/null +++ b/include/sprites/pipe.h @@ -0,0 +1,32 @@ +/*
+
+ EXPORT.H
+
+ Include File.
+
+ Info:
+ Form : All tiles as one unit.
+ Format : Gameboy 4 color.
+ Compression : None.
+ Counter : None.
+ Tile size : 8 x 8
+ Tiles : 0 to 0
+
+ Palette colors : None.
+ SGB Palette : None.
+ CGB Palette : None.
+
+ Convert to metatiles : No.
+
+ This file was generated by GBTD v2.2
+
+*/
+
+#pragma once
+
+/* Bank of tiles. */
+#define PIPE_TILE_DATABank 0
+/* Start of tile array. */
+extern const unsigned char PIPE_TILE_DATA[];
+
+/* End of EXPORT.H */
diff --git a/res/bg.gbm b/res/bg.gbm Binary files differnew file mode 100644 index 0000000..0c51d5c --- /dev/null +++ b/res/bg.gbm diff --git a/res/bg.gbr b/res/bg.gbr Binary files differnew file mode 100644 index 0000000..a22cd84 --- /dev/null +++ b/res/bg.gbr diff --git a/res/bird.gbr b/res/bird.gbr Binary files differnew file mode 100644 index 0000000..7a7e5b8 --- /dev/null +++ b/res/bird.gbr diff --git a/res/button.gbr b/res/button.gbr Binary files differnew file mode 100644 index 0000000..a87d1ef --- /dev/null +++ b/res/button.gbr diff --git a/res/game_over.gbm b/res/game_over.gbm Binary files differnew file mode 100644 index 0000000..26178b7 --- /dev/null +++ b/res/game_over.gbm diff --git a/res/game_over.gbr b/res/game_over.gbr Binary files differnew file mode 100644 index 0000000..8afd5f9 --- /dev/null +++ b/res/game_over.gbr diff --git a/res/numerals.gbr b/res/numerals.gbr Binary files differnew file mode 100644 index 0000000..281e9d7 --- /dev/null +++ b/res/numerals.gbr diff --git a/res/pipe.gbr b/res/pipe.gbr Binary files differnew file mode 100644 index 0000000..a990378 --- /dev/null +++ b/res/pipe.gbr 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 <bcd.h> +#include <gb/gb.h> +#include <rand.h> +#include <stdbool.h> + +#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 */
|