diff --git a/assets/sprites/pacman.png b/assets/sprites/pacman.png new file mode 100644 index 0000000..63e7438 Binary files /dev/null and b/assets/sprites/pacman.png differ 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; +}