aboutsummaryrefslogtreecommitdiffstats
path: root/src/gameplay.cpp
diff options
context:
space:
mode:
authorsalaaad2 <arthurdurant263@gmail.com>2022-01-04 16:36:37 +0100
committersalaaad2 <arthurdurant263@gmail.com>2022-01-04 16:36:37 +0100
commitbcb489c3b869fb6c15ee26d511f5042b8ce698ae (patch)
treecd663d747e0ed00d57c299e85ad193971ed8febc /src/gameplay.cpp
parentadd headers (diff)
downloadthreshold-bcb489c3b869fb6c15ee26d511f5042b8ce698ae.tar.gz
threshold-bcb489c3b869fb6c15ee26d511f5042b8ce698ae.tar.bz2
threshold-bcb489c3b869fb6c15ee26d511f5042b8ce698ae.tar.xz
threshold-bcb489c3b869fb6c15ee26d511f5042b8ce698ae.tar.zst
threshold-bcb489c3b869fb6c15ee26d511f5042b8ce698ae.zip
map read from file
Diffstat (limited to 'src/gameplay.cpp')
-rw-r--r--src/gameplay.cpp19
1 files changed, 15 insertions, 4 deletions
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 <iostream>
-
#include "raymath.h"
+#include <fstream>
-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<Entity>(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);