Rendering things ! Time for some generation
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "Things.hpp"
|
||||
#include "Camera.hpp"
|
||||
#include "Logger.hpp"
|
||||
|
||||
Dungeon::Dungeon()
|
||||
{
|
||||
@@ -12,7 +13,33 @@ Dungeon::Dungeon()
|
||||
|
||||
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::Draw(olc::PixelGameEngine* engine)
|
||||
{
|
||||
int ActiveTile = MapVector[y * MAPWIDTH + x];
|
||||
|
||||
// sky
|
||||
if (ActiveTile == -1) continue;
|
||||
|
||||
|
||||
// find tile in map
|
||||
auto DrawFrom = [&](int tile) {
|
||||
// mod w for x int div y - JavidX9
|
||||
@@ -45,13 +68,23 @@ void Dungeon::Draw(olc::PixelGameEngine* engine)
|
||||
int h = tile / (TileSet->width / 16);
|
||||
return olc::vi2d(w * 16, h * 16);
|
||||
};
|
||||
|
||||
auto index = [](int x, int y, int depth) -> int { return x + depth * y; };
|
||||
|
||||
//engine->DrawPartialSprite(
|
||||
// { static_cast<int>(Coords.x + camera->Coords.x), static_cast<int>(Coords.y + camera->Coords.y) },
|
||||
// SpriteMap, SpriteTextureMask, { 16, 16 });
|
||||
for (int x = 0; x < DungeonWidth; x++)
|
||||
for (int y = 0; y < DungeonHeight; y++)
|
||||
{
|
||||
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()
|
||||
{
|
||||
|
||||
for (int i = 0; i < DungeonTiles.size(); i++)
|
||||
delete DungeonTiles[i];
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ class Tile;
|
||||
class Entity;
|
||||
class Playable;
|
||||
class FixedItem;
|
||||
class TileDictionary;
|
||||
|
||||
// Single level dungeon, no need for fancy levels
|
||||
class Dungeon
|
||||
@@ -28,10 +29,13 @@ public:
|
||||
Playable* Player;
|
||||
Camera* ActiveCamera;
|
||||
|
||||
int DungeonWidth;
|
||||
int DungeonHeight;
|
||||
std::vector<Tile*> DungeonTiles;
|
||||
std::unordered_map<olc::vf2d, Entity*> Entities; // key here could be room?
|
||||
std::unordered_map<olc::vf2d, FixedItem*> FixedItems;
|
||||
|
||||
TileDictionary* TileSetDictionary;
|
||||
olc::Sprite* TileSet;
|
||||
|
||||
~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;
|
||||
|
||||
namespace ETexture
|
||||
{
|
||||
enum Type
|
||||
{
|
||||
EightByEight,
|
||||
SixteenBySixteen
|
||||
};
|
||||
}
|
||||
|
||||
namespace ETile
|
||||
{
|
||||
enum Type
|
||||
{
|
||||
Backdrop,
|
||||
None,
|
||||
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
|
||||
@@ -83,18 +122,26 @@ public:
|
||||
|
||||
class TileDictionary
|
||||
{
|
||||
|
||||
public:
|
||||
void Register();
|
||||
std::map<ETile::Type, olc::vi2d> Dictionary;
|
||||
};
|
||||
|
||||
class Tile
|
||||
{
|
||||
public:
|
||||
Tile(olc::vi2d coords, ETile::Type type, ETile::State state)
|
||||
: Coords(coords)
|
||||
, Type(type)
|
||||
, State(state)
|
||||
{ }
|
||||
|
||||
olc::vi2d Coords;
|
||||
ETile::Type Type;
|
||||
ETile::State State;
|
||||
|
||||
olc::vf2d SpriteTextureMask;
|
||||
olc::Sprite* SpriteMap;
|
||||
//olc::vf2d SpriteTextureMask;
|
||||
//olc::Sprite* SpriteMap;
|
||||
|
||||
virtual void Update(float fTime);
|
||||
};
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -46,20 +46,18 @@ public:
|
||||
|
||||
Clear({ 38, 36, 40 });
|
||||
|
||||
_Logger.Debug(m_TimeAccumilator);
|
||||
// _Logger.Debug(m_TimeAccumilator);
|
||||
|
||||
if (m_TimeAccumilator < 4.0f)
|
||||
{
|
||||
DisplayTitle(fTime);
|
||||
return true;
|
||||
}
|
||||
//if (m_TimeAccumilator < 4.0f)
|
||||
//{
|
||||
// DisplayTitle(fTime);
|
||||
// return true;
|
||||
//}
|
||||
|
||||
_Dungeon->Input(this);
|
||||
|
||||
_Dungeon->Draw(this);
|
||||
|
||||
DrawSprite({ 0, 0 }, _TileSet);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 17 KiB |
Reference in New Issue
Block a user