From d5e16effbac565310c1a43869d8d1d72264b400c Mon Sep 17 00:00:00 2001 From: salaaad2 Date: Sat, 22 Jan 2022 06:54:03 +0100 Subject: Parsing: the great rework (tm) finally works as intended --- meta/maps/stage_1_1.bfm | 2 +- meta/maps/stage_1_boss.bfm | 2 +- meta/maps/stage_2_start.bfm | 2 +- src/gameplay.cpp | 36 +++++++++++++++++++++++------------- 4 files changed, 26 insertions(+), 16 deletions(-) diff --git a/meta/maps/stage_1_1.bfm b/meta/maps/stage_1_1.bfm index 61008a4..a3dd5dd 100644 --- a/meta/maps/stage_1_1.bfm +++ b/meta/maps/stage_1_1.bfm @@ -1,5 +1,5 @@ BOSS 0 0 -ENEMIES 20 20 +MINIONS 20 20 WAVES 2 10 NEXT stage_1_boss.bfm BACKGROUND ../meta/media/sprites/stage_1_regbg.png diff --git a/meta/maps/stage_1_boss.bfm b/meta/maps/stage_1_boss.bfm index c5af193..57cae07 100644 --- a/meta/maps/stage_1_boss.bfm +++ b/meta/maps/stage_1_boss.bfm @@ -1,5 +1,5 @@ BOSS 1 10 -ENEMIES 2 100 +MINIONS 2 100 WAVES 1 2 NEXT stage_1_boss.bfm BACKGROUND ../meta/media/sprites/stage_1_bossbg.png diff --git a/meta/maps/stage_2_start.bfm b/meta/maps/stage_2_start.bfm index 957fd5d..756acb6 100644 --- a/meta/maps/stage_2_start.bfm +++ b/meta/maps/stage_2_start.bfm @@ -1,4 +1,4 @@ -BOSS 1 10 +BOSS 2 10 MINIONS 2 50 WAVES 1 2 NEXT stage_1_boss.bfm diff --git a/src/gameplay.cpp b/src/gameplay.cpp index a522cba..276d9e9 100644 --- a/src/gameplay.cpp +++ b/src/gameplay.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include "raymath.h" @@ -36,8 +37,11 @@ Level* Game::parse(std::string const& path) { } if (tok == "BOSS") { ifs >> tok; - ret->nBoss = (tok == "0") ? 0 : 1; - ret->bRadius = ret->mRadius; + ret->nBoss = std::atoi(tok.c_str()); + ifs >> tok; + ret->bHp = std::atoi(tok.c_str()); + ret->bRadius = 50; + std::cerr << "DEBUG: bosses : " << ret->nBoss << "\n"; } if (tok == "NEXT") { ifs >> tok; @@ -112,6 +116,7 @@ Game::Game(std::string const& path) { sourceRec = {0.0f, 0.0f, (float)frameWidth, (float)frameHeight}; origin = {(float)frameWidth, (float)frameHeight}; + nEnemies = level->nTotal; } Game::~Game() { @@ -125,6 +130,7 @@ void Game::draw() { auto left = std::to_string(enemies->size()); for (auto& en : *enemies) { + DrawCircle(en.posX, en.posY, en.radius, GREEN); if (en.hp <= 0) DrawTextureEx(en.hurtTex, (Vector2){en.posX - en.radius, en.posY - en.radius}, @@ -134,6 +140,12 @@ void Game::draw() { (Vector2){en.posX - en.radius, en.posY - en.radius}, 1.0f, 0.6f, WHITE); } + if (en.hp > 1) { + for (auto j = 0; j < en.hp; j++) { + DrawRectangle(en.posX + (10 * j), en.posY - 100, 10, 10, + COOLPURPLE); + } + } } // Destination rectangle Rectangle destRec = {player->posX, player->posY, frameWidth * 1.8f, @@ -154,14 +166,8 @@ void Game::draw() { i++) { // draw weapon ammo DrawRectangle(40 + (i * 20), SCREENHEIGHT - 60, 10, 30, RED); } - if (enemies->at(0).hp >= 2) { // draw hp in boss stages - for (auto i = 0; i < enemies->size(); i++) { - if (enemies->at(i).hp >= 2) { - for (auto j = 0; j < enemies->at(i).hp; j++) { - DrawRectangle(400 + (j * 40), 80 + (i * 40), 40, 30, - COOLPURPLE); - } - } + for (auto i = 0; i < enemies->size(); i++) { + if (enemies->at(i).hp >= 2) { } } } @@ -185,7 +191,9 @@ int Game::tick() { // baddie logic // + // std::cerr << "DEBUG: start baddie move loop \n"; for (auto en = enemies->begin(); en != enemies->end(); en++) { + // std::cerr << "DEBUG: direction :" << en->direction.x<< "\n"; if (en->hp > 0) { if (en->posX >= SCREENWIDTH || en->posX <= 0) { en->direction.x = -en->direction.x; @@ -209,9 +217,10 @@ int Game::tick() { en->posY += MINION_SPEED; en->direction.y += 0.1f; } - if ((GetRandomValue(0, 100) == - 50) && // make enemy fire at random intervals - (en->currentWeapon != nullptr)) { + if ((en->currentWeapon != nullptr) && + (GetRandomValue(0, 100) == + 50) // make enemy fire at random intervals + ) { en->currentWeapon->bang(enemies, &(*en)); nEnemies++; return ( @@ -223,6 +232,7 @@ int Game::tick() { if (en->posX >= SCREENWIDTH || en->posX <= 0 || en->posY >= SCREENHEIGHT) { enemies->erase(en); + std::cerr << "DEBUG: delete baddie" << std::endl; return (0); } } -- cgit v1.2.3