diff --git a/OLCCodeJam2020-The-Great-Machine.zip b/OLCCodeJam2020-The-Great-Machine.zip new file mode 100644 index 0000000..9809b7d Binary files /dev/null and b/OLCCodeJam2020-The-Great-Machine.zip differ diff --git a/The Great Machine.exe b/The Great Machine.exe index ad3e534..e054389 100644 Binary files a/The Great Machine.exe and b/The Great Machine.exe differ diff --git a/The Great Machine/Dungeon.cpp b/The Great Machine/Dungeon.cpp index 791f483..5447d2f 100644 --- a/The Great Machine/Dungeon.cpp +++ b/The Great Machine/Dungeon.cpp @@ -472,6 +472,13 @@ void Dungeon::Input(olc::PixelGameEngine* engine, float fTime) lastTile = currentTile; } +template +float vecDistance(T v1, T v2) +{ + return sqrt(pow(v2.x - v1.x, 2.0f) + pow(v2.y - v1.y, 2.0f) * 1.0f); +} + + void Dungeon::Update(olc::PixelGameEngine* engine, float fTime) { ActiveCamera->Update(fTime); @@ -479,25 +486,36 @@ void Dungeon::Update(olc::PixelGameEngine* engine, float fTime) if (!HasBegun) return; // spawn enemies - if (Enemies.size() == 0)// rand() % 1000 < 1) + if (rand() % 100 < 1) { Enemy* enemy = new Enemy(); enemy->Type = EEntity::Type::Enemy; enemy->Renderable = EnemyRenderable; enemy->Animator = EnemyAnimator; - enemy->Coords = { Player->Coords.x + static_cast((rand() % 100) - 50 ), Player->Coords.y + static_cast((rand() % 100) - 50) }; + enemy->Coords = { static_cast(((float)rand() / (float)RAND_MAX) * 1280.0f), static_cast(((float)rand() / (float)RAND_MAX) * 720.0f) }; + enemy->dxdy = { static_cast(rand() % 10 - 5), static_cast(rand() % 10 - 5) }; + + float distanceFromPlayer = vecDistance(Player->Coords, enemy->Coords); + _Logger.Debug(enemy->Coords.x, " ", enemy->Coords.y); + if (distanceFromPlayer > 100) + { + enemy->HitBox = new Collider{ 0, 0, 28, 36 }; + Enemies.push_back(enemy); + } + else + { + delete enemy; + } - 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(TileSize) * (fTime * (Player->Speed / 1.5f) * olc::vf2d(desiredLocation - enemy->Coords).norm()); + enemy->dxdy = static_cast(TileSize) * (fTime * (Player->Speed / 1.5f) * olc::vf2d(desiredLocation - enemy->Coords).norm()); - enemy->Coords += enemy->Velocity; + enemy->Coords += enemy->dxdy; } } @@ -611,6 +629,12 @@ void Dungeon::Draw(olc::PixelGameEngine* engine, float fTime) // left engine->FillRectDecal({0.0f, 0.0f}, {lightLeft, static_cast(engine->ScreenHeight())}, olc::BLACK); + // UI Layer + engine->SetDrawTarget(1); + engine->Clear(olc::BLANK); + + engine->DrawString({15, 15}, std::to_string(Enemies.size()), olc::WHITE, 5); + } Dungeon::~Dungeon() diff --git a/The Great Machine/Things.hpp b/The Great Machine/Things.hpp index 07e3d5e..6abca61 100644 --- a/The Great Machine/Things.hpp +++ b/The Great Machine/Things.hpp @@ -132,7 +132,7 @@ class Playable : public Entity class Enemy : public Entity { public: - olc::vf2d Velocity = { 0.0f, 0.0f }; + olc::vf2d dxdy = { 0.0f, 0.0f }; }; diff --git a/The Great Machine/main.cpp b/The Great Machine/main.cpp index 218e4ff..4c9c0ee 100644 --- a/The Great Machine/main.cpp +++ b/The Great Machine/main.cpp @@ -92,24 +92,24 @@ class Game : public olc::PixelGameEngine // TODO: Center these omd SetPixelMode(olc::Pixel::ALPHA); if (_TimeAccumilator > 16.0f) - DrawString((ScreenWidth() / 2) - (7 * 4) * (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(_DeltaFade1)), 3); + DrawString(15, 40, "the machine has done nothing for me", olc::Pixel(255, 255, 255, static_cast(_DeltaFade1)), 3); if (_TimeAccumilator > 20.0f) - DrawString((ScreenWidth() / 2) - (7 * 4) * (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(_DeltaFade1)), 3); + DrawString(15, 120, "the machine has left me with nothing", olc::Pixel(255, 255, 255, static_cast(_DeltaFade1)), 3); if (_TimeAccumilator > 23.0f) DrawString((ScreenWidth() / 2) - (7 * 7) * (std::string("i am nothing").length() / 2), 300, "i am nothing", olc::Pixel(255, 255, 255, static_cast(_DeltaFade1)), 6); - if (_TimeAccumilator > 25.0f) - DrawString((ScreenWidth() / 2) - (7 * 3) * (std::string("your demons can't survive the dark").length() / 2), 650, "your demons can't survive the dark", olc::Pixel(255, 255, 255, static_cast(_DeltaFade1)), 2); + if (_TimeAccumilator > 24.0f) + DrawString(15, 650, "your demons can't survive the dark", olc::Pixel(255, 255, 255, static_cast(_DeltaFade1)), 2); } } if (_TimeAccumilator > 26.0f) { + bruh: _Dungeon->IsFireLit = true; } - bruh: _Dungeon->Input(this, fTime); diff --git a/openal32.dll b/openal32.dll new file mode 100644 index 0000000..7760c05 Binary files /dev/null and b/openal32.dll differ