Skip to content
This repository has been archived by the owner on May 19, 2024. It is now read-only.

Commit

Permalink
Added 'dist' command to Makefile, minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
xfnty committed Jul 5, 2023
1 parent d4634de commit d050825
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Files
*.sublime*
compile_commands.json
*.zip


# Folders
bin/
dist/
.cmake/
.ignore/
.cache/
Expand Down
43 changes: 32 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ MAKEFLAGS=--no-print-directory --quiet

ifdef OS
path = $(subst /,\,$1)
OS_NAME:=windows
OS_ARCH:=x86_x64
else
path = $1
OS_NAME:=$(shell uname -s | tr A-Z a-z)
OS_ARCH:=$(shell uname -p)
endif

PROJECT_NAME=flappy-bird
Expand All @@ -15,39 +19,56 @@ CONFIGURE:=configure c
BUILD:=build b
RUN:=run r
DEBUG:=debug d
DIST:=dist

_CONFIGURE:=cmake -B $(CMAKE_DIR) -S . -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=1
_COPY_CCOMMANDS:=cp -f $(call path, $(CMAKE_DIR)/compile_commands.json) compile_commands.json
_BUILD:=cmake --build $(CMAKE_DIR) -j
_COPY_ASSETS:=cp -rf assets $(OUTPUT_DIR)

all: $(CMAKE_DIR) build run

$(CONFIGURE):
echo ----- Configuring -----
-mkdir -p $(CMAKE_DIR)
cmake -B $(CMAKE_DIR) -S . -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=1
-cp -f $(call path, $(CMAKE_DIR)/compile_commands.json) compile_commands.json
mkdir -p $(CMAKE_DIR)
$(_CONFIGURE)
-$(_COPY_CCOMMANDS)

$(BUILD):
echo ----- Building -----
-mkdir -p $(OUTPUT_DIR)
cmake --build $(CMAKE_DIR)
mkdir -p $(OUTPUT_DIR)
$(_BUILD)
$(_COPY_ASSETS)

$(RUN):
echo ----- Running -----
cp -rf assets $(OUTPUT_DIR)
$(_COPY_ASSETS)
cd $(OUTPUT_DIR)
$(EXE)

$(DEBUG):
echo ----- Debugging -----
cp -rf assets $(OUTPUT_DIR)
$(_COPY_ASSETS)
cd $(OUTPUT_DIR)
gdb -q --return-child-result $(EXE)

$(DIST): $(OUTPUT_DIR)
echo ----- Packing distribution -----
$(_COPY_ASSETS)
-rm -f $(PROJECT_NAME)-$(OS_NAME)-$(OS_ARCH).zip
zip -9 -r $(PROJECT_NAME)-$(OS_NAME)-$(OS_ARCH).zip $(call path, $(OUTPUT_DIR)/*)

$(CMAKE_DIR):
echo ----- Configuring -----
-mkdir -p $(CMAKE_DIR)
cmake -B $(CMAKE_DIR) -S . -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=1
-cp -f $(call path, $(CMAKE_DIR)/compile_commands.json) compile_commands.json
mkdir -p $(CMAKE_DIR)
$(_CONFIGURE)
-$(_COPY_CCOMMANDS)

$(OUTPUT_DIR):
mkdir -p $(OUTPUT_DIR)
$(_BUILD)

clean:
git clean -Xdfq

.PHONY=$(CONFIGURE) $(BUILD) $(RUN) $(DEBUG) clean
.PHONY=$(CONFIGURE) $(BUILD) $(RUN) $(DEBUG) $(DIST) clean
Binary file added assets/die.mp3
Binary file not shown.
12 changes: 11 additions & 1 deletion src/game/states/gameplay.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ static struct {
Texture2D digits[10];
} sprites = {0};

static struct {
Music flap;
Sound gameover;
} sounds = {0};

typedef struct gameplay_state_s {
bool is_paused;
float bird_y;
Expand Down Expand Up @@ -77,6 +82,9 @@ static void _gameplay_state_enter(game_state_t* state, game_t* game) {
for (int i = 0; i < STACKARRAY_SIZE(sprites.digits); i++)
if (sprites.digits[i].id == 0) sprites.digits[i] = LoadTexture(TextFormat("assets/%d.png", i));

if (!IsMusicReady(sounds.flap)) sounds.flap = LoadMusicStream("assets/die.mp3");
if (!IsSoundReady(sounds.gameover)) sounds.gameover = LoadSoundFromWave(LoadWave("assets/die.wav"));

gameplay->bird_y = ((float)game->canvas.texture.height - sprites.base.height) / 2;

kv_init(gameplay->pipes);
Expand Down Expand Up @@ -282,8 +290,10 @@ void debug_draw(gameplay_state_t* gameplay, game_t* game) {
}

void update_bird(gameplay_state_t* gameplay, game_t* game) {
if (IsKeyPressed(KEY_SPACE) && !gameplay->is_gameover)
if (IsKeyPressed(KEY_SPACE) && !gameplay->is_gameover) {
gameplay->bird_y_speed = -bird_up_force;
PlayMusicStream(sounds.flap);
}

gameplay->bird_y += gameplay->bird_y_speed * GetFrameTime();

Expand Down

0 comments on commit d050825

Please sign in to comment.