added some new files and started on a GameWorld and Camera structures

This commit is contained in:
Ben
2018-10-03 14:08:56 +01:00
parent 72d3f76de4
commit 40ff1ecc4d
13 changed files with 114 additions and 41 deletions

View File

@@ -0,0 +1,9 @@
#include "camera.h"
Camera::Camera() {
}
Camera::~Camera() {
}

14
crumpet-engine/camera.h Normal file
View File

@@ -0,0 +1,14 @@
#pragma once
#include <vector>
#include <SDL.h>
#include "mathHelper.h"
class Camera {
public:
Camera();
Vec2* Pos;
virtual ~Camera();
private:
SDL_Rect* m_veiw;
};

View File

@@ -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;

View File

@@ -0,0 +1,9 @@
#include "gameWorld.h"
GameWorld::GameWorld() {
}
GameWorld::~GameWorld() {
}

View File

@@ -0,0 +1,12 @@
#pragma once
#include <vector>
#include "camera.h"
class GameWorld {
public:
GameWorld();
virtual ~GameWorld();
private:
std::vector<Camera*> m_cameras;
};

9
crumpet-engine/level.cpp Normal file
View File

@@ -0,0 +1,9 @@
#include "level.h"
Level::Level() {
}
Level::~Level() {
}

7
crumpet-engine/level.h Normal file
View File

@@ -0,0 +1,7 @@
#pragma once
class Level {
public:
Level();
virtual ~Level();
};

View File

@@ -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();
}

View File

@@ -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) {}
};

View File

@@ -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];

View File

@@ -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();

BIN
resources/explosion.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 637 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 215 KiB