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 100c76f2f8f4f0d4303a558a70c8c2a414b57693
parent 8191953fd6eff7254b58e9d5dcb1657d77881cf6
Author: Henry Unite <unitehenry@gmail.com>
Date:   Sun, 19 Apr 2026 06:08:41 +0000

refactor: pipe state

Diffstat:
Msrc/game.c | 44++++++++++++++++++++++++--------------------
1 file changed, 24 insertions(+), 20 deletions(-)

diff --git a/src/game.c b/src/game.c @@ -81,28 +81,9 @@ void draw_pipes() { if (screen == TITLE) return; - static const float scrollSpeed = 1.2f; - - float offscreenX = 0.0f - pipeTexture.width; - - float defaultY = (screenHeight / 2.0f + (pipeTexture.height / 6.0f)); - for (int i = 0; i < sizeof(pipeRects) / sizeof(pipeRects[0]); i++) { bool topPipe = i % 2 != 0; - Rectangle pipeRect = pipeRects[i]; - - if (pipeRect.x < offscreenX) { - pipeRect.x = screenWidth + pipeTexture.width; - } - - pipeRect.x -= scrollSpeed; - pipeRect.y = topPipe ? defaultY - 420 : defaultY; - pipeRect.width = (float)pipeTexture.width; - pipeRect.height = (float)pipeTexture.height; - - pipeRects[i] = pipeRect; - Rectangle source = {0, 0, (float)pipeTexture.width, topPipe ? -(float)pipeTexture.height : (float)pipeTexture.height}; @@ -110,7 +91,7 @@ void draw_pipes() { float rotate = 0.0f; - DrawTexturePro(pipeTexture, source, pipeRect, origin, rotate, WHITE); + DrawTexturePro(pipeTexture, source, pipeRects[i], origin, rotate, WHITE); } } @@ -327,6 +308,29 @@ void update() { birdRect.y += gravity; } + static const float scrollSpeed = 1.2f; + + float offscreenX = 0.0f - pipeTexture.width; + + float defaultY = (screenHeight / 2.0f + (pipeTexture.height / 6.0f)); + + for (int i = 0; i < sizeof(pipeRects) / sizeof(pipeRects[0]); i++) { + bool topPipe = i % 2 != 0; + + Rectangle pipeRect = pipeRects[i]; + + if (pipeRect.x < offscreenX) { + pipeRect.x = screenWidth + pipeTexture.width; + } + + pipeRect.x -= scrollSpeed; + pipeRect.y = topPipe ? defaultY - 420 : defaultY; + pipeRect.width = (float)pipeTexture.width; + pipeRect.height = (float)pipeTexture.height; + + pipeRects[i] = pipeRect; + } + collide(); }