diff --git a/crumpet-engine/camera.cpp b/crumpet-engine/camera.cpp new file mode 100644 index 0000000..3b5e737 --- /dev/null +++ b/crumpet-engine/camera.cpp @@ -0,0 +1,9 @@ +#include "camera.h" + +Camera::Camera() { + +} + +Camera::~Camera() { + +} diff --git a/crumpet-engine/camera.h b/crumpet-engine/camera.h new file mode 100644 index 0000000..6478698 --- /dev/null +++ b/crumpet-engine/camera.h @@ -0,0 +1,14 @@ +#pragma once + +#include +#include +#include "mathHelper.h" + +class Camera { +public: + Camera(); + Vec2* Pos; + virtual ~Camera(); +private: + SDL_Rect* m_veiw; +}; diff --git a/crumpet-engine/entity.h b/crumpet-engine/entity.h index 5838cba..f09b658 100644 --- a/crumpet-engine/entity.h +++ b/crumpet-engine/entity.h @@ -45,8 +45,8 @@ public: virtual ~Entity(); protected: - //std::string PATH = "C:/Users/Ben/Desktop/crumpet-engine"; - std::string PATH = "E:/Games/crumpet-engine"; + std::string PATH = "C:/Users/Ben/Desktop/crumpet-engine"; + // std::string PATH = "E:/Games/crumpet-engine"; private: std::string m_name; diff --git a/crumpet-engine/gameWorld.cpp b/crumpet-engine/gameWorld.cpp new file mode 100644 index 0000000..7fb7000 --- /dev/null +++ b/crumpet-engine/gameWorld.cpp @@ -0,0 +1,9 @@ +#include "gameWorld.h" + +GameWorld::GameWorld() { + +} + +GameWorld::~GameWorld() { + +} diff --git a/crumpet-engine/gameWorld.h b/crumpet-engine/gameWorld.h new file mode 100644 index 0000000..f910cfe --- /dev/null +++ b/crumpet-engine/gameWorld.h @@ -0,0 +1,12 @@ +#pragma once + +#include +#include "camera.h" + +class GameWorld { +public: + GameWorld(); + virtual ~GameWorld(); +private: + std::vector m_cameras; +}; diff --git a/crumpet-engine/level.cpp b/crumpet-engine/level.cpp new file mode 100644 index 0000000..e722d8a --- /dev/null +++ b/crumpet-engine/level.cpp @@ -0,0 +1,9 @@ +#include "level.h" + +Level::Level() { + +} + +Level::~Level() { + +} diff --git a/crumpet-engine/level.h b/crumpet-engine/level.h new file mode 100644 index 0000000..08f8d42 --- /dev/null +++ b/crumpet-engine/level.h @@ -0,0 +1,7 @@ +#pragma once + +class Level { +public: + Level(); + virtual ~Level(); +}; diff --git a/crumpet-engine/main.cpp b/crumpet-engine/main.cpp index 0a28371..e2b8674 100644 --- a/crumpet-engine/main.cpp +++ b/crumpet-engine/main.cpp @@ -14,6 +14,12 @@ int main(int argc, char** argv) { sans.UseSpriteSheet(SpriteState::STATE_FRONT, 30, 9, 230, 300, 10, 4); sans.UseSpriteSheet(SpriteState::STATE_RIGHT, 30, 320, 170, 300, 10, 4); sans.UseSpriteSheet(SpriteState::STATE_LEFT, 40, 640, 170, 300, 10, 4); + sans.Pos = Vec2(100, 100); + + Sprite explosion("explosion", game.SDLRenderer, SpriteType::SPRITE_ANIMATED); + explosion.LoadSpriteTextures("/resources/explosion.png"); + explosion.UseSpriteSheet(SpriteState::STATE_DEFAULT, 1, 260, 65, 63, 0, 16); + explosion.ResizeSpriteStateByFactor(SpriteState::STATE_DEFAULT, 4); while (!game.IsDisplayClosed()) { game.PollEvents(); @@ -27,6 +33,7 @@ int main(int argc, char** argv) { if (timer.ticks % 5 == 0) { sans.TickAninmation(); + explosion.TickAninmation(); } timer.Tick(); @@ -34,6 +41,7 @@ int main(int argc, char** argv) { game.RenderClear(); game.RenderSprite(&sans); + game.RenderSprite(&explosion); game.RenderUpdate(); } diff --git a/crumpet-engine/mathHelper.h b/crumpet-engine/mathHelper.h index e0de74f..d341fec 100644 --- a/crumpet-engine/mathHelper.h +++ b/crumpet-engine/mathHelper.h @@ -1,61 +1,31 @@ #pragma once struct Vec4 { - Vec4(int x, int y, int z, int w) { - this->x = x; - this->y = y; - this->z = z; - this->w = w; - } - int x, y, z, w; + Vec4(int x, int y, int z, int w) : x(x), y(y), z(z), w(w) {} }; struct Vec4f { - Vec4f(float x, float y, float z, float w) { - this->x = x; - this->y = y; - this->z = z; - this->w = w; - } - float x, y, z, w; + Vec4f(float x, float y, float z, float w) : x(x), y(y), z(z), w(w) {} }; struct Vec3 { - Vec3(int x, int y, int z) { - this->x = x; - this->y = y; - this->z = z; - } - int x, y, z; + Vec3(int x, int y, int z) : x(x), y(y), z(z) {} }; struct Vec3f { - Vec3f(float x, float y, float z) { - this->x = x; - this->y = y; - this->z = z; - } - float x, y, z; + Vec3f(float x, float y, float z) : x(x), y(y), z(z) {} }; struct Vec2 { - Vec2(int x, int y) { - this->x = x; - this->y = y; - } - int x, y; + Vec2(int x, int y) : x(x), y(y) {} }; struct Vec2f { - Vec2f(float x, float y) { - this->x = x; - this->y = y; - } - float x, y; + Vec2f(float x, float y) : x(x), y(y) {} }; diff --git a/crumpet-engine/sprite.cpp b/crumpet-engine/sprite.cpp index 28da462..6c765f4 100644 --- a/crumpet-engine/sprite.cpp +++ b/crumpet-engine/sprite.cpp @@ -2,8 +2,7 @@ Sprite::Sprite(std::string name, SDL_Renderer* SDLRenderer, SpriteType mode) : Entity(name, SDLRenderer), - Pos(0, 0), - Size(0, 0) { + Pos(0, 0) { this->m_SDLRenderer = SDLRenderer; this->Spritetype = mode; @@ -55,6 +54,31 @@ void Sprite::TickAninmation() { if (m_currentFrame > m_spriteMaps[Spritestate].size()) m_currentFrame = 1; } +// TODO: get this and the next method done correct +void Sprite::ResizeSprites(Vec2* newSize) { + for (auto 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++) { + m_spriteSize[SpriteState(i)]->x *= factor; + m_spriteSize[SpriteState(i)]->y *= factor; + } +} + +void Sprite::ResizeSpriteState(SpriteState state, Vec2* newSize) { + m_spriteSize[state]->x = newSize->x; + m_spriteSize[state]->y = newSize->y; +} + +void Sprite::ResizeSpriteStateByFactor(SpriteState state, float factor) { + m_spriteSize[state]->x *= factor; + m_spriteSize[state]->y *= factor; +} + 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 e220875..9a62ade 100644 --- a/crumpet-engine/sprite.h +++ b/crumpet-engine/sprite.h @@ -17,7 +17,11 @@ enum struct SpriteType { enum struct SpriteState { STATE_DEFAULT, STATE_LEFT, + STATE_ACCELERATING_LEFT, + STATE_RUNNING_LEFT, STATE_RIGHT, + STATE_ACCELERATING_RIGHT, + STATE_RUNNING_RIGHT, STATE_UP, STATE_DOWN, STATE_TOP, @@ -25,8 +29,10 @@ enum struct SpriteState { STATE_FRONT, STATE_BACK, STATE_JUMP, + STATE_CROUCHING, STATE_CROUCH, STATE_ATTACKING, + STATE_DEATH, STATE_MISC1, STATE_MISC2, STATE_MISC3, @@ -45,10 +51,15 @@ public: void UseSpriteSheet(SpriteState state, int startX, int startY, int width, int height, int separation, int frames); void TickAninmation(SpriteState state); void TickAninmation(); + + void ResizeSprites(Vec2* newSize); + void ResizeSpritesByFactor(float factor); + void ResizeSpriteState(SpriteState state, Vec2* newSize); + void ResizeSpriteStateByFactor(SpriteState state, float factor); + void Move(); Vec2 Pos; - Vec2 Size; void Render(); virtual ~Sprite(); diff --git a/resources/explosion.png b/resources/explosion.png new file mode 100644 index 0000000..4d1b3a3 Binary files /dev/null and b/resources/explosion.png differ diff --git a/resources/woman-spritesheet.png b/resources/woman-spritesheet.png new file mode 100644 index 0000000..de7b252 Binary files /dev/null and b/resources/woman-spritesheet.png differ