summaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authorDominik Kaiser2026-05-24 23:11:01 +0200
committerDominik Kaiser2026-05-24 23:11:01 +0200
commit51a07c8d81a14b3a3ad79ccec725539ccb7f2e1b (patch)
tree9219db7f2ff215d7f3165d53657be411452677cc /src/main.cpp
parent920157796a2e381d35ba97c15d58ea77eae60a72 (diff)
downloadflappy-bird-51a07c8d81a14b3a3ad79ccec725539ccb7f2e1b.tar.gz
flappy-bird-51a07c8d81a14b3a3ad79ccec725539ccb7f2e1b.zip
Implement flappy bird prototypeHEADmain
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp65
1 files changed, 59 insertions, 6 deletions
diff --git a/src/main.cpp b/src/main.cpp
index c2e66a5..8e28b0f 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,23 +1,76 @@
#include "raylib.h"
+#include <string>
-#define SCREEN_WIDTH (800)
-#define SCREEN_HEIGHT (450)
+#define SCREEN_WIDTH (400)
+#define SCREEN_HEIGHT (600)
#define WINDOW_TITLE "Hello World"
+#define PLAYER_SIZE 50
+#define BAR_WIDTH 50
+#define BAR_GAP 250
+
int
main(void)
{
InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, WINDOW_TITLE);
SetTargetFPS(60);
+ int score = 0;
+ float player_y = 20;
+ float player_velocity = 0;
+
+ float bar_x = SCREEN_WIDTH;
+ float bar_y = GetRandomValue(BAR_GAP + 50, SCREEN_HEIGHT - 50);
+
+ Rectangle player_rec;
+ Rectangle upper_bar_rec;
+ Rectangle lower_bar_rec;
+
while (!WindowShouldClose())
{
- BeginDrawing();
+ player_rec = {
+ (SCREEN_WIDTH - PLAYER_SIZE) / 2.0,
+ player_y,
+ PLAYER_SIZE,
+ PLAYER_SIZE};
+
+ upper_bar_rec = { bar_x, 0, BAR_WIDTH, bar_y - BAR_GAP };
+ lower_bar_rec = {bar_x, bar_y, BAR_WIDTH, SCREEN_HEIGHT - bar_y};
+
+ player_velocity += 1;
+ bar_x -= 2;
+ if (IsKeyPressed(KEY_SPACE))
+ {
+ player_velocity = -15;
+ }
+ player_y += player_velocity;
+
+ if (player_y < 0 || player_y > SCREEN_HEIGHT)
+ score = 0;
+
+ if (CheckCollisionRecs(player_rec, upper_bar_rec)
+ || CheckCollisionRecs(player_rec, lower_bar_rec))
+ score = 0;
+
+ if (bar_x < -40)
+ {
+ bar_x = SCREEN_WIDTH;
+ bar_y = GetRandomValue(BAR_GAP + 50, SCREEN_HEIGHT - 50);
+ score++;
+ }
+
- ClearBackground(RAYWHITE);
- DrawText("Hello world!", 10, 10, 20, BLACK);
+ BeginDrawing();
- EndDrawing();
+ ClearBackground(BLUE);
+
+ DrawRectangleRec(upper_bar_rec, GOLD);
+ DrawRectangleRec(lower_bar_rec, GOLD);
+ DrawText(std::to_string(score).c_str(),
+ (SCREEN_WIDTH / 2) - 25, 50, 50, RAYWHITE);
+ DrawRectangleRec(player_rec, BLACK);
+
+ EndDrawing();
}
CloseWindow();