Rendering things ! Time for some generation
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include "Things.hpp"
|
#include "Things.hpp"
|
||||||
#include "Camera.hpp"
|
#include "Camera.hpp"
|
||||||
|
#include "Logger.hpp"
|
||||||
|
|
||||||
Dungeon::Dungeon()
|
Dungeon::Dungeon()
|
||||||
{
|
{
|
||||||
@@ -12,7 +13,33 @@ Dungeon::Dungeon()
|
|||||||
|
|
||||||
void Dungeon::Generate()
|
void Dungeon::Generate()
|
||||||
{
|
{
|
||||||
TileSet = new olc::Sprite("./res/dungeon_tileset.png");
|
TileSetDictionary = new TileDictionary();
|
||||||
|
TileSetDictionary->Register();
|
||||||
|
TileSet = new olc::Sprite("res/dungeon_tileset.png");
|
||||||
|
Logger::getInstance().Debug("Texture Loaded: ", TileSet, " ", TileSet->width, " ", TileSet->height);
|
||||||
|
|
||||||
|
auto index = [](int x, int y, int depth) -> int { return x + depth * y; };
|
||||||
|
|
||||||
|
// Generate a dungeon
|
||||||
|
// Loosely follows the algorithm in section 3.3 "Agent Based Growing"
|
||||||
|
// http://pcgbook.com/wp-content/uploads/chapter03.pdf
|
||||||
|
|
||||||
|
struct Room
|
||||||
|
{
|
||||||
|
int x, y, w, h;
|
||||||
|
};
|
||||||
|
|
||||||
|
auto randomRoom = [](int x, int y)
|
||||||
|
{ return new Room{ x, y, (rand() % 15) + 5, (rand() % 15) + 5 }; };
|
||||||
|
|
||||||
|
std::vector<Room*> rooms;
|
||||||
|
std::map<olc::vi2d, bool> tiles;
|
||||||
|
|
||||||
|
// Starting at 0,0
|
||||||
|
|
||||||
|
olc::vi2d agentPos;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,16 +55,12 @@ void Dungeon::Input(olc::PixelGameEngine* engine)
|
|||||||
|
|
||||||
void Dungeon::Update(float fTime)
|
void Dungeon::Update(float fTime)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Dungeon::Draw(olc::PixelGameEngine* engine)
|
void Dungeon::Draw(olc::PixelGameEngine* engine)
|
||||||
{
|
{
|
||||||
int ActiveTile = MapVector[y * MAPWIDTH + x];
|
|
||||||
|
|
||||||
// sky
|
|
||||||
if (ActiveTile == -1) continue;
|
|
||||||
|
|
||||||
// find tile in map
|
// find tile in map
|
||||||
auto DrawFrom = [&](int tile) {
|
auto DrawFrom = [&](int tile) {
|
||||||
// mod w for x int div y - JavidX9
|
// mod w for x int div y - JavidX9
|
||||||
@@ -45,13 +68,23 @@ void Dungeon::Draw(olc::PixelGameEngine* engine)
|
|||||||
int h = tile / (TileSet->width / 16);
|
int h = tile / (TileSet->width / 16);
|
||||||
return olc::vi2d(w * 16, h * 16);
|
return olc::vi2d(w * 16, h * 16);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
auto index = [](int x, int y, int depth) -> int { return x + depth * y; };
|
||||||
|
|
||||||
//engine->DrawPartialSprite(
|
for (int x = 0; x < DungeonWidth; x++)
|
||||||
// { static_cast<int>(Coords.x + camera->Coords.x), static_cast<int>(Coords.y + camera->Coords.y) },
|
for (int y = 0; y < DungeonHeight; y++)
|
||||||
// SpriteMap, SpriteTextureMask, { 16, 16 });
|
{
|
||||||
|
static Logger& _Logger = Logger::getInstance();
|
||||||
|
// _Logger.Debug(x, " ", y);
|
||||||
|
Tile* tile = DungeonTiles[index(x, y, DungeonWidth)];
|
||||||
|
|
||||||
|
engine->DrawPartialSprite({ x * 32, y * 32 }, TileSet,
|
||||||
|
TileSetDictionary->Dictionary[tile->Type], { 16, 16 }, 2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Dungeon::~Dungeon()
|
Dungeon::~Dungeon()
|
||||||
{
|
{
|
||||||
|
for (int i = 0; i < DungeonTiles.size(); i++)
|
||||||
|
delete DungeonTiles[i];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ class Tile;
|
|||||||
class Entity;
|
class Entity;
|
||||||
class Playable;
|
class Playable;
|
||||||
class FixedItem;
|
class FixedItem;
|
||||||
|
class TileDictionary;
|
||||||
|
|
||||||
// Single level dungeon, no need for fancy levels
|
// Single level dungeon, no need for fancy levels
|
||||||
class Dungeon
|
class Dungeon
|
||||||
@@ -28,10 +29,13 @@ public:
|
|||||||
Playable* Player;
|
Playable* Player;
|
||||||
Camera* ActiveCamera;
|
Camera* ActiveCamera;
|
||||||
|
|
||||||
|
int DungeonWidth;
|
||||||
|
int DungeonHeight;
|
||||||
std::vector<Tile*> DungeonTiles;
|
std::vector<Tile*> DungeonTiles;
|
||||||
std::unordered_map<olc::vf2d, Entity*> Entities; // key here could be room?
|
std::unordered_map<olc::vf2d, Entity*> Entities; // key here could be room?
|
||||||
std::unordered_map<olc::vf2d, FixedItem*> FixedItems;
|
std::unordered_map<olc::vf2d, FixedItem*> FixedItems;
|
||||||
|
|
||||||
|
TileDictionary* TileSetDictionary;
|
||||||
olc::Sprite* TileSet;
|
olc::Sprite* TileSet;
|
||||||
|
|
||||||
~Dungeon();
|
~Dungeon();
|
||||||
|
|||||||
@@ -6,3 +6,38 @@ void Tile::Update(float fTime)
|
|||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TileDictionary::Register()
|
||||||
|
{
|
||||||
|
Dictionary[ETile::Type::Floor] = { 27, 37 };
|
||||||
|
Dictionary[ETile::Type::FloorV1] = { 44, 16 };
|
||||||
|
Dictionary[ETile::Type::WallL] = { 0, 16 };
|
||||||
|
Dictionary[ETile::Type::WallR] = { 64, 16 };
|
||||||
|
Dictionary[ETile::Type::WallU] = { 16, 0 };
|
||||||
|
Dictionary[ETile::Type::WallD] = { 16, 64 };
|
||||||
|
Dictionary[ETile::Type::WallTRCorner] = { 64, 0 };
|
||||||
|
Dictionary[ETile::Type::WallTLCorner] = { 0, 0 };
|
||||||
|
Dictionary[ETile::Type::WallBRCorner] = { 64, 64 };
|
||||||
|
Dictionary[ETile::Type::WallBLCorner] = { 0, 64 };
|
||||||
|
Dictionary[ETile::Type::PathUp] = { 84, 16 };
|
||||||
|
Dictionary[ETile::Type::PathAcross] = { 100, 0 };
|
||||||
|
Dictionary[ETile::Type::PathTop] = { 84, 64 };
|
||||||
|
Dictionary[ETile::Type::PathBottom] = { 84, 80 };
|
||||||
|
Dictionary[ETile::Type::PathLeft] = { 0, 96 };
|
||||||
|
Dictionary[ETile::Type::PathRight] = { 16, 96 };
|
||||||
|
Dictionary[ETile::Type::PathTRCorner] = { 88, 128 };
|
||||||
|
Dictionary[ETile::Type::PathTLCorner] = { 56, 128 };
|
||||||
|
Dictionary[ETile::Type::PathBRCorner] = { 88, 176 };
|
||||||
|
Dictionary[ETile::Type::PathBLCorner] = { 56, 176 };
|
||||||
|
Dictionary[ETile::Type::OneByOne] = { 36, 96 };
|
||||||
|
Dictionary[ETile::Type::DoorOpen] = { 108, 180 };
|
||||||
|
Dictionary[ETile::Type::DoorClosed] = { 124, 180 };
|
||||||
|
Dictionary[ETile::Type::DoorPortcullis] = { 208, 108 };
|
||||||
|
Dictionary[ETile::Type::DoorOpenTop] = { 208, 108 };
|
||||||
|
Dictionary[ETile::Type::DoorClosedTop] = { 224, 108 };
|
||||||
|
Dictionary[ETile::Type::DoorPortcullisTop] = { 240, 108 };
|
||||||
|
Dictionary[ETile::Type::ThreeDStandard] = { 0, 80 };
|
||||||
|
Dictionary[ETile::Type::ThreeDSolid] = { 0, 160 };
|
||||||
|
Dictionary[ETile::Type::ThreeDSpike] = { 0, 260 };
|
||||||
|
Dictionary[ETile::Type::ThreeDSpikeBottom] = { 0, 276 };
|
||||||
|
}
|
||||||
|
|||||||
@@ -8,13 +8,52 @@
|
|||||||
|
|
||||||
class Camera;
|
class Camera;
|
||||||
|
|
||||||
|
namespace ETexture
|
||||||
|
{
|
||||||
|
enum Type
|
||||||
|
{
|
||||||
|
EightByEight,
|
||||||
|
SixteenBySixteen
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
namespace ETile
|
namespace ETile
|
||||||
{
|
{
|
||||||
enum Type
|
enum Type
|
||||||
{
|
{
|
||||||
Backdrop,
|
None,
|
||||||
Floor,
|
Floor,
|
||||||
Wall
|
FloorV1,
|
||||||
|
WallL,
|
||||||
|
WallR,
|
||||||
|
WallU,
|
||||||
|
WallD,
|
||||||
|
WallTRCorner,
|
||||||
|
WallTLCorner,
|
||||||
|
WallBRCorner,
|
||||||
|
WallBLCorner,
|
||||||
|
PathUp,
|
||||||
|
PathAcross,
|
||||||
|
PathTop,
|
||||||
|
PathBottom,
|
||||||
|
PathLeft,
|
||||||
|
PathRight,
|
||||||
|
PathTRCorner,
|
||||||
|
PathTLCorner,
|
||||||
|
PathBRCorner,
|
||||||
|
PathBLCorner,
|
||||||
|
OneByOne,
|
||||||
|
DoorOpen,
|
||||||
|
DoorClosed,
|
||||||
|
DoorPortcullis,
|
||||||
|
DoorOpenTop,
|
||||||
|
DoorClosedTop,
|
||||||
|
DoorPortcullisTop,
|
||||||
|
|
||||||
|
ThreeDStandard,
|
||||||
|
ThreeDSolid,
|
||||||
|
ThreeDSpike,
|
||||||
|
ThreeDSpikeBottom
|
||||||
};
|
};
|
||||||
|
|
||||||
enum State
|
enum State
|
||||||
@@ -83,18 +122,26 @@ public:
|
|||||||
|
|
||||||
class TileDictionary
|
class TileDictionary
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
void Register();
|
||||||
|
std::map<ETile::Type, olc::vi2d> Dictionary;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Tile
|
class Tile
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
Tile(olc::vi2d coords, ETile::Type type, ETile::State state)
|
||||||
|
: Coords(coords)
|
||||||
|
, Type(type)
|
||||||
|
, State(state)
|
||||||
|
{ }
|
||||||
|
|
||||||
olc::vi2d Coords;
|
olc::vi2d Coords;
|
||||||
ETile::Type Type;
|
ETile::Type Type;
|
||||||
ETile::State State;
|
ETile::State State;
|
||||||
|
|
||||||
olc::vf2d SpriteTextureMask;
|
//olc::vf2d SpriteTextureMask;
|
||||||
olc::Sprite* SpriteMap;
|
//olc::Sprite* SpriteMap;
|
||||||
|
|
||||||
virtual void Update(float fTime);
|
virtual void Update(float fTime);
|
||||||
};
|
};
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -46,20 +46,18 @@ public:
|
|||||||
|
|
||||||
Clear({ 38, 36, 40 });
|
Clear({ 38, 36, 40 });
|
||||||
|
|
||||||
_Logger.Debug(m_TimeAccumilator);
|
// _Logger.Debug(m_TimeAccumilator);
|
||||||
|
|
||||||
if (m_TimeAccumilator < 4.0f)
|
//if (m_TimeAccumilator < 4.0f)
|
||||||
{
|
//{
|
||||||
DisplayTitle(fTime);
|
// DisplayTitle(fTime);
|
||||||
return true;
|
// return true;
|
||||||
}
|
//}
|
||||||
|
|
||||||
_Dungeon->Input(this);
|
_Dungeon->Input(this);
|
||||||
|
|
||||||
_Dungeon->Draw(this);
|
_Dungeon->Draw(this);
|
||||||
|
|
||||||
DrawSprite({ 0, 0 }, _TileSet);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 17 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 17 KiB |
Reference in New Issue
Block a user