Fixed modularity issues

This commit is contained in:
Rendo 2026-03-10 16:13:58 +05:00
commit 7fe086a477
2 changed files with 43 additions and 52 deletions

View file

@ -1,20 +1,8 @@
#include <raylib.h> #include <raylib.h>
#include <raymath.h> #include <raymath.h>
#include "components.h"
class IComponent { Rectangle Pacman::getTextureRect(){
public:
virtual ~IComponent() {}
virtual void process() = 0;
};
class Pacman : IComponent {
const int speed = 64;
private:
Texture2D texture;
Vector2 position;
int facing;
Rectangle getTextureRect(){
Rectangle result; Rectangle result;
result.x = 0; result.x = 0;
result.y = facing*16; result.y = facing*16;
@ -22,21 +10,20 @@ class Pacman : IComponent {
result.width = 16; result.width = 16;
return result; return result;
} }
public: Pacman::Pacman() {
Pacman() {
this->texture = LoadTexture("assets/sprites/pacman.png"); this->texture = LoadTexture("assets/sprites/pacman.png");
this->facing = 0; this->facing = 0;
this->position = {0.,0.}; this->position = {0.,0.};
} }
Pacman(Vector2 position) { Pacman::Pacman(Vector2 position) {
this->texture = LoadTexture("assets/sprites/pacman.png"); this->texture = LoadTexture("assets/sprites/pacman.png");
this->facing = 0; this->facing = 0;
this->position = position; this->position = position;
} }
~Pacman() { Pacman::~Pacman() {
UnloadTexture(this->texture); UnloadTexture(this->texture);
} }
virtual void process() { void Pacman::process() {
float delta = GetFrameTime(); float delta = GetFrameTime();
// Input handling // Input handling
@ -53,4 +40,3 @@ class Pacman : IComponent {
// Drawing // Drawing
DrawTextureRec(this->texture, this->getTextureRect(), this->position, WHITE); DrawTextureRec(this->texture, this->getTextureRect(), this->position, WHITE);
} }
};

View file

@ -1,3 +1,6 @@
#ifndef COMPONENTS_H
#define COMPONENTS_H
#include <raylib.h> #include <raylib.h>
#include <raymath.h> #include <raymath.h>
@ -21,3 +24,5 @@ class Pacman : IComponent {
~Pacman(); ~Pacman();
virtual void process(); virtual void process();
}; };
#endif