#include "raylib.h" #include #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()) { 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++; } BeginDrawing(); 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(); return 0; }