rayflap

A Flappy Bird clone written in C and compiled to WebAssembly.
git clone https://unitehenry.com/git/rayflap.git
Log | Files | Refs | README

commit 25cce6c63a77c48903cbb0d99bd759ab1d76d789
parent a82c26ebbab1aaef898fc4b907e61e4e178eb10f
Author: Henry Unite <unitehenry@gmail.com>
Date:   Sat, 18 Apr 2026 23:22:55 +0000

feat: parallax background

Diffstat:
Msrc/game.c | 17+++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/src/game.c b/src/game.c @@ -1,6 +1,7 @@ #include "raylib.h" #include <emscripten/emscripten.h> #include <stdio.h> +#include <math.h> #define MainLoop emscripten_set_main_loop @@ -18,8 +19,8 @@ Texture2D baseTexture; /* Game State */ typedef enum { TITLE, PLAY } Screen; Screen screen = TITLE; -int backgroundScroll = 0; -int baseScroll = 0; +float backgroundScroll = 0.0f; +float baseScroll = 0.0f; void draw_message() { if (screen != TITLE) return; @@ -40,13 +41,13 @@ void draw_background() { backgroundTexture = LoadTexture("assets/sprites/background-day.png"); } - static const int scrollSpeed = 1; + static const float scrollSpeed = 0.5f; backgroundScroll -= scrollSpeed; - DrawTexture(backgroundTexture, backgroundScroll % screenWidth, 0, WHITE); + DrawTexture(backgroundTexture, (int) fmodf(backgroundScroll, (float) screenWidth), 0, WHITE); - DrawTexture(backgroundTexture, (backgroundScroll % screenWidth) + screenWidth, 0, + DrawTexture(backgroundTexture, (int) fmodf(backgroundScroll, (float) screenWidth) + screenWidth, 0, WHITE); } @@ -75,13 +76,13 @@ void draw_base() { float bottomY = screenHeight - baseTexture.height + (baseTexture.height / 2.0f); - static const int scrollSpeed = 1; + static const float scrollSpeed = 1.2f; baseScroll -= scrollSpeed; - DrawTexture(baseTexture, baseScroll % screenWidth, bottomY, WHITE); + DrawTexture(baseTexture, (int) fmodf(baseScroll, (float) screenWidth), bottomY, WHITE); - DrawTexture(baseTexture, (baseScroll % screenWidth) + screenWidth, bottomY, WHITE); + DrawTexture(baseTexture, (int) fmodf(baseScroll, (float) screenWidth) + screenWidth, bottomY, WHITE); } void draw(void) {