diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000000000000000000000000000000000000..348b5754ed4b128d424395c3a90c7137c944ceae --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,22 @@ +image: ubuntu:latest # Use latest Ubuntu as the base image + +stages: + - build + +before_script: + - apt-get update && apt-get install -y build-essential libgl1-mesa-dev xorg-dev wget unzip + - wget https://github.com/raysan5/raylib/releases/download/5.0/raylib-5.0_linux_amd64.tar.gz + - tar -xvzf raylib-5.0_linux_amd64.tar.gz + - cp raylib-5.0_linux_amd64/lib/libraylib.a /usr/local/lib/ + - cp -r raylib-5.0_linux_amd64/include/* /usr/local/include/ + +build: + stage: build + script: + - echo "Checking files..." + - ls -R # List all files for debugging + - gcc main.c paddle.c ball.c brick.c -o brickbreaker -I/usr/local/include -L/usr/local/lib -lraylib -lm -ldl -lpthread -lGL -lX11 -lXrandr -lXi -lXinerama -lXcursor + artifacts: + paths: + - brickbreaker + expire_in: 1 day # Keep the binary for 1 day diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..4b089989acaf2877601bfa048740b0793ccff804 --- /dev/null +++ b/Makefile @@ -0,0 +1,18 @@ +CC = gcc +CFLAGS = -Wall -std=c99 +LDFLAGS = -lraylib -lGL -lm -lpthread -ldl -lrt -lX11 + +SRC = main.c paddle.c ball.c brick.c +OBJ = $(SRC:.c=.o) +EXEC = brickbreaker + +all: $(EXEC) + +$(EXEC): $(OBJ) + $(CC) $(OBJ) -o $(EXEC) $(LDFLAGS) + +%.o: %.c + $(CC) $(CFLAGS) -c $< -o $@ + +clean: + rm -f $(OBJ) $(EXEC) diff --git a/ball.c b/ball.c new file mode 100644 index 0000000000000000000000000000000000000000..3c25f41a4a42c39c08ca6d63da39eabeb920303d --- /dev/null +++ b/ball.c @@ -0,0 +1,39 @@ +#include "ball.h" + +#define SCREEN_WIDTH 800 +#define SCREEN_HEIGHT 600 + +Ball InitBall() { + Ball ball; + ball.position = (Vector2){SCREEN_WIDTH / 2, 300}; + ball.speed = (Vector2){4, -4}; + ball.radius = 10; + return ball; +} + +void UpdateBall(Ball *ball, Paddle *paddle) { + ball->position.x += ball->speed.x; + ball->position.y += ball->speed.y; + + // Bounce off walls + if (ball->position.x <= 0 || ball->position.x >= SCREEN_WIDTH) { + ball->speed.x *= -1; + } + if (ball->position.y <= 0) { + ball->speed.y *= -1; + } + + // Paddle collision + if (CheckCollisionCircleRec(ball->position, ball->radius, paddle->rect)) { + ball->speed.y *= -1; + } + + // Ball falls off the screen (reset) + if (ball->position.y > SCREEN_HEIGHT) { + *ball = InitBall(); // Reset ball + } +} + +void DrawBall(Ball ball) { + DrawCircleV(ball.position, ball.radius, RED); +} diff --git a/ball.h b/ball.h new file mode 100644 index 0000000000000000000000000000000000000000..bc6ff21154a4ec86c7bb15358ed75b0eca5ca600 --- /dev/null +++ b/ball.h @@ -0,0 +1,17 @@ +#ifndef BALL_H +#define BALL_H + +#include "raylib.h" +#include "paddle.h" + +typedef struct { + Vector2 position; + Vector2 speed; + float radius; +} Ball; + +Ball InitBall(); +void UpdateBall(Ball *ball, Paddle *paddle); +void DrawBall(Ball ball); + +#endif diff --git a/brick.c b/brick.c new file mode 100644 index 0000000000000000000000000000000000000000..35bb713b254fbb4448deebd5c9250af7390426f0 --- /dev/null +++ b/brick.c @@ -0,0 +1,33 @@ +#include "brick.h" + +Brick bricks[BRICK_ROWS][BRICK_COLS]; + +void InitBricks() { + for (int row = 0; row < BRICK_ROWS; row++) { + for (int col = 0; col < BRICK_COLS; col++) { + bricks[row][col].rect = (Rectangle){col * BRICK_WIDTH, row * BRICK_HEIGHT, BRICK_WIDTH, BRICK_HEIGHT}; + bricks[row][col].active = true; + } + } +} + +void DrawBricks() { + for (int row = 0; row < BRICK_ROWS; row++) { + for (int col = 0; col < BRICK_COLS; col++) { + if (bricks[row][col].active) { + DrawRectangleRec(bricks[row][col].rect, GREEN); + } + } + } +} + +void CheckBrickCollision(Ball *ball) { + for (int row = 0; row < BRICK_ROWS; row++) { + for (int col = 0; col < BRICK_COLS; col++) { + if (bricks[row][col].active && CheckCollisionCircleRec(ball->position, ball->radius, bricks[row][col].rect)) { + bricks[row][col].active = false; // Remove brick + ball->speed.y *= -1; // Reverse ball direction + } + } + } +} diff --git a/brick.h b/brick.h new file mode 100644 index 0000000000000000000000000000000000000000..9e08d70411962c493492c5fb014ca303525ab47e --- /dev/null +++ b/brick.h @@ -0,0 +1,21 @@ +#ifndef BRICK_H +#define BRICK_H + +#include "raylib.h" +#include "ball.h" + +#define BRICK_ROWS 5 +#define BRICK_COLS 8 +#define BRICK_WIDTH 80 +#define BRICK_HEIGHT 30 + +typedef struct { + Rectangle rect; + bool active; +} Brick; + +void InitBricks(); +void DrawBricks(); +void CheckBrickCollision(Ball *ball); + +#endif diff --git a/main.c b/main.c new file mode 100644 index 0000000000000000000000000000000000000000..82eccd0246f77c97e973ec8f7c99621bae6a6d36 --- /dev/null +++ b/main.c @@ -0,0 +1,36 @@ +#include "raylib.h" +#include "paddle.h" +#include "ball.h" +#include "brick.h" + +#define SCREEN_WIDTH 800 +#define SCREEN_HEIGHT 600 + +int main() { + InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "Brick Breaker"); + SetTargetFPS(60); + + Paddle paddle = InitPaddle(); + Ball ball = InitBall(); + InitBricks(); + + while (!WindowShouldClose()) { + // Update game elements + UpdatePaddle(&paddle); + UpdateBall(&ball, &paddle); + CheckBrickCollision(&ball); + + // Render the game + BeginDrawing(); + ClearBackground(BLACK); + + DrawPaddle(paddle); + DrawBall(ball); + DrawBricks(); + + EndDrawing(); + } + + CloseWindow(); + return 0; +} diff --git a/paddle.c b/paddle.c new file mode 100644 index 0000000000000000000000000000000000000000..94741376e6b403ce61855764e84c2462ba5cca7f --- /dev/null +++ b/paddle.c @@ -0,0 +1,25 @@ +#include "paddle.h" + +#define PADDLE_WIDTH 100 +#define PADDLE_HEIGHT 20 +#define SCREEN_WIDTH 800 + +Paddle InitPaddle() { + Paddle paddle; + paddle.rect = (Rectangle){SCREEN_WIDTH / 2 - PADDLE_WIDTH / 2, 550, PADDLE_WIDTH, PADDLE_HEIGHT}; + paddle.speed = 5.0f; + return paddle; +} + +void UpdatePaddle(Paddle *paddle) { + if (IsKeyDown(KEY_LEFT) && paddle->rect.x > 0) { + paddle->rect.x -= paddle->speed; + } + if (IsKeyDown(KEY_RIGHT) && paddle->rect.x < SCREEN_WIDTH - paddle->rect.width) { + paddle->rect.x += paddle->speed; + } +} + +void DrawPaddle(Paddle paddle) { + DrawRectangleRec(paddle.rect, BLUE); +} diff --git a/paddle.h b/paddle.h new file mode 100644 index 0000000000000000000000000000000000000000..6440bb6721025c6f1a4dca371240a6699976e4b6 --- /dev/null +++ b/paddle.h @@ -0,0 +1,15 @@ +#ifndef PADDLE_H +#define PADDLE_H + +#include "raylib.h" + +typedef struct { + Rectangle rect; + float speed; +} Paddle; + +Paddle InitPaddle(); +void UpdatePaddle(Paddle *paddle); +void DrawPaddle(Paddle paddle); + +#endif