added header files
This commit is contained in:
@@ -0,0 +1,27 @@
|
|||||||
|
#include "entitybase.hpp"
|
||||||
|
#include "../../include/raylib-cpp.hpp"
|
||||||
|
#include "../render/textures.hpp"
|
||||||
|
#include <functional>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
#ifndef ENTITYBASE_HPP
|
||||||
|
#define ENTITYBASE_HPP
|
||||||
|
|
||||||
|
#include "../../include/raylib-cpp.hpp"
|
||||||
|
#include "../render/textures.hpp"
|
||||||
|
#include <functional>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
struct Entity;
|
||||||
|
|
||||||
|
|
||||||
|
using ControllerFunc = std::function<void(Entity&)>;
|
||||||
|
|
||||||
|
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
|
||||||
+8
-16
@@ -1,32 +1,31 @@
|
|||||||
#include "../../include/raylib-cpp.hpp"
|
#include "../../include/raylib-cpp.hpp"
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include "textures.hpp"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
typedef int ID;
|
typedef int ID;
|
||||||
|
|
||||||
struct TextureAtlas {
|
TextureAtlas::TextureAtlas (){
|
||||||
vector<Texture> atlas;
|
atlas.clear();
|
||||||
|
}
|
||||||
|
|
||||||
Texture GetTexture(ID id) {
|
Texture TextureAtlas::GetTexture(ID id) {
|
||||||
if (atlas.size() >= id) {
|
if (atlas.size() >= id) {
|
||||||
return atlas[0];
|
return atlas[0];
|
||||||
}
|
}
|
||||||
return atlas[id];
|
return atlas[id];
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoadImage(const char *path) {
|
void TextureAtlas::LoadImage(const char *path) {
|
||||||
atlas.push_back(LoadTexture(path));
|
atlas.push_back(LoadTexture(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddTexture(Texture texture){
|
void TextureAtlas::AddTexture(Texture texture){
|
||||||
atlas.push_back(texture);
|
atlas.push_back(texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
Texture defaultTexture;
|
Texture defaultTexture;
|
||||||
|
TextureAtlas entityTextures;
|
||||||
|
|
||||||
void GenDefaultTexture(){
|
void GenDefaultTexture(){
|
||||||
Image img = GenImageChecked(64, 64, 16, 16, PURPLE, BLACK);
|
Image img = GenImageChecked(64, 64, 16, 16, PURPLE, BLACK);
|
||||||
@@ -34,10 +33,3 @@ void GenDefaultTexture(){
|
|||||||
UnloadImage(img);
|
UnloadImage(img);
|
||||||
}
|
}
|
||||||
|
|
||||||
TextureAtlas NewTextureAtlas() {
|
|
||||||
TextureAtlas atlas;
|
|
||||||
atlas.AddTexture(defaultTexture);
|
|
||||||
return atlas;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
#ifndef TEXTURES_HPP
|
||||||
|
#define TEXTURES_HPP
|
||||||
|
|
||||||
|
#include "../../include/raylib-cpp.hpp"
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
typedef int ID;
|
||||||
|
|
||||||
|
struct TextureAtlas {
|
||||||
|
std::vector<Texture>atlas;
|
||||||
|
|
||||||
|
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
|
||||||
Reference in New Issue
Block a user