From bcb489c3b869fb6c15ee26d511f5042b8ce698ae Mon Sep 17 00:00:00 2001 From: salaaad2 Date: Tue, 4 Jan 2022 16:36:37 +0100 Subject: map read from file --- src/gameplay.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'src/gameplay.cpp') diff --git a/src/gameplay.cpp b/src/gameplay.cpp index 15f96bd..b424229 100644 --- a/src/gameplay.cpp +++ b/src/gameplay.cpp @@ -8,14 +8,24 @@ #include "gameplay.hpp" -#include - #include "raymath.h" +#include -Game::Game(void) +Game::Game(std::string const & path) { - nEnemies = 10; + std::ifstream ifs(path); + std::string tok; + std::cout << "Init: reading map file [" << path << "]" << std::endl; + while (ifs >> tok) + { + if (tok == "E") + { + ifs >> tok; + std::cout << "will spawn " << tok << " enemies" << std::endl; + nEnemies = std::atoi(tok.c_str()); + } + } enemies = new std::vector(nEnemies); player = new Entity; player->posX = SCREENWIDTH / 2; @@ -107,6 +117,7 @@ int Game::getKeys() const std::cout << "hit enemy at " << en->posX << "|" << en->posY << std::endl; enemies->erase(en); + return (0); } } DrawLineEx((Vector2){player->posX, player->posY}, Vector2Add((Vector2){player->posX, player->posY}, player->direction), 20, RED); -- cgit v1.2.3