From e08080bdfd2d1abdc110c062e1b44f93112189cc Mon Sep 17 00:00:00 2001 From: Ben Date: Sat, 6 Oct 2018 11:49:38 +0100 Subject: [PATCH] Updated files, new rect plan and updated TODO.txt --- TODO.txt | 16 +++++++++++- crumpet-engine/camera.h | 26 +++++++------------ crumpet-engine/crumpet-engine.vcxproj | 2 ++ crumpet-engine/crumpet-engine.vcxproj.filters | 4 +++ crumpet-engine/entity.cpp | 10 +++---- crumpet-engine/main.cpp | 4 --- crumpet-engine/mathHelper.h | 11 ++++++++ crumpet-engine/rect.cpp | 9 +++++++ crumpet-engine/rect.h | 7 +++++ crumpet-engine/sprite.cpp | 19 +++++++++++--- crumpet-engine/sprite.h | 4 ++- 11 files changed, 80 insertions(+), 32 deletions(-) create mode 100644 crumpet-engine/rect.cpp create mode 100644 crumpet-engine/rect.h diff --git a/TODO.txt b/TODO.txt index d614450..c9c0975 100644 --- a/TODO.txt +++ b/TODO.txt @@ -2,11 +2,25 @@ CURRENT TODO LIST FOR THE DEVELOPMENT OF THE CRUMPET GAME ENGINE [ ] Fix entity / sprite resizing [ ] Add sprite methods to entity +[ ] Logger class + [ ] Maybe use preprocessor statements + [ ] Time and other useful logging methods + [ ] Empty constructor, instance method +[ ] Rect class to extend SDL_Rect and add conversion capabilitys, colision and intersection to it + [ ] Camera class to use Rect* instead of SLD_Rect* + [ ] Add and subtract (+ -) operators to add rectangles and subtract them together + [ ] Equal and not equal (!= ==) operators to return true / flase if the rectangles match + [ ] ToString function for easy logging + [ ] Setposition and translate methods + [ ] Intersects, contains methods + [ ] x,y,w,h properties + [ ] Center point + [ ] Maybe a point class [ ] Game camera class and redo rendering pipeline [ ] Add rotation and flipping for entities and sprites [x] Camera class [ ] Make the camera class control the rendering of the active scene - [ ] Change every class to use vector pointers and remove the initalization lists + [ ] Change every class / constructor to use vector pointers and remove the initalization lists [ ] Game coordinate system [ ] Render to GameWorld coordinates instead of screen coordinates [ ] Each entity and sprite should store a reference to Camera diff --git a/crumpet-engine/camera.h b/crumpet-engine/camera.h index c386b42..fc8eff3 100644 --- a/crumpet-engine/camera.h +++ b/crumpet-engine/camera.h @@ -1,28 +1,20 @@ #pragma once #include -#include #include "mathHelper.h" - -struct AspectRatio { - int w, h; - AspectRatio(int w, int h) : w(w), h(h) {} -}; +#include "rect.h" class Camera { public: - Camera() { - this->Zoom = 1.0f; - this->Pos = new Vec2(0, 0); - this->Rotation = 1.0f; - this->Aspectratio = new AspectRatio(16, 9); - } - Vec2* Pos; - float Zoom; - float Rotation; - AspectRatio* Aspectratio; + Camera(); + void TranslateView(Vec2* offset); + void TranslateViewX(int x); + void TranslateViewY(int y); + void SetSize(Vec2* size); + + void SetCenter(Vec2* point); virtual ~Camera(); private: - SDL_Rect* m_veiw; + Rect* m_view; }; diff --git a/crumpet-engine/crumpet-engine.vcxproj b/crumpet-engine/crumpet-engine.vcxproj index 1f7ea72..2ebd585 100644 --- a/crumpet-engine/crumpet-engine.vcxproj +++ b/crumpet-engine/crumpet-engine.vcxproj @@ -131,6 +131,7 @@ + @@ -142,6 +143,7 @@ + diff --git a/crumpet-engine/crumpet-engine.vcxproj.filters b/crumpet-engine/crumpet-engine.vcxproj.filters index 048fde3..0f830fc 100644 --- a/crumpet-engine/crumpet-engine.vcxproj.filters +++ b/crumpet-engine/crumpet-engine.vcxproj.filters @@ -9,6 +9,7 @@ + @@ -46,5 +47,8 @@ headers + + headers + \ No newline at end of file diff --git a/crumpet-engine/entity.cpp b/crumpet-engine/entity.cpp index 0861df0..2514e39 100644 --- a/crumpet-engine/entity.cpp +++ b/crumpet-engine/entity.cpp @@ -1,11 +1,11 @@ #include "entity.h" Entity::Entity(std::string name, SDL_Renderer* SDLRenderer) - : m_rectPos(0, 0), - m_rectSize(0, 0), - m_col(0, 0, 0, 0), - Pos(0, 0), - Size(0, 0) { + : m_rectPos(0, 0) + , m_rectSize(0, 0) + , m_col(0, 0, 0, 0) + , Pos(0, 0) + , Size(0, 0) { this->m_name = name; this->m_SDLRenderer = SDLRenderer; diff --git a/crumpet-engine/main.cpp b/crumpet-engine/main.cpp index d8bbdc2..c3abfc3 100644 --- a/crumpet-engine/main.cpp +++ b/crumpet-engine/main.cpp @@ -9,9 +9,6 @@ int main(int argc, char** argv) { Game game("Crumpet engine", SCREEN_WIDTH, SCREEN_HEIGHT, 0, 1000 / 60); // 1000 / 60); Timer timer; - Entity bay("bay", game.SDLRenderer); - bay.LoadTexture("/resources/bay.jpg"); - Sprite sans("sans", game.SDLRenderer, SpriteType::SPRITE_ANIMATED); sans.LoadSpriteTextures("/resources/sans-undertale-spritesheet.png"); sans.UseSpriteSheet(SpriteState::STATE_FRONT, 30, 9, 230, 300, 10, 4); @@ -48,7 +45,6 @@ int main(int argc, char** argv) { game.RenderClear(); game.RenderSprite(&sans); - game.RenderEntity(&bay); game.RenderSprite(&explosion); game.RenderUpdate(); } diff --git a/crumpet-engine/mathHelper.h b/crumpet-engine/mathHelper.h index d341fec..8ea2aba 100644 --- a/crumpet-engine/mathHelper.h +++ b/crumpet-engine/mathHelper.h @@ -1,5 +1,16 @@ #pragma once +const float DEG2RAD = 0.01745329251994329576923690768f; +const float RAD2DEG = 57.2957795130823208767981548141f; + +inline float ToRadian(const float Degree) { + return (Degree * DEG2RAD); +} + +inline float ToDegree(const float Radian) { + return (Radian * RAD2DEG); +} + struct Vec4 { int x, y, z, w; Vec4(int x, int y, int z, int w) : x(x), y(y), z(z), w(w) {} diff --git a/crumpet-engine/rect.cpp b/crumpet-engine/rect.cpp new file mode 100644 index 0000000..aa4ff35 --- /dev/null +++ b/crumpet-engine/rect.cpp @@ -0,0 +1,9 @@ +#include "rect.h" + +Rect::Rect() { + +} + +Rect::~Rect() { + +} diff --git a/crumpet-engine/rect.h b/crumpet-engine/rect.h new file mode 100644 index 0000000..2b1f85d --- /dev/null +++ b/crumpet-engine/rect.h @@ -0,0 +1,7 @@ +#pragma once +class Rect { +public: + Rect(); + virtual ~Rect(); +}; + diff --git a/crumpet-engine/sprite.cpp b/crumpet-engine/sprite.cpp index 6c765f4..e7f2643 100644 --- a/crumpet-engine/sprite.cpp +++ b/crumpet-engine/sprite.cpp @@ -1,8 +1,8 @@ #include "sprite.h" Sprite::Sprite(std::string name, SDL_Renderer* SDLRenderer, SpriteType mode) - : Entity(name, SDLRenderer), - Pos(0, 0) { + : Entity(name, SDLRenderer) + , Pos(0, 0) { this->m_SDLRenderer = SDLRenderer; this->Spritetype = mode; @@ -55,20 +55,26 @@ void Sprite::TickAninmation() { } // TODO: get this and the next method done correct +//at the moment the SpriteState(i) will just check for +//sprites with that state, and if they exist it will +//resize them, it needs to resize only the sprites +//in the std::map m_spriteSize void Sprite::ResizeSprites(Vec2* newSize) { - for (auto i = 0; i < m_spriteSize.size(); i++) { + for (unsigned int i = 0; i < m_spriteSize.size(); i++) { m_spriteSize[SpriteState(i)]->x = newSize->x; m_spriteSize[SpriteState(i)]->y = newSize->y; } } void Sprite::ResizeSpritesByFactor(float factor) { - for (auto i = 0; i < m_spriteSize.size(); i++) { + for (unsigned int i = 0; i < m_spriteSize.size(); i++) { m_spriteSize[SpriteState(i)]->x *= factor; m_spriteSize[SpriteState(i)]->y *= factor; } } +//These 2 methods work as they change a spesific and predefined +//sprite state void Sprite::ResizeSpriteState(SpriteState state, Vec2* newSize) { m_spriteSize[state]->x = newSize->x; m_spriteSize[state]->y = newSize->y; @@ -79,6 +85,11 @@ void Sprite::ResizeSpriteStateByFactor(SpriteState state, float factor) { m_spriteSize[state]->y *= factor; } +void Sprite::Move(Vec2* offset) { + Pos.x += offset->x; + Pos.y += offset->y; +} + void Sprite::Render() { SDL_Rect* currentFrameClip = m_spriteMaps[Spritestate][m_currentFrame]; Vec2* currentRenderSize = m_spriteSize[Spritestate]; diff --git a/crumpet-engine/sprite.h b/crumpet-engine/sprite.h index 9a62ade..b9f3c5f 100644 --- a/crumpet-engine/sprite.h +++ b/crumpet-engine/sprite.h @@ -57,7 +57,9 @@ public: void ResizeSpriteState(SpriteState state, Vec2* newSize); void ResizeSpriteStateByFactor(SpriteState state, float factor); - void Move(); + void Move(Vec2* offest); + void MoveX(int offest); + void MoveY(int offest); Vec2 Pos; void Render();