From 5273927cb35b4ae25cc5e5316d1f4065adcacce3 Mon Sep 17 00:00:00 2001 From: rendo Date: Tue, 10 Mar 2026 11:50:58 +0500 Subject: [PATCH] Pacman --- assets/sprites/pacman.png | Bin 0 -> 461 bytes compiler_flags.txt | 3 ++ main.cpp | 22 -------------- makefile | 5 ++-- src/main.cpp | 60 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 66 insertions(+), 24 deletions(-) create mode 100644 assets/sprites/pacman.png delete mode 100644 main.cpp create mode 100644 src/main.cpp diff --git a/assets/sprites/pacman.png b/assets/sprites/pacman.png new file mode 100644 index 0000000000000000000000000000000000000000..63e743875caeadeae390af711de547d014acc72b GIT binary patch literal 461 zcmV;;0W$uHP)Px#1am@3R0s$N2z&@+hyVZqcS%G+RA_$m+jnoV+Xtp8)jeuYolF)e=~f zTMXMjYi|(g0I1E&0+3SA>aSh`%M7$Y4BG<~h+#A&)v@&>XD&445K04CLENH*IoNp) zBT0~m<5(2n*x`txYqbYji6TIp0HmX&`f0%BeO*}~9YFrw6q2;HrJ52VYO`Ve*aW>Q zNhSYUm=NU&TZ0H!LROeYmSmXSau!SlV0b-n^?&Bgr~qzu2#)J^NGzlIRL;1wlNmuuZ)V{00000NkvXXu0mjf Dietoq literal 0 HcmV?d00001 diff --git a/compiler_flags.txt b/compiler_flags.txt index 66713b8..63dd840 100644 --- a/compiler_flags.txt +++ b/compiler_flags.txt @@ -1,2 +1,5 @@ -Wall -lraylib +-lstdc++ +-lm +-v diff --git a/main.cpp b/main.cpp deleted file mode 100644 index 8b44b01..0000000 --- a/main.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include - -int main() { - const int screen_height = 720; - const int screen_width = 1280; - - InitWindow(screen_width, screen_height, "Test game"); - - SetTargetFPS(60); - - while (WindowShouldClose() == false) { - BeginDrawing(); - - ClearBackground(RAYWHITE); - - DrawText("Congrats to me, I created first window!", 190, 200, 20, LIGHTGRAY); - - EndDrawing(); - } - - return 0; -} diff --git a/makefile b/makefile index 1e472d0..5481246 100644 --- a/makefile +++ b/makefile @@ -1,8 +1,9 @@ CFLAGS=$(shell cat compiler_flags.txt) -build/raylib-test-linux.x86_64 : main.cpp +build/raylib-test-linux.x86_64 : src/main.cpp mkdir -p build - clang main.cpp $(CFLAGS) -o build/raylib-test-linux.x86_64 + clang src/main.cpp $(CFLAGS) -o build/raylib-test-linux.x86_64 + clean : rm -r build/* diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..6f7e132 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,60 @@ +#include +#include +#include + +class Pacman { + const int speed = 16; + private: + Texture2D texture; + Vector2 position; + int facing; + + Rectangle getTextureRect(){ + Rectangle result; + result.x = 0; + result.y = facing; + result.height = 16; + result.width = 16; + return result; + } + public: + Pacman() { + this->texture = LoadTexture("assets/sprites/pacman.png"); + this->facing = 0; + } + ~Pacman() { + UnloadTexture(this->texture); + } + + void process() { + float delta = GetFrameTime(); + + // Movement in direction + double angle = PI/2.0*facing; + Vector2 direction = {(float)(cos(angle)),(float)(sin(angle))}; + this->position = Vector2Add(this->position,Vector2Scale(direction, delta * (float)speed)); + + DrawTextureRec(this->texture, this->getTextureRect(), this->position, WHITE); + } +}; + +int main() { + const int screen_height = 320; + const int screen_width = 320; + + InitWindow(screen_width, screen_height, "Test game"); + + SetTargetFPS(60); + + Pacman pacman; + + while (WindowShouldClose() == false) { + BeginDrawing(); + + pacman.process(); + + EndDrawing(); + } + + return 0; +}