From 1695d91cf887522bbaf8837b66095dc568d6d887 Mon Sep 17 00:00:00 2001 From: nosch Date: Sun, 31 Aug 2025 03:21:47 +0200 Subject: [PATCH] added header files --- src/entitys/base.cpp | 27 +++++++++++++++++++++++++ src/entitys/controllers.cpp | 0 src/entitys/controllers.hpp | 0 src/entitys/entitybase.hpp | 29 +++++++++++++++++++++++++++ src/render/textures.cpp | 40 +++++++++++++++---------------------- src/render/textures.hpp | 25 +++++++++++++++++++++++ 6 files changed, 97 insertions(+), 24 deletions(-) create mode 100644 src/entitys/base.cpp create mode 100644 src/entitys/controllers.cpp create mode 100644 src/entitys/controllers.hpp create mode 100644 src/entitys/entitybase.hpp create mode 100644 src/render/textures.hpp diff --git a/src/entitys/base.cpp b/src/entitys/base.cpp new file mode 100644 index 0000000..8da2fd2 --- /dev/null +++ b/src/entitys/base.cpp @@ -0,0 +1,27 @@ +#include "entitybase.hpp" +#include "../../include/raylib-cpp.hpp" +#include "../render/textures.hpp" +#include +#include +#include + +Entity::Entity(ID Id, int x, int y, std::string &n, int h, int maxh) { + id = Id; + position.x = x; + position.y = y; + health = h; + maxhealth = maxh; + nametag = n; +} + +void Entity::Update() { + if (controller) { + controller(*this); + }else { + std::cout << "Entity is missing an controller, doing nothing.\n"; + } +} + +void Entity::Draw() { + DrawTextureEx(entityTextures.GetTexture(id), position, 0, 0, WHITE); +} diff --git a/src/entitys/controllers.cpp b/src/entitys/controllers.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/entitys/controllers.hpp b/src/entitys/controllers.hpp new file mode 100644 index 0000000..e69de29 diff --git a/src/entitys/entitybase.hpp b/src/entitys/entitybase.hpp new file mode 100644 index 0000000..8e37e4c --- /dev/null +++ b/src/entitys/entitybase.hpp @@ -0,0 +1,29 @@ +#ifndef ENTITYBASE_HPP +#define ENTITYBASE_HPP + +#include "../../include/raylib-cpp.hpp" +#include "../render/textures.hpp" +#include +#include +#include + +struct Entity; + + +using ControllerFunc = std::function; + +struct Entity { + ID id; + raylib::Vector2 position; + int health; + int maxhealth; + std::string nametag; + ControllerFunc controller; + void Update(); + void Draw(); + + Entity(ID Id, int x, int y, std::string &n, int h, int maxh); + +}; + +#endif //ENTITYBASE_HPP diff --git a/src/render/textures.cpp b/src/render/textures.cpp index e765012..05de634 100644 --- a/src/render/textures.cpp +++ b/src/render/textures.cpp @@ -1,32 +1,31 @@ #include "../../include/raylib-cpp.hpp" -#include #include - +#include "textures.hpp" using namespace std; typedef int ID; -struct TextureAtlas { - vector atlas; +TextureAtlas::TextureAtlas (){ + atlas.clear(); +} - Texture GetTexture(ID id) { - if (atlas.size() >= id) { - return atlas[0]; - } - return atlas[id]; +Texture TextureAtlas::GetTexture(ID id) { + if (atlas.size() >= id) { + return atlas[0]; } + return atlas[id]; +} - void LoadImage(const char *path) { - atlas.push_back(LoadTexture(path)); - } +void TextureAtlas::LoadImage(const char *path) { + atlas.push_back(LoadTexture(path)); +} - void AddTexture(Texture texture){ - atlas.push_back(texture); - } - -}; +void TextureAtlas::AddTexture(Texture texture){ + atlas.push_back(texture); +} Texture defaultTexture; +TextureAtlas entityTextures; void GenDefaultTexture(){ Image img = GenImageChecked(64, 64, 16, 16, PURPLE, BLACK); @@ -34,10 +33,3 @@ void GenDefaultTexture(){ UnloadImage(img); } -TextureAtlas NewTextureAtlas() { - TextureAtlas atlas; - atlas.AddTexture(defaultTexture); - return atlas; -} - - diff --git a/src/render/textures.hpp b/src/render/textures.hpp new file mode 100644 index 0000000..52a654d --- /dev/null +++ b/src/render/textures.hpp @@ -0,0 +1,25 @@ +#ifndef TEXTURES_HPP +#define TEXTURES_HPP + +#include "../../include/raylib-cpp.hpp" +#include + +typedef int ID; + +struct TextureAtlas { + std::vectoratlas; + + Texture GetTexture(ID id); + void LoadImage(const char *path); + void AddTexture(Texture texture); + TextureAtlas(); + + +}; + +extern Texture defaultTexture; +extern TextureAtlas entityTextures; + +void GenDefaulTexture(); + +#endif // !TEXTURES_HPP