From 14fe89b85a91d1bfe0b221b3b764f059ba6c550d Mon Sep 17 00:00:00 2001 From: kruegerzo72182 <puskelyzo72182@th-nuernberg.de> Date: Mon, 18 Jan 2021 17:23:50 +0100 Subject: [PATCH] level.cpp comments --- Level.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/Level.cpp b/Level.cpp index 46acccb..dd83b3b 100644 --- a/Level.cpp +++ b/Level.cpp @@ -112,6 +112,7 @@ void Level::addEnemy(std::unique_ptr<Enemy> enemy_) enemyVector.push_back(std::move(enemy_)); } +// primes the trooperSpawner void Level::fillTrooperSpawner(float posX, float posY, unsigned int nmbrEnemies) { direction dir = direction::LEFT; @@ -139,6 +140,7 @@ void Level::addPlayerProjectile(const PlayerProjectile& projectile) // weberma73121> ---------------------------------------------------------------------- // <kruegerzo72182 ---------------------------------------------------------------------- +// pops the last trooper from the trooperSpawner and reduces the vector capacity std::unique_ptr<Enemy> Level::getTrooperSpawn() { if(trooperSpawner.back() != 0){ @@ -160,6 +162,7 @@ void Level::enemyVector_PushBack(std::unique_ptr<Enemy> enemy_) this->enemyVector.push_back(std::move(enemy_)); } +// do all the Steps for movement and animations bool Level::doDoSteps(FloatSeconds const &frame_time) { player.step(player.getTopLeft(), frame_time, *this); @@ -191,6 +194,7 @@ bool Level::doDoSteps(FloatSeconds const &frame_time) for(auto it = sceneryVector.begin(); it != sceneryVector.end();) { auto& i = *it; if(!i.step(player.getTopLeft(), frame_time, *this)) { + // call the step method from the Entity class to see if the object was hit it = sceneryVector.erase(it); } else { it++; @@ -200,6 +204,7 @@ bool Level::doDoSteps(FloatSeconds const &frame_time) for(auto it = wallVector.begin(); it != wallVector.end();) { auto& i = *it; if(!i.step(player.getTopLeft(), frame_time, *this)) { + // call the step method from the Entity class to see if the object was hit it = wallVector.erase(it); } else { it++; @@ -208,6 +213,7 @@ bool Level::doDoSteps(FloatSeconds const &frame_time) return true; } +// checks if the two given buffers are overlaping bool Level::collHelper(Position const& vecPos, PixelBuffer const& vecBuf, float buffPosX, float buffPosY, int buffWidth, int buffHeigth) { for(int x = static_cast<int>(vecPos.X); x <= static_cast<int>(vecPos.X) + vecBuf.w(); ++x){ @@ -220,6 +226,7 @@ bool Level::collHelper(Position const& vecPos, PixelBuffer const& vecBuf, float return false; } +// iterates through the border, walls and the scenery and checks for collisions bool Level::checkCollision(float posX, float posY, int bufferWidth, int bufferHeigth) { for(auto i = this->wallVector.begin(); i != this->wallVector.end(); i++ ){ @@ -246,6 +253,11 @@ bool Level::HitEnemy(float posX, float posY, int bufferWidth, int bufferHeigth) } return false; } + +int Level::getScore() const +{ + return score; +} // hauerch71498> ---------------------------------------------------------------------- // <weberma73121 ---------------------------------------------------------------------- @@ -268,6 +280,8 @@ bool Level::HitPlayer(float posX, float posY, int bufferWidth, int bufferHeigth) // weberma73121> ---------------------------------------------------------------------- // <kruegerzo72182 ---------------------------------------------------------------------- +// remove scenery and wall objects from their corresponding vectors if theay are hit +// vector.erase() happens in doDoSteps() do to animation by Claudio bool Level::HitObstacle(float posX, float posY, Color hitColor, int bufferWidth, int bufferHeigth) { for(auto &i : wallVector){ @@ -287,11 +301,7 @@ bool Level::HitObstacle(float posX, float posY, Color hitColor, int bufferWidth, return false; } -int Level::getScore() const -{ - return score; -} - +// blit all objects, enemies and the player stored in the level class to the levelBuffer DynamicPixelBuffer const& Level::draw() { this->levelBuffer.clear(_t); -- GitLab