ALOT, titlescreen, sound, enemies
This commit is contained in:
Binary file not shown.
1
TODO
1
TODO
@@ -10,6 +10,7 @@
|
|||||||
[d] Fix collision
|
[d] Fix collision
|
||||||
[x] Better player spritesheet
|
[x] Better player spritesheet
|
||||||
[x] Animation system
|
[x] Animation system
|
||||||
|
[x] Sound
|
||||||
[ ] Enemies / AI
|
[ ] Enemies / AI
|
||||||
[ ] Dungeon fixed entity spawning
|
[ ] Dungeon fixed entity spawning
|
||||||
[ ] Enemy AI
|
[ ] Enemy AI
|
||||||
|
|||||||
Binary file not shown.
@@ -15,7 +15,7 @@ bool EntityCollide(Entity* entity, std::vector<Tile*>& nearby, int tileSize, Col
|
|||||||
|
|
||||||
static Logger& _Logger = Logger::getInstance();
|
static Logger& _Logger = Logger::getInstance();
|
||||||
|
|
||||||
engine->SetDrawTarget(uint8_t(0));
|
engine->SetDrawTarget(1);
|
||||||
engine->Clear(olc::BLANK);
|
engine->Clear(olc::BLANK);
|
||||||
|
|
||||||
float entityX = static_cast<float>(entity->Coords.x - entity->TrackingCamera->Coords.x);
|
float entityX = static_cast<float>(entity->Coords.x - entity->TrackingCamera->Coords.x);
|
||||||
@@ -28,12 +28,12 @@ bool EntityCollide(Entity* entity, std::vector<Tile*>& nearby, int tileSize, Col
|
|||||||
int entityTop = static_cast<int>(entityY);
|
int entityTop = static_cast<int>(entityY);
|
||||||
int entityBottom = static_cast<int>(entityY + entityH);
|
int entityBottom = static_cast<int>(entityY + entityH);
|
||||||
|
|
||||||
if (ShowDebug)
|
if (ShowCollisionDebug)
|
||||||
engine->DrawRect(entityX, entityY, entityW, entityH, olc::RED);
|
engine->DrawRect(entityX, entityY, entityW, entityH, olc::RED);
|
||||||
|
|
||||||
for (auto tile : nearby)
|
for (auto tile : nearby)
|
||||||
{
|
{
|
||||||
if (ShowDebug)
|
if (ShowCollisionDebug)
|
||||||
engine->DrawRect({ static_cast<int>(static_cast<float>((tile->Coords.x * tileSize) - entity->TrackingCamera->Coords.x)), static_cast<int>(static_cast<float>((tile->Coords.y * tileSize) - entity->TrackingCamera->Coords.y)) }, {tileSize, tileSize}, olc::BLUE);
|
engine->DrawRect({ static_cast<int>(static_cast<float>((tile->Coords.x * tileSize) - entity->TrackingCamera->Coords.x)), static_cast<int>(static_cast<float>((tile->Coords.y * tileSize) - entity->TrackingCamera->Coords.y)) }, {tileSize, tileSize}, olc::BLUE);
|
||||||
|
|
||||||
// return if not collidable
|
// return if not collidable
|
||||||
@@ -51,7 +51,7 @@ bool EntityCollide(Entity* entity, std::vector<Tile*>& nearby, int tileSize, Col
|
|||||||
|
|
||||||
bool collision = xOverlaps && yOverlaps;
|
bool collision = xOverlaps && yOverlaps;
|
||||||
|
|
||||||
if (ShowDebug)
|
if (ShowCollisionDebug)
|
||||||
engine->FillRect({static_cast<int>(static_cast<float>((tile->Coords.x * tileSize) - entity->TrackingCamera->Coords.x)), static_cast<int>(static_cast<float>((tile->Coords.y * tileSize) - entity->TrackingCamera->Coords.y))}, {tileSize, tileSize}, collision ? olc::RED : olc::BLUE);
|
engine->FillRect({static_cast<int>(static_cast<float>((tile->Coords.x * tileSize) - entity->TrackingCamera->Coords.x)), static_cast<int>(static_cast<float>((tile->Coords.y * tileSize) - entity->TrackingCamera->Coords.y))}, {tileSize, tileSize}, collision ? olc::RED : olc::BLUE);
|
||||||
|
|
||||||
if (!collision) continue;
|
if (!collision) continue;
|
||||||
|
|||||||
@@ -14,7 +14,6 @@
|
|||||||
|
|
||||||
void PerlinNoise1D(int nCount, float *fSeed, int nOctaves, float fBias, float *fOutput)
|
void PerlinNoise1D(int nCount, float *fSeed, int nOctaves, float fBias, float *fOutput)
|
||||||
{
|
{
|
||||||
// Used 1D Perlin Noise
|
|
||||||
for (int x = 0; x < nCount; x++)
|
for (int x = 0; x < nCount; x++)
|
||||||
{
|
{
|
||||||
float fNoise = 0.0f;
|
float fNoise = 0.0f;
|
||||||
@@ -80,7 +79,21 @@ Dungeon::Dungeon()
|
|||||||
Player->Type = EEntity::Type::Player;
|
Player->Type = EEntity::Type::Player;
|
||||||
// Relative to player TL corner
|
// Relative to player TL corner
|
||||||
// not really used ? lol
|
// not really used ? lol
|
||||||
Player->HitBox = new Collider{ 0, 0, 28, 36 } ;
|
Player->HitBox = new Collider{ 0, 0, 28, 36 };
|
||||||
|
|
||||||
|
EnemyRenderable = new olc::Renderable();
|
||||||
|
EnemyRenderable->Load("res/player.png");
|
||||||
|
EnemyAnimator = new olc::AnimatedSprite();
|
||||||
|
EnemyAnimator->mode = olc::AnimatedSprite::SPRITE_MODE::SINGLE;
|
||||||
|
EnemyAnimator->type = olc::AnimatedSprite::SPRITE_TYPE::DECAL;
|
||||||
|
EnemyAnimator->spriteSheet = EnemyRenderable;
|
||||||
|
EnemyAnimator->SetSpriteSize({28, 36});
|
||||||
|
|
||||||
|
EnemyAnimator->AddState("idle", 0.127f, olc::AnimatedSprite::PLAY_MODE::LOOP, std::vector<olc::vi2d>{
|
||||||
|
{28, 0}
|
||||||
|
});
|
||||||
|
EnemyAnimator->SetState("idle");
|
||||||
|
|
||||||
|
|
||||||
Player->Renderable = new olc::Renderable();
|
Player->Renderable = new olc::Renderable();
|
||||||
Player->Renderable->Load("res/player.png");
|
Player->Renderable->Load("res/player.png");
|
||||||
@@ -90,29 +103,29 @@ Dungeon::Dungeon()
|
|||||||
Player->Animator->spriteSheet = Player->Renderable;
|
Player->Animator->spriteSheet = Player->Renderable;
|
||||||
Player->Animator->SetSpriteSize({28, 36});
|
Player->Animator->SetSpriteSize({28, 36});
|
||||||
|
|
||||||
Player->Animator->AddState("idle", std::vector<olc::vi2d>{
|
Player->Animator->AddState("idle", 0.127f, olc::AnimatedSprite::PLAY_MODE::LOOP, std::vector<olc::vi2d>{
|
||||||
{28, 0}
|
{28, 0}
|
||||||
});
|
});
|
||||||
|
|
||||||
Player->Animator->AddState("north", std::vector<olc::vi2d>{
|
Player->Animator->AddState("north", 0.127f, olc::AnimatedSprite::PLAY_MODE::LOOP, std::vector<olc::vi2d>{
|
||||||
{0, 110},
|
{0, 110},
|
||||||
{28, 110},
|
{28, 110},
|
||||||
{56, 110},
|
{56, 110},
|
||||||
{84, 110}
|
{84, 110}
|
||||||
});
|
});
|
||||||
Player->Animator->AddState("east", std::vector<olc::vi2d>{
|
Player->Animator->AddState("east", 0.127f, olc::AnimatedSprite::PLAY_MODE::LOOP, std::vector<olc::vi2d>{
|
||||||
{0, 36},
|
{0, 36},
|
||||||
{28, 36},
|
{28, 36},
|
||||||
{56, 36},
|
{56, 36},
|
||||||
{84, 36}
|
{84, 36}
|
||||||
});
|
});
|
||||||
Player->Animator->AddState("south", std::vector<olc::vi2d>{
|
Player->Animator->AddState("south", 0.127f, olc::AnimatedSprite::PLAY_MODE::LOOP, std::vector<olc::vi2d>{
|
||||||
{0, 0},
|
{0, 0},
|
||||||
{28, 0},
|
{28, 0},
|
||||||
{56, 0},
|
{56, 0},
|
||||||
{84, 0}
|
{84, 0}
|
||||||
});
|
});
|
||||||
Player->Animator->AddState("west", std::vector<olc::vi2d>{
|
Player->Animator->AddState("west", 0.127f, olc::AnimatedSprite::PLAY_MODE::LOOP, std::vector<olc::vi2d>{
|
||||||
{0, 72},
|
{0, 72},
|
||||||
{28, 72},
|
{28, 72},
|
||||||
{56, 72},
|
{56, 72},
|
||||||
@@ -133,6 +146,27 @@ Dungeon::Dungeon()
|
|||||||
FireOverlay = new olc::Renderable();
|
FireOverlay = new olc::Renderable();
|
||||||
FireOverlay->Load("res/torch.png");
|
FireOverlay->Load("res/torch.png");
|
||||||
|
|
||||||
|
SoundBufferFireLighting.loadFromFile("res/fire_start.wav");
|
||||||
|
SoundFireLighting.setBuffer(SoundBufferFireLighting);
|
||||||
|
SoundFireLighting.setLoop(false);
|
||||||
|
SoundFireLighting.setVolume(50.f);
|
||||||
|
|
||||||
|
SoundBufferFire.loadFromFile("res/fire.wav");
|
||||||
|
SoundFire.setBuffer(SoundBufferFire);
|
||||||
|
SoundFire.setLoop(true);
|
||||||
|
SoundFire.setVolume(100.f);
|
||||||
|
|
||||||
|
SoundBufferAmbient.loadFromFile("res/ambient.ogg");
|
||||||
|
SoundAmbient.setBuffer(SoundBufferAmbient);
|
||||||
|
SoundAmbient.setLoop(true);
|
||||||
|
SoundAmbient.play();
|
||||||
|
|
||||||
|
SoundBufferFootsteps.loadFromFile("res/run.ogg");
|
||||||
|
SoundFootsteps.setBuffer(SoundBufferFootsteps);
|
||||||
|
SoundFootsteps.setLoop(true);
|
||||||
|
SoundFootsteps.setVolume(20.f);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Dungeon::Generate()
|
void Dungeon::Generate()
|
||||||
@@ -283,11 +317,6 @@ void Dungeon::Generate()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Dungeon::SpawnEntity(Entity* entity)
|
|
||||||
{
|
|
||||||
Entities[entity->Coords] = entity;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Dungeon::Input(olc::PixelGameEngine* engine, float fTime)
|
void Dungeon::Input(olc::PixelGameEngine* engine, float fTime)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -295,30 +324,36 @@ void Dungeon::Input(olc::PixelGameEngine* engine, float fTime)
|
|||||||
|
|
||||||
static std::string state = "idle";
|
static std::string state = "idle";
|
||||||
static std::string lastState = "idle";
|
static std::string lastState = "idle";
|
||||||
|
static bool WasMoving = false;
|
||||||
|
bool IsMoving = false;
|
||||||
|
|
||||||
if (engine->GetKey(olc::W).bHeld)
|
if (engine->GetKey(olc::W).bHeld)
|
||||||
{
|
{
|
||||||
Player->Coords.y -= static_cast<float>(TileSize) * (fTime * Player->Speed);
|
Player->Coords.y -= static_cast<float>(TileSize) * (fTime * Player->Speed);
|
||||||
if (state != "north")
|
if (state != "north")
|
||||||
state = "north";
|
state = "north";
|
||||||
|
IsMoving = true;
|
||||||
}
|
}
|
||||||
if (engine->GetKey(olc::A).bHeld)
|
if (engine->GetKey(olc::A).bHeld)
|
||||||
{
|
{
|
||||||
Player->Coords.x -= static_cast<float>(TileSize) * (fTime * Player->Speed);
|
Player->Coords.x -= static_cast<float>(TileSize) * (fTime * Player->Speed);
|
||||||
if (state != "west")
|
if (state != "west")
|
||||||
state = "west";
|
state = "west";
|
||||||
|
IsMoving = true;
|
||||||
}
|
}
|
||||||
if (engine->GetKey(olc::S).bHeld)
|
if (engine->GetKey(olc::S).bHeld)
|
||||||
{
|
{
|
||||||
Player->Coords.y += static_cast<float>(TileSize) * (fTime * Player->Speed);
|
Player->Coords.y += static_cast<float>(TileSize) * (fTime * Player->Speed);
|
||||||
if (state != "south")
|
if (state != "south")
|
||||||
state = "south";
|
state = "south";
|
||||||
|
IsMoving = true;
|
||||||
}
|
}
|
||||||
if (engine->GetKey(olc::D).bHeld)
|
if (engine->GetKey(olc::D).bHeld)
|
||||||
{
|
{
|
||||||
Player->Coords.x += static_cast<float>(TileSize) * (fTime * Player->Speed);
|
Player->Coords.x += static_cast<float>(TileSize) * (fTime * Player->Speed);
|
||||||
if (state != "east")
|
if (state != "east")
|
||||||
state = "east";
|
state = "east";
|
||||||
|
IsMoving = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (engine->GetKey(olc::W).bHeld && engine->GetKey(olc::A).bHeld)
|
if (engine->GetKey(olc::W).bHeld && engine->GetKey(olc::A).bHeld)
|
||||||
@@ -327,7 +362,6 @@ void Dungeon::Input(olc::PixelGameEngine* engine, float fTime)
|
|||||||
Player->Coords.x += static_cast<float>(TileSize) * (fTime * (Player->Speed / 3.0f));
|
Player->Coords.x += static_cast<float>(TileSize) * (fTime * (Player->Speed / 3.0f));
|
||||||
if (state != "west")
|
if (state != "west")
|
||||||
state = "west";
|
state = "west";
|
||||||
|
|
||||||
}
|
}
|
||||||
if (engine->GetKey(olc::W).bHeld && engine->GetKey(olc::D).bHeld)
|
if (engine->GetKey(olc::W).bHeld && engine->GetKey(olc::D).bHeld)
|
||||||
{
|
{
|
||||||
@@ -352,8 +386,22 @@ void Dungeon::Input(olc::PixelGameEngine* engine, float fTime)
|
|||||||
state = "west";
|
state = "west";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!WasMoving && IsMoving)
|
||||||
|
{
|
||||||
|
SoundFootsteps.setPlayingOffset(sf::seconds(0.05f));
|
||||||
|
SoundFootsteps.play();
|
||||||
|
}
|
||||||
|
if (WasMoving && !IsMoving)
|
||||||
|
{
|
||||||
|
SoundFootsteps.stop();
|
||||||
|
}
|
||||||
|
WasMoving = IsMoving;
|
||||||
|
|
||||||
if (oldCoords == Player->Coords)
|
if (oldCoords == Player->Coords)
|
||||||
|
{
|
||||||
state = "idle";
|
state = "idle";
|
||||||
|
SoundFootsteps.pause();
|
||||||
|
}
|
||||||
if (state != lastState)
|
if (state != lastState)
|
||||||
Player->Animator->SetState(state);
|
Player->Animator->SetState(state);
|
||||||
lastState = state;
|
lastState = state;
|
||||||
@@ -427,6 +475,31 @@ void Dungeon::Input(olc::PixelGameEngine* engine, float fTime)
|
|||||||
void Dungeon::Update(olc::PixelGameEngine* engine, float fTime)
|
void Dungeon::Update(olc::PixelGameEngine* engine, float fTime)
|
||||||
{
|
{
|
||||||
ActiveCamera->Update(fTime);
|
ActiveCamera->Update(fTime);
|
||||||
|
|
||||||
|
if (!HasBegun) return;
|
||||||
|
|
||||||
|
// spawn enemies
|
||||||
|
if (Enemies.size() == 0)// rand() % 1000 < 1)
|
||||||
|
{
|
||||||
|
Enemy* enemy = new Enemy();
|
||||||
|
enemy->Type = EEntity::Type::Enemy;
|
||||||
|
enemy->Renderable = EnemyRenderable;
|
||||||
|
enemy->Animator = EnemyAnimator;
|
||||||
|
enemy->Coords = { Player->Coords.x + static_cast<float>((rand() % 100) - 50 ), Player->Coords.y + static_cast<float>((rand() % 100) - 50) };
|
||||||
|
|
||||||
|
enemy->HitBox = new Collider{ 0, 0, 28, 36 };
|
||||||
|
|
||||||
|
Enemies.push_back(enemy);
|
||||||
|
}
|
||||||
|
|
||||||
|
olc::vf2d desiredLocation = Player->Coords;
|
||||||
|
for (auto enemy : Enemies)
|
||||||
|
{
|
||||||
|
enemy->Velocity = static_cast<float>(TileSize) * (fTime * (Player->Speed / 3.0f) * olc::vf2d(desiredLocation - enemy->Coords).norm());
|
||||||
|
|
||||||
|
enemy->Coords += enemy->Velocity;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
olc::Pixel pixelMultiply(const int x, const int y, const olc::Pixel& pSource, const olc::Pixel& pDest)
|
olc::Pixel pixelMultiply(const int x, const int y, const olc::Pixel& pSource, const olc::Pixel& pDest)
|
||||||
@@ -447,7 +520,7 @@ void Dungeon::Draw(olc::PixelGameEngine* engine, float fTime)
|
|||||||
// Entities are always (tilesize / 3) * 2
|
// Entities are always (tilesize / 3) * 2
|
||||||
|
|
||||||
// Dungeon Layer
|
// Dungeon Layer
|
||||||
engine->SetDrawTarget(3);
|
engine->SetDrawTarget(4);
|
||||||
engine->Clear({38, 36, 40});
|
engine->Clear({38, 36, 40});
|
||||||
|
|
||||||
engine->SetPixelMode(olc::Pixel::ALPHA);
|
engine->SetPixelMode(olc::Pixel::ALPHA);
|
||||||
@@ -456,25 +529,67 @@ void Dungeon::Draw(olc::PixelGameEngine* engine, float fTime)
|
|||||||
engine->DrawPartialDecal({ static_cast<float>((tile.first.x * TileSize) - ActiveCamera->Coords.x), static_cast<float>((tile.first.y * TileSize) - ActiveCamera->Coords.y) },
|
engine->DrawPartialDecal({ static_cast<float>((tile.first.x * TileSize) - ActiveCamera->Coords.x), static_cast<float>((tile.first.y * TileSize) - ActiveCamera->Coords.y) },
|
||||||
{ static_cast<float>(TileSize), static_cast<float>(TileSize) }, TileSet->Decal(), TileSetDictionary->Dictionary[tile.second->Type], { 16, 16 });
|
{ static_cast<float>(TileSize), static_cast<float>(TileSize) }, TileSet->Decal(), TileSetDictionary->Dictionary[tile.second->Type], { 16, 16 });
|
||||||
|
|
||||||
|
|
||||||
// Entity Layer
|
// Entity Layer
|
||||||
engine->SetDrawTarget(2);
|
engine->SetDrawTarget(3);
|
||||||
engine->Clear(olc::BLANK);
|
engine->Clear(olc::BLANK);
|
||||||
|
|
||||||
// Draw character
|
// Draw character
|
||||||
Player->Animator->Draw(fTime, {Player->Coords.x - ActiveCamera->Coords.x, Player->Coords.y - ActiveCamera->Coords.y});
|
Player->Animator->Draw(fTime, {Player->Coords.x - ActiveCamera->Coords.x, Player->Coords.y - ActiveCamera->Coords.y});
|
||||||
|
|
||||||
|
for (int i = 0; i < Enemies.size(); i++)
|
||||||
|
{
|
||||||
|
_Logger.Debug(i);
|
||||||
|
Enemies[i]->Animator->SetState("idle");
|
||||||
|
Enemies[i]->Animator->Draw(fTime, {Enemies[i]->Coords.x - ActiveCamera->Coords.x, Enemies[i]->Coords.y - ActiveCamera->Coords.y});
|
||||||
|
}
|
||||||
|
|
||||||
// Lighting layers
|
// Lighting layers
|
||||||
engine->SetDrawTarget(1);
|
engine->SetDrawTarget(2);
|
||||||
engine->Clear(olc::BLANK);
|
engine->Clear(olc::BLANK);
|
||||||
|
|
||||||
|
static bool WasFireLit = false;
|
||||||
|
static bool HasFireLit = false;
|
||||||
|
static float FireAccumilator = 0.0f;
|
||||||
|
|
||||||
|
if (engine->GetKey(olc::F).bPressed) IsFireLit = true;
|
||||||
|
|
||||||
|
if (!IsLightOn && !HasFireLit)
|
||||||
|
{
|
||||||
|
engine->FillRectDecal({0.0f, 0.0f}, {static_cast<float>(engine->ScreenWidth()), static_cast<float>(engine->ScreenHeight())}, olc::Pixel(0,0,0));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!IsFireLit) return;
|
||||||
|
|
||||||
|
// Wait for fire to get going to render
|
||||||
|
if (WasFireLit != IsFireLit)
|
||||||
|
{
|
||||||
|
SoundFireLighting.setPlayingOffset(sf::seconds(0.3f));
|
||||||
|
SoundFireLighting.play();
|
||||||
|
}
|
||||||
|
WasFireLit = true;
|
||||||
|
static bool LastPlayFire = false;
|
||||||
|
static bool PlayFire = false;
|
||||||
|
FireAccumilator += fTime;
|
||||||
|
if (FireAccumilator > 1.4f)
|
||||||
|
PlayFire = true;
|
||||||
|
if (FireAccumilator < 1.4f)
|
||||||
|
return;
|
||||||
|
if (LastPlayFire != PlayFire)
|
||||||
|
{
|
||||||
|
SoundFire.play();
|
||||||
|
LastPlayFire = true;
|
||||||
|
HasFireLit = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
HasBegun = true;
|
||||||
|
|
||||||
static std::function<olc::Pixel(const int x, const int y, const olc::Pixel& pSource, const olc::Pixel& pDest)> fPixelMultiply = pixelMultiply;
|
static std::function<olc::Pixel(const int x, const int y, const olc::Pixel& pSource, const olc::Pixel& pDest)> fPixelMultiply = pixelMultiply;
|
||||||
|
|
||||||
// loads to make it more chaotic
|
// loads to make it more chaotic
|
||||||
float lightScale = 1.4f + GetNextPerlin(); GetNextPerlin(); GetNextPerlin(); GetNextPerlin(); GetNextPerlin();
|
float lightScale = 1.2f + GetNextPerlin(); GetNextPerlin(); GetNextPerlin(); GetNextPerlin(); GetNextPerlin();
|
||||||
|
|
||||||
float lightX = static_cast<float>(Player->Coords.x - ActiveCamera->Coords.x) - ((FireOverlay->Sprite()->width * lightScale) / 2.0f);
|
float lightX = static_cast<float>(Player->Coords.x - ActiveCamera->Coords.x) - ((FireOverlay->Sprite()->width * lightScale) / 2.0f) + static_cast<float>(Player->HitBox->w) / 2.0f;
|
||||||
float lightY = static_cast<float>(Player->Coords.y - ActiveCamera->Coords.y) - ((FireOverlay->Sprite()->height * lightScale) / 2.0f);
|
float lightY = static_cast<float>(Player->Coords.y - ActiveCamera->Coords.y) - ((FireOverlay->Sprite()->height * lightScale) / 2.0f) + static_cast<float>(Player->HitBox->h) / 2.0f;
|
||||||
|
|
||||||
float lightLeft = lightX + 1.0f;
|
float lightLeft = lightX + 1.0f;
|
||||||
float lightRight = lightX + FireOverlay->Sprite()->width * lightScale - 1.0f;
|
float lightRight = lightX + FireOverlay->Sprite()->width * lightScale - 1.0f;
|
||||||
@@ -511,10 +626,12 @@ Dungeon::~Dungeon()
|
|||||||
delete TileSet;
|
delete TileSet;
|
||||||
for (std::pair<olc::vi2d, Tile*> tile : DungeonTiles)
|
for (std::pair<olc::vi2d, Tile*> tile : DungeonTiles)
|
||||||
delete tile.second;
|
delete tile.second;
|
||||||
for (std::pair<olc::vi2d, Entity*> entity : Entities)
|
|
||||||
delete entity.second;
|
for (auto enemy : Enemies)
|
||||||
for (std::pair<olc::vi2d, FixedItem*> entity : FixedItems)
|
{
|
||||||
delete entity.second;
|
delete enemy->HitBox;
|
||||||
|
delete enemy;
|
||||||
|
}
|
||||||
|
|
||||||
free(perlinSeed);
|
free(perlinSeed);
|
||||||
free(perlinOutput);
|
free(perlinOutput);
|
||||||
|
|||||||
@@ -2,8 +2,11 @@
|
|||||||
#define GREATMACHINE_DUNGEON_H_
|
#define GREATMACHINE_DUNGEON_H_
|
||||||
|
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include <SFML/Audio.hpp>
|
||||||
#include "olcPixelGameEngine.hpp"
|
#include "olcPixelGameEngine.hpp"
|
||||||
|
#include "olcPGEX_AnimatedSprite.hpp"
|
||||||
|
|
||||||
#include "Logger.hpp"
|
#include "Logger.hpp"
|
||||||
|
|
||||||
@@ -11,6 +14,7 @@ class Camera;
|
|||||||
|
|
||||||
class Tile;
|
class Tile;
|
||||||
class Entity;
|
class Entity;
|
||||||
|
class Enemy;
|
||||||
class Playable;
|
class Playable;
|
||||||
class FixedItem;
|
class FixedItem;
|
||||||
class TileDictionary;
|
class TileDictionary;
|
||||||
@@ -22,27 +26,42 @@ class Dungeon
|
|||||||
Dungeon();
|
Dungeon();
|
||||||
|
|
||||||
void Generate();
|
void Generate();
|
||||||
void SpawnEntity(Entity* entity);
|
|
||||||
|
|
||||||
void Input(olc::PixelGameEngine* engine, float fTime);
|
void Input(olc::PixelGameEngine* engine, float fTime);
|
||||||
void Update(olc::PixelGameEngine* engine, float fTime);
|
void Update(olc::PixelGameEngine* engine, float fTime);
|
||||||
void Draw(olc::PixelGameEngine* engine, float fTime);
|
void Draw(olc::PixelGameEngine* engine, float fTime);
|
||||||
|
|
||||||
|
bool HasBegun = false;
|
||||||
|
|
||||||
Playable* Player;
|
Playable* Player;
|
||||||
Camera* ActiveCamera;
|
Camera* ActiveCamera;
|
||||||
|
|
||||||
int TileSize = 64;
|
olc::Renderable* EnemyRenderable;
|
||||||
|
olc::AnimatedSprite* EnemyAnimator;
|
||||||
|
std::vector<Enemy*> Enemies;
|
||||||
|
|
||||||
|
int TileSize = 64;
|
||||||
|
|
||||||
int DungeonWidth;
|
int DungeonWidth;
|
||||||
int DungeonHeight;
|
int DungeonHeight;
|
||||||
std::unordered_map<olc::vi2d, Tile*> DungeonTiles;
|
std::unordered_map<olc::vi2d, Tile*> DungeonTiles;
|
||||||
std::unordered_map<olc::vf2d, Entity*> Entities;
|
|
||||||
std::unordered_map<olc::vf2d, FixedItem*> FixedItems;
|
|
||||||
|
|
||||||
TileDictionary* TileSetDictionary;
|
TileDictionary* TileSetDictionary;
|
||||||
olc::Renderable* TileSet;
|
olc::Renderable* TileSet;
|
||||||
olc::Renderable* FireOverlay;
|
olc::Renderable* FireOverlay;
|
||||||
|
|
||||||
|
bool IsFireLit = false;
|
||||||
|
bool IsLightOn = true;
|
||||||
|
sf::SoundBuffer SoundBufferFireLighting;
|
||||||
|
sf::Sound SoundFireLighting;
|
||||||
|
sf::SoundBuffer SoundBufferFire;
|
||||||
|
sf::Sound SoundFire;
|
||||||
|
|
||||||
|
sf::SoundBuffer SoundBufferAmbient;
|
||||||
|
sf::Sound SoundAmbient;
|
||||||
|
sf::SoundBuffer SoundBufferFootsteps;
|
||||||
|
sf::Sound SoundFootsteps;
|
||||||
|
|
||||||
~Dungeon();
|
~Dungeon();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -21,13 +21,13 @@ constexpr const char* magic(ELogType::Type e)
|
|||||||
{
|
{
|
||||||
switch (e)
|
switch (e)
|
||||||
{
|
{
|
||||||
default: return ""; break;
|
default: return ""; break;
|
||||||
case ELogType::Type::NONE: return ""; break;
|
case ELogType::Type::NONE: return ""; break;
|
||||||
case ELogType::Type::INFO: return "INFO"; break;
|
case ELogType::Type::INFO: return "INFO"; break;
|
||||||
case ELogType::Type::DEBUG: return "DEBUG"; break;
|
case ELogType::Type::DEBUG: return "DEBUG"; break;
|
||||||
case ELogType::Type::WARN: return "WARN"; break;
|
case ELogType::Type::WARN: return "WARN"; break;
|
||||||
case ELogType::Type::ERR: return "ERROR"; break;
|
case ELogType::Type::ERR: return "ERROR"; break;
|
||||||
case ELogType::Type::PANIC: return "PANIC"; break;
|
case ELogType::Type::PANIC: return "PANIC"; break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,19 +67,19 @@ void OutputWorker(Logger* _Logger)
|
|||||||
|
|
||||||
switch (entity->Type)
|
switch (entity->Type)
|
||||||
{
|
{
|
||||||
case ELogType::INFO:
|
case ELogType::INFO:
|
||||||
Colour::ConsoleColour(EConsoleColour::FG_GREEN);
|
Colour::ConsoleColour(EConsoleColour::FG_GREEN);
|
||||||
break;
|
break;
|
||||||
case ELogType::DEBUG:
|
case ELogType::DEBUG:
|
||||||
Colour::ConsoleColour(EConsoleColour::FG_BLUE);
|
Colour::ConsoleColour(EConsoleColour::FG_BLUE);
|
||||||
break;
|
break;
|
||||||
case ELogType::WARN:
|
case ELogType::WARN:
|
||||||
Colour::ConsoleColour(EConsoleColour::FG_YELLOW);
|
Colour::ConsoleColour(EConsoleColour::FG_YELLOW);
|
||||||
break;
|
break;
|
||||||
case ELogType::ERR:
|
case ELogType::ERR:
|
||||||
Colour::ConsoleColour(EConsoleColour::FG_LIGHT_RED);
|
Colour::ConsoleColour(EConsoleColour::FG_LIGHT_RED);
|
||||||
break;
|
break;
|
||||||
case ELogType::PANIC:
|
case ELogType::PANIC:
|
||||||
Colour::ConsoleColour(EConsoleColour::FG_RED);
|
Colour::ConsoleColour(EConsoleColour::FG_RED);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -257,6 +257,7 @@ class Logger
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
std::atomic<bool> _IsRunning = false;
|
std::atomic<bool> _IsRunning = false;
|
||||||
|
std::atomic<bool> _Terminate = false;
|
||||||
|
|
||||||
std::condition_variable _TaskEnqueued;
|
std::condition_variable _TaskEnqueued;
|
||||||
std::queue<LogEntity*> _LogQueue;
|
std::queue<LogEntity*> _LogQueue;
|
||||||
|
|||||||
@@ -81,6 +81,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
<LinkIncremental>false</LinkIncremental>
|
<LinkIncremental>false</LinkIncremental>
|
||||||
|
<LibraryPath>$(LibraryPath)</LibraryPath>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
<ClCompile>
|
<ClCompile>
|
||||||
@@ -116,11 +117,14 @@
|
|||||||
<SDLCheck>true</SDLCheck>
|
<SDLCheck>true</SDLCheck>
|
||||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<ConformanceMode>true</ConformanceMode>
|
<ConformanceMode>true</ConformanceMode>
|
||||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
<LanguageStandard>stdcpplatest</LanguageStandard>
|
||||||
|
<AdditionalIncludeDirectories>;C:\dev\SFML\include</AdditionalIncludeDirectories>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
<AdditionalLibraryDirectories>C:\dev\SFML\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||||
|
<AdditionalDependencies>sfml-main.lib;sfml-audio.lib;sfml-system.lib</AdditionalDependencies>
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
@@ -132,12 +136,15 @@
|
|||||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<ConformanceMode>true</ConformanceMode>
|
<ConformanceMode>true</ConformanceMode>
|
||||||
<LanguageStandard>stdcpplatest</LanguageStandard>
|
<LanguageStandard>stdcpplatest</LanguageStandard>
|
||||||
|
<AdditionalIncludeDirectories>C:\dev\SFML\include;%(AdditionalIncludeDirectories);C:\dev\SFML\include</AdditionalIncludeDirectories>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
<OptimizeReferences>true</OptimizeReferences>
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
<AdditionalDependencies>sfml-main.lib;sfml-audio.lib;sfml-system.lib</AdditionalDependencies>
|
||||||
|
<AdditionalLibraryDirectories>C:\dev\SFML\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -1,4 +1,11 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
<PropertyGroup />
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<LocalDebuggerWorkingDirectory>$(ProjectDir)/../</LocalDebuggerWorkingDirectory>
|
||||||
|
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<LocalDebuggerWorkingDirectory>$(ProjectDir)/../</LocalDebuggerWorkingDirectory>
|
||||||
|
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||||
|
</PropertyGroup>
|
||||||
</Project>
|
</Project>
|
||||||
@@ -129,6 +129,12 @@ class Playable : public Entity
|
|||||||
std::array<Item*, 6> Inventory;
|
std::array<Item*, 6> Inventory;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class Enemy : public Entity
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
olc::vf2d Velocity = { 0.0f, 0.0f };
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
class TileDictionary
|
class TileDictionary
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -29,67 +29,125 @@ class Game : public olc::PixelGameEngine
|
|||||||
for (int i = 0; i < 5; i++)
|
for (int i = 0; i < 5; i++)
|
||||||
CreateLayer();
|
CreateLayer();
|
||||||
|
|
||||||
return true;
|
SetDrawTarget(uint8_t(0));
|
||||||
|
Clear(olc::BLANK);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DisplayTitle(float fTime)
|
void DisplayTitle(float fTime)
|
||||||
{
|
{
|
||||||
if (m_TimeAccumilator > 2.0f)
|
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>(_DeltaFade)), 6);
|
||||||
{
|
DrawString(5, ScreenHeight() - 15, "Powered by the OLC Pixel Game Engine", olc::Pixel(255, 255, 255, static_cast<int>(_DeltaFade)));
|
||||||
m_DeltaFade -= fTime * 200.0f;
|
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>(_DeltaFade)));
|
||||||
if (m_DeltaFade < 0.1f) m_DeltaFade = 0.0f;
|
|
||||||
}
|
|
||||||
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)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OnUserUpdate(float fTime) override
|
bool OnUserUpdate(float fTime) override
|
||||||
{
|
{
|
||||||
m_TimeAccumilator += fTime;
|
_TimeAccumilator += fTime;
|
||||||
|
|
||||||
Clear({38, 36, 40});
|
Clear({38, 36, 40});
|
||||||
|
|
||||||
// _Logger.Debug(m_TimeAccumilator);
|
// _Logger.Debug(m_TimeAccumilator);
|
||||||
|
|
||||||
//if (m_TimeAccumilator < 4.0f)
|
SetDrawTarget(uint8_t(0));
|
||||||
//{
|
Clear(olc::BLANK);
|
||||||
//DisplayTitle(fTime);
|
goto bruh;
|
||||||
//return true;
|
|
||||||
//}
|
if (_TimeAccumilator < 6.0f)
|
||||||
|
{
|
||||||
|
Clear({38, 36, 40});
|
||||||
|
if (_TimeAccumilator > 4.0f)
|
||||||
|
{
|
||||||
|
_DeltaFade -= fTime * 200.0f;
|
||||||
|
if (_DeltaFade < 0.1f) _DeltaFade = 0.0f;
|
||||||
|
}
|
||||||
|
DisplayTitle(fTime);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static bool IsFlicker = false;
|
||||||
|
if (_TimeAccumilator > 10.0f && _TimeAccumilator < 27.0f)
|
||||||
|
{
|
||||||
|
if (rand() % 60 < 1)
|
||||||
|
IsFlicker = true;
|
||||||
|
if (rand() % 20 < 1)
|
||||||
|
IsFlicker = false;
|
||||||
|
|
||||||
|
if (IsFlicker)
|
||||||
|
_Dungeon->IsLightOn = true;
|
||||||
|
else
|
||||||
|
_Dungeon->IsLightOn = false;
|
||||||
|
|
||||||
|
if (_TimeAccumilator > 13.0f)
|
||||||
|
{
|
||||||
|
_Dungeon->IsLightOn = false;
|
||||||
|
|
||||||
|
if (_TimeAccumilator > 26.0f)
|
||||||
|
{
|
||||||
|
_DeltaFade1 -= fTime * 200.0f;
|
||||||
|
if (_DeltaFade1 < 0.1f) _DeltaFade1 = 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
SetPixelMode(olc::Pixel::ALPHA);
|
||||||
|
if (_TimeAccumilator > 16.0f)
|
||||||
|
DrawString((ScreenWidth() / 2) - (7 * 3) * (std::string("the machine has done nothing for me").length() / 2), 40, "the machine has done nothing for me", olc::Pixel(255, 255, 255, static_cast<int>(_DeltaFade1)), 3);
|
||||||
|
if (_TimeAccumilator > 20.0f)
|
||||||
|
DrawString((ScreenWidth() / 2) - (7 * 3) * (std::string("the machine has left me with nothing").length() / 2), 120, "the machine has left me with nothing", olc::Pixel(255, 255, 255, static_cast<int>(_DeltaFade1)), 3);
|
||||||
|
if (_TimeAccumilator > 23.0f)
|
||||||
|
DrawString((ScreenWidth() / 2) - (7 * 5) * (std::string("i am nothing").length() / 2), 300, "i am nothing", olc::Pixel(255, 255, 255, static_cast<int>(_DeltaFade1)), 5);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_TimeAccumilator > 26.0f)
|
||||||
|
{
|
||||||
|
_Dungeon->IsFireLit = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bruh:
|
||||||
|
|
||||||
_Dungeon->Input(this, fTime);
|
_Dungeon->Input(this, fTime);
|
||||||
|
|
||||||
_Dungeon->Update(this, fTime);
|
_Dungeon->Update(this, fTime);
|
||||||
|
|
||||||
_Dungeon->Draw(this, fTime);
|
_Dungeon->Draw(this, fTime);
|
||||||
|
|
||||||
for (int i = 0; i < 5; i++)
|
for (int i = 0; i < 5; i++)
|
||||||
EnableLayer(i, true);
|
EnableLayer(i, true);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool OnUserDestroy() override
|
||||||
|
{
|
||||||
|
delete _Dungeon;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
long float m_TimeAccumilator = 0;
|
long float _TimeAccumilator = 0.0f;
|
||||||
|
|
||||||
float m_DeltaFade = 255.0f;
|
|
||||||
|
|
||||||
|
float _DeltaFade = 255.0f;
|
||||||
|
float _DeltaFade1 = 255.0f;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#include <SFML/Audio.hpp>
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
Logger& _Logger = Logger::getInstance();
|
Logger& _Logger = Logger::getInstance();
|
||||||
_Logger.InitializeFileLogging("./logs.log");
|
_Logger.InitializeFileLogging("./logs.log");
|
||||||
_Logger.InitializeLoggingThread();
|
_Logger.InitializeLoggingThread();
|
||||||
|
_Logger.Debug("Initializing");
|
||||||
|
|
||||||
Game _Game;
|
Game _Game;
|
||||||
_Game.Construct(1280, 720, 1, 1, false, false);
|
_Game.Construct(1280, 720, 1, 1, false, false);
|
||||||
_Logger.Info("Game Constructed");
|
_Logger.Info("Game Constructed");
|
||||||
|
|
||||||
if (!_Game.Start())
|
if (!_Game.Start())
|
||||||
{
|
{
|
||||||
_Logger.Panic("PGE Cannot start");
|
_Logger.Panic("PGE Cannot start");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_Logger.~Logger();
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 63 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 17 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 36 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 79 KiB |
BIN
res/ambient.ogg
Normal file
BIN
res/ambient.ogg
Normal file
Binary file not shown.
BIN
res/fire.wav
Normal file
BIN
res/fire.wav
Normal file
Binary file not shown.
BIN
res/fire_start.wav
Normal file
BIN
res/fire_start.wav
Normal file
Binary file not shown.
BIN
res/run.ogg
Normal file
BIN
res/run.ogg
Normal file
Binary file not shown.
BIN
sfml-audio-2.dll
Normal file
BIN
sfml-audio-2.dll
Normal file
Binary file not shown.
BIN
sfml-system-2.dll
Normal file
BIN
sfml-system-2.dll
Normal file
Binary file not shown.
Reference in New Issue
Block a user