made the player a Entity and gave it a controller
This commit is contained in:
+10
-4
@@ -5,22 +5,28 @@
|
||||
#include <sys/types.h>
|
||||
#include <iostream>
|
||||
|
||||
Entity::Entity(ID Id, raylib::Rectangle Rect, std::string &n, int h, int maxh) {
|
||||
void emptycontroller (Entity &e, float deltatime) {
|
||||
std::cout << "doing no shit cuz funny lmao";
|
||||
}
|
||||
|
||||
Entity::Entity(ID Id, raylib::Rectangle Rect,std::string n, int h, int maxh) {
|
||||
id = Id;
|
||||
spriteid = 0;
|
||||
rect = Rect;
|
||||
health = h;
|
||||
maxhealth = maxh;
|
||||
nametag = n;
|
||||
controller = emptycontroller;
|
||||
}
|
||||
|
||||
void Entity::Update() {
|
||||
void Entity::Update(float deltatime) {
|
||||
if (controller) {
|
||||
controller(*this);
|
||||
controller(*this, deltatime);
|
||||
}else {
|
||||
std::cout << "Entity is missing an controller, doing nothing.\n";
|
||||
}
|
||||
}
|
||||
|
||||
void Entity::Draw() {
|
||||
DrawTextureEx(entityTextures.GetTexture(id), raylib::Vector2(rect.x, rect.y), 0, 0, WHITE);
|
||||
DrawTextureEx(entityTextures.GetTexture(spriteid), raylib::Vector2(rect.x, rect.y), 0, 0, WHITE);
|
||||
}
|
||||
|
||||
@@ -10,19 +10,21 @@
|
||||
struct Entity;
|
||||
|
||||
|
||||
using ControllerFunc = std::function<void(Entity&)>;
|
||||
using ControllerFunc = std::function<void(Entity&, float)>;
|
||||
|
||||
struct Entity {
|
||||
ID id;
|
||||
ID spriteid;
|
||||
raylib::Rectangle rect;
|
||||
int health;
|
||||
int maxhealth;
|
||||
std::string nametag;
|
||||
ControllerFunc controller;
|
||||
void Update();
|
||||
Vector2 velocity;
|
||||
void Update(float deltatime);
|
||||
void Draw();
|
||||
|
||||
Entity(ID Id, raylib::Rectangle rect, std::string &n, int h, int maxh);
|
||||
Entity(ID Id, raylib::Rectangle rect, std::string n, int h, int maxh);
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user