From 9882c48dd970fda09baf219155cc61abd8460e1f Mon Sep 17 00:00:00 2001
From: salaaad2 <arthurdurant263@gmail.com>
Date: Tue, 11 Jan 2022 19:03:38 +0100
Subject: stages now work as intended, with multiple waves : \[v0.0.9\]

---
 meta/maps/stage_1_start.bfm |  2 +-
 src/gameplay.cpp            | 20 +++++++++++++++++---
 src/gameplay.hpp            |  4 ++--
 3 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/meta/maps/stage_1_start.bfm b/meta/maps/stage_1_start.bfm
index c243e84..601bc8f 100644
--- a/meta/maps/stage_1_start.bfm
+++ b/meta/maps/stage_1_start.bfm
@@ -1,4 +1,4 @@
 BOSS 0 0
 ENEMIES 20 20
-WAVES 1 20
+WAVES 2 10
 NEXT stage_1_1.bfm
diff --git a/src/gameplay.cpp b/src/gameplay.cpp
index 54270e3..c27c712 100644
--- a/src/gameplay.cpp
+++ b/src/gameplay.cpp
@@ -56,7 +56,7 @@ Game::Game(std::string const& path) : current(path) {
     }
     ifs.close();
     enemies = new std::vector<Entity>;
-    for (auto i = 0; i < nEnemies; i++) {
+    for (auto i = 0; i < nPerWave; i++) {
         if (ehp == 0) {
             Entity en(ehp);
             en.radius = radius;
@@ -152,7 +152,7 @@ void Game::draw() {
 
 // progress the game & check for player death
 // NEW: go towards player NEXT: spawn at different furyTimes
-int Game::tick() const {
+int Game::tick() {
     auto target = GetMousePosition();
 
     DrawLine(player->posX, player->posY, target.x, target.y, RAYWHITE);
@@ -164,6 +164,20 @@ int Game::tick() const {
 
     player->direction = v2;
 
+    if (player->victims == nPerWave && nWaves > 1) {
+        nWaves--;
+        std::cout << "DEBUG : waves left [" << nWaves << std::endl;
+        std::cout << "DEBUG : victims [" << nWaves << std::endl;
+        for (int i = 0 ; i < nPerWave; i++) {
+            Entity en(1);
+            en.radius = 20;
+            en.idleTex = LoadTexture(SBIRE_TEX_IDLE);
+            en.hurtTex = LoadTexture(SBIRE_TEX_HURT);
+            enemies->push_back(en);
+            std::cout << "DEBUG : spawn new enemy [" << i << std::endl;
+        }
+    }
+
     for (auto en = enemies->begin(); en != enemies->end(); en++) {
         if (en->hp > 0) {
             if (en->posX >= SCREENWIDTH || en->posX <= 0) {
@@ -207,7 +221,7 @@ int Game::tick() const {
     return (0);
 }
 
-int Game::getKeys() const {
+int Game::getKeys() {
     auto oldX = 0, oldY = 0;  // get position before processing keys to check
                               // for player movement in threshold mode
     oldX = player->posX;
diff --git a/src/gameplay.hpp b/src/gameplay.hpp
index 3a4f4cb..a759f42 100644
--- a/src/gameplay.hpp
+++ b/src/gameplay.hpp
@@ -69,8 +69,8 @@ class Game {
 
     void start();
     void draw();
-    int tick() const;
-    int getKeys() const;
+    int tick() ;
+    int getKeys() ;
     int shoot() const;
     int hit(Entity en, Vector2 add1, Vector2 add2) const;
 
-- 
cgit v1.2.3