commit 3de7aeeabca516bda5eade014b6cc2ca9bf1cc29
parent 76caa33a4717c8f5a9477d9b448e5b678b2f585f
Author: Henry Unite <unitehenry@gmail.com>
Date: Sun, 19 Apr 2026 04:58:10 +0000
feat: collision
Diffstat:
1 file changed, 32 insertions(+), 0 deletions(-)
diff --git a/src/game.c b/src/game.c
@@ -23,6 +23,7 @@ Texture2D baseTexture;
/* Game State */
typedef enum { TITLE, PLAY } Screen;
Screen screen = TITLE;
+bool isPaused = false;
float backgroundScroll = 0.0f;
float baseScroll = 0.0f;
char *birdColor = NULL;
@@ -156,6 +157,11 @@ void draw_base() {
void draw() {
BeginDrawing();
+ if (isPaused) {
+ EndDrawing();
+ return;
+ }
+
draw_background();
draw_base();
@@ -187,10 +193,34 @@ void reset_bird() {
birdRect.height = (float)birdTexture.height;
}
+void collide() {
+ Rectangle collideRects[2] = { baseRect1, baseRect2 };
+
+ for (int i = 0; i < (sizeof(collideRects) / sizeof(collideRects[0])); i++) {
+ Rectangle collideRect = collideRects[i];
+
+ if (CheckCollisionRecs(birdRect, collideRect)) {
+ isPaused = true;
+ }
+ }
+}
+
+void reset() {
+ reset_bird();
+ isPaused = false;
+ screen = TITLE;
+ birdColor = NULL;
+}
+
void input() {
if (!IsMouseButtonReleased(0))
return;
+ if (isPaused) {
+ reset();
+ return;
+ }
+
if (screen == TITLE) {
screen = PLAY;
}
@@ -216,6 +246,8 @@ void update() {
}
birdRect.y += gravity;
}
+
+ collide();
}
void game_loop(void) {