From 9b1acbbe28626bd240d8eb76037c207562e7fac9 Mon Sep 17 00:00:00 2001 From: Rendo Date: Tue, 10 Mar 2026 21:51:01 +0500 Subject: [PATCH] Separated interfaces --- src/components.cpp | 26 +++++++++++++++++++++++++- src/components.h | 30 +++++++++++++++++++++++++++--- src/main.cpp | 8 ++++++-- 3 files changed, 58 insertions(+), 6 deletions(-) diff --git a/src/components.cpp b/src/components.cpp index 15413f6..a06d782 100644 --- a/src/components.cpp +++ b/src/components.cpp @@ -2,6 +2,8 @@ #include #include "components.h" +// Pacman definitions + Rectangle Pacman::getTextureRect(){ Rectangle result; result.x = 0; @@ -36,7 +38,29 @@ void Pacman::process() { double angle = PI/2.0*facing; Vector2 direction = {(float)(cos(angle)),(float)(sin(-angle))}; this->position = Vector2Add(this->position,Vector2Scale(direction, delta * (float)speed)); - + } + +void Pacman::draw() { // Drawing DrawTextureRec(this->texture, this->getTextureRect(), this->position, WHITE); } + +// Wall definitions + +Wall::Wall() { + this->texture = LoadTexture("assets/sprites/walls.png"); +} + +Wall::~Wall() { + UnloadTexture(this->texture); +} + +void Wall::ready() { + // Set neigbors depending on state +} + +void Wall::draw() { + // Draw based on neighbors +} + + diff --git a/src/components.h b/src/components.h index d515a45..7f8c418 100644 --- a/src/components.h +++ b/src/components.h @@ -4,13 +4,26 @@ #include #include -class IComponent { +class IProcessable { public: - virtual ~IComponent() {} + virtual ~IProcessable() {} + // Called every frame virtual void process() = 0; }; +class IReadible { + public: + virtual ~IReadible() {} + // Called when the level is set up + virtual void ready() = 0; +}; -class Pacman : IComponent { +class IDrawable { + public: + virtual ~IDrawable() {} + virtual void draw() = 0; +}; + +class Pacman : public IProcessable, public IDrawable { const int speed = 64; private: Texture2D texture; @@ -23,6 +36,17 @@ class Pacman : IComponent { Pacman(Vector2 position); ~Pacman(); virtual void process(); + virtual void draw(); +}; + +class Wall : public IReadible, public IDrawable { + private: + Texture2D texture; + public: + Wall(); + ~Wall(); + virtual void ready(); + virtual void draw(); }; #endif diff --git a/src/main.cpp b/src/main.cpp index 9afd159..5356416 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -13,11 +13,15 @@ int main() { Pacman pacman = Pacman(Vector2{screen_width/2.0,screen_height/2.0}); while (WindowShouldClose() == false) { + + + pacman.process(); + BeginDrawing(); ClearBackground(BLACK); - - pacman.process(); + + pacman.draw(); EndDrawing(); }