MathHelper and entity abstractions
This commit is contained in:
@@ -128,11 +128,13 @@
|
||||
<ClCompile Include="entity.cpp" />
|
||||
<ClCompile Include="game.cpp" />
|
||||
<ClCompile Include="main.cpp" />
|
||||
<ClCompile Include="mathHelper.cpp" />
|
||||
<ClCompile Include="renderer.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="entity.h" />
|
||||
<ClInclude Include="game.h" />
|
||||
<ClInclude Include="mathHelper.h" />
|
||||
<ClInclude Include="renderer.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
<ClCompile Include="entity.cpp" />
|
||||
<ClCompile Include="renderer.cpp" />
|
||||
<ClCompile Include="game.cpp" />
|
||||
<ClCompile Include="mathHelper.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Filter Include="headers">
|
||||
@@ -21,5 +22,8 @@
|
||||
<ClInclude Include="renderer.h">
|
||||
<Filter>headers</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="mathHelper.h">
|
||||
<Filter>headers</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -1,9 +1,9 @@
|
||||
#include "entity.h"
|
||||
|
||||
Entity::Entity(std::string name, SDL_Renderer* SDLRenderer, EntityType mode) {
|
||||
Entity::Entity(std::string name, SDL_Renderer* SDLRenderer, RenderType mode) {
|
||||
this->m_name = name;
|
||||
this->m_SDLRenderer = SDLRenderer;
|
||||
this->RenderType = mode;
|
||||
this->Rendertype = mode;
|
||||
}
|
||||
|
||||
bool Entity::LoadTexture(std::string path) {
|
||||
@@ -18,12 +18,25 @@ bool Entity::LoadTexture(std::string path) {
|
||||
std::cout << "Unable to create texture from:" << (PATH + path).c_str() << " SDL ERROR: " << SDL_GetError() << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
SDL_FreeSurface(loadedSurface);
|
||||
return true;
|
||||
}
|
||||
|
||||
void Entity::SetVecPoints(std::vector<Vec2> polyPoints) {
|
||||
this->m_polyPoints = polyPoints;
|
||||
}
|
||||
|
||||
void Entity::AddVecPoint(Vec2 point) {
|
||||
this->m_polyPoints.push_back(point);
|
||||
}
|
||||
|
||||
void Entity::SetPolyDrawType(PolyDrawType type) {
|
||||
this->Drawtype = type;
|
||||
}
|
||||
|
||||
void Entity::Render() {
|
||||
if (RenderType == EntityType::MODE_TEXTURE)
|
||||
if (Rendertype == RenderType::MODE_TEXTURE)
|
||||
SDL_RenderCopy(m_SDLRenderer, m_texture, NULL, NULL);
|
||||
// if (RenderType == EntityType::MODE_POLYGON)
|
||||
|
||||
|
||||
@@ -2,33 +2,50 @@
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <SDL.h>
|
||||
#include <SDL_image.h>
|
||||
#include "mathHelper.h"
|
||||
|
||||
enum struct EntityType {
|
||||
enum struct RenderType {
|
||||
MODE_DEFAULT,
|
||||
MODE_TEXTURE,
|
||||
MODE_POLYGON
|
||||
};
|
||||
|
||||
enum struct PolyDrawType {
|
||||
DRAW_DEFAULT,
|
||||
DRAW_FILLED_RECT,
|
||||
DRAW_OUTLINE_RECT,
|
||||
DRAW_LINES
|
||||
};
|
||||
|
||||
class Entity {
|
||||
public:
|
||||
Entity(std::string name, SDL_Renderer* SDLRenderer, EntityType mode); // Texture overload
|
||||
Entity(std::string name, SDL_Renderer* SDLRenderer, RenderType mode); // Texture overload
|
||||
// Entity(); // Polygon overload
|
||||
|
||||
EntityType RenderType = EntityType::MODE_DEFAULT;
|
||||
RenderType Rendertype = RenderType::MODE_DEFAULT;
|
||||
PolyDrawType Drawtype = PolyDrawType::DRAW_DEFAULT;
|
||||
|
||||
bool LoadTexture(std::string path);
|
||||
|
||||
void SetVecPoints(std::vector<Vec2> polyPoints);
|
||||
void AddVecPoint(Vec2 point);
|
||||
void SetPolyDrawType(PolyDrawType type);
|
||||
|
||||
void Render();
|
||||
|
||||
virtual ~Entity();
|
||||
private:
|
||||
std::string m_name;
|
||||
|
||||
// std::string PATH = "C:/Users/Ben/Desktop/crumpet-engine";
|
||||
std::string PATH = "E:/Games/crumpet-engine";
|
||||
|
||||
std::vector<Vec2> m_polyPoints;
|
||||
SDL_Texture* m_texture;
|
||||
|
||||
std::string PATH = "C:/Users/Ben/Desktop/crumpet-engine";
|
||||
// std::string PATH = "E:/Games/crumpet-engine";
|
||||
|
||||
SDL_Renderer* m_SDLRenderer;
|
||||
};
|
||||
|
||||
|
||||
@@ -8,10 +8,10 @@
|
||||
int main(int argc, char** argv) {
|
||||
Game game("Crumpet engine", SCREEN_WIDTH, SCREEN_HEIGHT, 0, 60);
|
||||
|
||||
Entity mario("mario", game.SDLRenderer, EntityType::MODE_TEXTURE);
|
||||
Entity mario("mario", game.SDLRenderer, RenderType::MODE_TEXTURE);
|
||||
mario.LoadTexture("/resources/mario.png");
|
||||
|
||||
Entity box("box", game.SDLRenderer, EntityType::MODE_POLYGON);
|
||||
Entity box("box", game.SDLRenderer, RenderType::MODE_POLYGON);
|
||||
|
||||
|
||||
while (!game.IsDisplayClosed()) {
|
||||
|
||||
1
crumpet-engine/mathHelper.cpp
Normal file
1
crumpet-engine/mathHelper.cpp
Normal file
@@ -0,0 +1 @@
|
||||
#include "mathHelper.h"
|
||||
55
crumpet-engine/mathHelper.h
Normal file
55
crumpet-engine/mathHelper.h
Normal file
@@ -0,0 +1,55 @@
|
||||
#pragma once
|
||||
|
||||
struct Vec3 {
|
||||
Vec3(float x, float y, float z) {
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
this->z = z;
|
||||
}
|
||||
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
};
|
||||
|
||||
struct Vec2 {
|
||||
Vec2(float x, float y) {
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
}
|
||||
|
||||
float x;
|
||||
float y;
|
||||
};
|
||||
|
||||
/* struct Vec2SInt16 {
|
||||
Vec2SInt16(Sint16 x, Sint16 y) {
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
}
|
||||
|
||||
Sint16 x;
|
||||
Sint16 y;
|
||||
};
|
||||
|
||||
struct Vec2UInt16 {
|
||||
Vec2UInt16(Uint16 x, Uint16 y) {
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
}
|
||||
|
||||
Uint16 x;
|
||||
Uint16 y;
|
||||
};
|
||||
|
||||
struct RectVect {
|
||||
RectVect(Vec2SInt16 pos, Vec2UInt16 size)
|
||||
: pos(1, 1),
|
||||
size(1, 1) {
|
||||
this->pos = pos;
|
||||
this->size = size;
|
||||
}
|
||||
|
||||
Vec2SInt16 pos;
|
||||
Vec2UInt16 size;
|
||||
}; */
|
||||
Reference in New Issue
Block a user