line abstraction for entity class
This commit is contained in:
@@ -49,6 +49,14 @@ void Entity::SetRect(Vec2 pos, Vec2 size) {
|
||||
m_rect = { pos.x, pos.y, size.x, size.y };
|
||||
}
|
||||
|
||||
void Entity::SetVecPoints(std::vector<Vec4> points) {
|
||||
this->m_linePoints = points;
|
||||
}
|
||||
|
||||
void Entity::AddVecPoint(Vec4 point) {
|
||||
this->m_linePoints.push_back(point);
|
||||
}
|
||||
|
||||
void Entity::Render() {
|
||||
if (Rendertype == RenderType::MODE_TEXTURE)
|
||||
SDL_RenderCopy(m_SDLRenderer, m_texture, NULL, NULL);
|
||||
@@ -58,6 +66,12 @@ void Entity::Render() {
|
||||
SDL_RenderFillRect(m_SDLRenderer, &m_rect);
|
||||
if (Drawtype == PolyDrawType::DRAW_OUTLINE_RECT)
|
||||
SDL_RenderDrawRect(m_SDLRenderer, &m_rect);
|
||||
|
||||
if (Drawtype == PolyDrawType::DRAW_LINES) {
|
||||
for (unsigned int i = 0; i < m_linePoints.size(); i++) {
|
||||
SDL_RenderDrawLine(m_SDLRenderer, m_linePoints[i].x, m_linePoints[i].y, m_linePoints[i].z, m_linePoints[i].w);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,8 +34,8 @@ public:
|
||||
|
||||
void SetRect(Vec2 pos, Vec2 size);
|
||||
|
||||
void SetVecPoints(std::vector<Vec2> linePoints);
|
||||
void AddVecPoint(Vec2 point);
|
||||
void SetVecPoints(std::vector<Vec4> points);
|
||||
void AddVecPoint(Vec4 point);
|
||||
|
||||
void Render();
|
||||
|
||||
@@ -49,7 +49,7 @@ private:
|
||||
|
||||
Vec4 m_col;
|
||||
|
||||
std::vector<Vec2> m_linePoints;
|
||||
std::vector<Vec4> m_linePoints;
|
||||
SDL_Texture* m_texture;
|
||||
|
||||
// std::string PATH = "C:/Users/Ben/Desktop/crumpet-engine";
|
||||
|
||||
@@ -19,6 +19,10 @@ int main(int argc, char** argv) {
|
||||
outlineBox.SetDrawColour(Vec4(0x00, 0xFF, 0x00, 0xFF));
|
||||
outlineBox.SetRect(Vec2(SCREEN_WIDTH / 6, SCREEN_HEIGHT / 6), Vec2(SCREEN_WIDTH * 2 / 3, SCREEN_HEIGHT * 2 / 3));
|
||||
|
||||
Entity lineMesh("line mesh", game.SDLRenderer, PolyDrawType::DRAW_LINES);
|
||||
lineMesh.SetDrawColour(Vec4(0x00, 0x00, 0xFF, 0xFF));
|
||||
lineMesh.AddVecPoint(Vec4(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT));
|
||||
|
||||
while (!game.IsDisplayClosed()) {
|
||||
game.PollEvents();
|
||||
|
||||
@@ -28,6 +32,7 @@ int main(int argc, char** argv) {
|
||||
|
||||
game.RenderEntity(&box);
|
||||
game.RenderEntity(&outlineBox);
|
||||
game.RenderEntity(&lineMesh);
|
||||
|
||||
game.RenderUpdate();
|
||||
}
|
||||
|
||||
@@ -59,36 +59,3 @@ struct Vec2f {
|
||||
|
||||
float x, 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;
|
||||
}; */
|
||||
|
||||
9
crumpet-engine/sprite.cpp
Normal file
9
crumpet-engine/sprite.cpp
Normal file
@@ -0,0 +1,9 @@
|
||||
#include "sprite.h"
|
||||
|
||||
Sprite::Sprite() {
|
||||
|
||||
}
|
||||
|
||||
Sprite::~Sprite() {
|
||||
|
||||
}
|
||||
10
crumpet-engine/sprite.h
Normal file
10
crumpet-engine/sprite.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include "entity.h";
|
||||
|
||||
class Sprite : public Entity {
|
||||
public:
|
||||
Sprite();
|
||||
virtual ~Sprite();
|
||||
};
|
||||
|
||||
BIN
resources/sans-undertale-spritesheet.png
Normal file
BIN
resources/sans-undertale-spritesheet.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 84 KiB |
Reference in New Issue
Block a user