texturess

This commit is contained in:
Ben Kyd
2020-08-30 19:13:47 +00:00
parent 5bc8776a48
commit 41e8e8c161
10 changed files with 52191 additions and 22 deletions

View File

@@ -8,8 +8,8 @@ class Entity;
class Camera
{
public:
olc::vd2d Coords;
olc::vd2d ViewPort;
olc::vf2d Coords;
olc::vi2d ViewPort;
void Update(float fTime);

View File

@@ -1,3 +1,41 @@
#include "Dungeon.hpp"
#include "Things.hpp"
#include "Camera.hpp"
Dungeon::Dungeon()
{
ActiveCamera = new Camera();
ActiveCamera->Coords = { 0.0f, 0.0f };
ActiveCamera->ViewPort = { 1280, 720 };
}
void Dungeon::Generate()
{
}
void Dungeon::SpawnEntity(Entity* entity)
{
Entities[entity->Coords] = entity;
}
void Dungeon::Input(olc::PixelGameEngine* engine)
{
// engine->GetKey(olc::W);
}
void Dungeon::Update(float fTime)
{
}
void Dungeon::Draw(olc::PixelGameEngine* engine)
{
}
Dungeon::~Dungeon()
{
}

View File

@@ -5,25 +5,34 @@
#include "olcPixelGameEngine.hpp"
class Camera;
class Tile;
class Entity;
class Playable;
class FixedItem;
// Single level dungeon, no need for fancy levels
class Dungeon
{
public:
Dungeon();
void Generate();
void SpawnEntity();
void SpawnEntity(Entity* entity);
void Input(olc::PixelGameEngine* engine);
void Update(float fTime);
void Draw(olc::PixelGameEngine* engine);
Playable* Player;
Camera* ActiveCamera;
std::unordered_map<olc::vd2d, Tile*> Dungeon;
std::unordered_map<olc::vd2d, Entity*> Entities;
std::unordered_map<olc::vd2d, FixedItem*> FixedItems;
std::unordered_map<olc::vi2d, Tile*> DungeonTiles;
std::unordered_map<olc::vf2d, Entity*> Entities; // key here could be room?
std::unordered_map<olc::vf2d, FixedItem*> FixedItems;
~Dungeon();
};
#endif

View File

@@ -10,6 +10,6 @@ void Tile::Update(float fTime)
void Tile::Draw(olc::PixelGameEngine* engine, Camera* camera)
{
engine->DrawPartialSprite(
{ Coords.x + camera->Coords.x, Coords.y + camera->Coords.y },
{ static_cast<int>(Coords.x + camera->Coords.x), static_cast<int>(Coords.y + camera->Coords.y) },
SpriteMap, SpriteTextureMask, { 16, 16 });
}

View File

@@ -55,8 +55,10 @@ namespace EEntity
class Entity
{
public:
olc::vd2d Coords;
olc::vi2d Coords;
EEntity::Type Type;
olc::vf2d SpriteTextureMask;
olc::Sprite* SpriteMap;
};
class Item : public Entity
@@ -82,11 +84,11 @@ public:
class Tile
{
public:
olc::vd2d Coords;
olc::vi2d Coords;
ETile::Type Type;
ETile::State State;
olc::vd2d SpriteTextureMask;
olc::vf2d SpriteTextureMask;
olc::Sprite* SpriteMap;
virtual void Update(float fTime);

File diff suppressed because it is too large Load Diff

View File

@@ -3,21 +3,31 @@
#define OLC_PGE_APPLICATION
#include "olcPixelGameEngine.hpp"
#include "Dungeon.hpp"
class Game : public olc::PixelGameEngine
{
public:
private:
Logger& _Logger;
Dungeon* _Dungeon;
olc::Sprite* _TileSet;
public:
Game()
: _Logger(Logger::getInstance())
{
sAppName = "Ben Kyd and The Great Machine";
sAppName = "The Great Machine";
}
bool OnUserCreate() override
{
_Dungeon = new Dungeon();
_Dungeon->Generate();
_TileSet = new olc::Sprite("./res/dungeon_tileset.png");
return true;
}
@@ -28,7 +38,6 @@ public:
m_DeltaFade -= fTime * 200.0f;
if (m_DeltaFade < 0.1f) m_DeltaFade = 0.0f;
}
SetPixelMode(olc::Pixel::ALPHA);
DrawString((ScreenWidth() / 2) - (7 * 7) * (std::string("The Great Machine").length() / 2), ScreenHeight() / 2, "The Great Machine", olc::Pixel(255, 255, 255, static_cast<int>(m_DeltaFade)), 6);
DrawString(5, ScreenHeight() - 15, "Powered by the OLC Pixel Game Engine", olc::Pixel(255, 255, 255, static_cast<int>(m_DeltaFade)));
DrawString(ScreenWidth() - (8 * (std::string("Copyright Benjamin Kyd 2020").length())) - 5, ScreenHeight() - 15, "Copyright Benjamin Kyd 2020", olc::Pixel(255, 255, 255, static_cast<int>(m_DeltaFade)));
@@ -36,20 +45,24 @@ public:
bool OnUserUpdate(float fTime) override
{
SetPixelMode(olc::Pixel::ALPHA);
m_TimeAccumilator += fTime;
Clear(olc::BLACK);
Clear({ 38, 36, 40 });
_Logger.Debug(m_TimeAccumilator);
if (m_TimeAccumilator < 4.0f)
{
DisplayTitle(fTime);
return true;
}
//_Logger.Debug(m_TimeAccumilator);
//if (m_TimeAccumilator < 4.0f)
//{
// DisplayTitle(fTime);
// return true;
//}
// _Dungeon->Input(this);
// _Dungeon->Draw(this);
DrawSprite({ 0, 0 }, _TileSet);
return true;
}
@@ -69,7 +82,7 @@ int main()
_Logger.InitializeLoggingThread();
Game _Game;
_Game.Construct(1280, 720, 1, 1);
_Game.Construct(1280, 720, 1, 1, false, true);
_Logger.Info("Game Constructed");
if (!_Game.Start())

View File

@@ -460,8 +460,35 @@ namespace olc
typedef v2d_generic<float> vf2d;
typedef v2d_generic<double> vd2d;
#endif
}
namespace std
{
template <>
struct hash<olc::vi2d>
{
std::size_t operator()(const olc::vi2d& k) const
{
uint64_t h1 = k.x << 31;
uint64_t h2 = k.y << 31;
return h1 ^ h2;
}
};
template <>
struct hash<olc::vf2d>
{
std::size_t operator()(const olc::vf2d& k) const
{
uint64_t h1 = static_cast<int>(k.x) << 31;
uint64_t h2 = static_cast<int>(k.y) << 31;
return h1 ^ h2;
}
};
}
namespace olc {
// O------------------------------------------------------------------------------O
// | olc::HWButton - Represents the state of a hardware button (mouse/key/joy) |