diff --git a/Bomber.cpp b/Bomber.cpp index 5ff99b9b4385c0226c967f77fba0f4b001663221..0e962bb18e5f414c0046a9eb75f2c2037eb2de42 100644 --- a/Bomber.cpp +++ b/Bomber.cpp @@ -5,7 +5,7 @@ Bomber::Bomber(float x, float y, enum direction dir, int animationstep) } int Bomber::getScore() { - return 0; + return 1000; } static StaticPixelBuffer<15,9> constexpr front[2] = { {{{ diff --git a/Level.cpp b/Level.cpp index 78f62e6003ca24d1da376fb58a76d97fa53a7f68..0153d34055fc5efd47470ddc07993f1051f9aec9 100644 --- a/Level.cpp +++ b/Level.cpp @@ -5,7 +5,7 @@ #include "playerprojectile.hpp" #include "PixelShaders.hpp" -// <kruegerzo72182 +// <kruegerzo72182 ---------------------------------------------------------------------- // Wall stuff -------------------------------------------------------------------------- DynamicPixelBuffer Wall::constructWallBuffer(Orientation orientation, int length, int thickness) @@ -77,7 +77,7 @@ Level::Level(int width, int heigth, Player &player) : levelBuffer(width, heigth), player(player) { - int thickness = 6; + int thickness = 10; borders.push_back(Wall(width, thickness, { 0.0f, 0.0f }, Orientation::Horizontal)); borders.push_back(Wall(width, thickness, { 0.0f, static_cast<float>(heigth - thickness )}, Orientation::Horizontal)); borders.push_back(Wall(heigth, thickness, { 0.0f, 0.0f }, Orientation::Vertical)); @@ -120,27 +120,25 @@ void Level::fillTrooperSpawner(float posX, float posY, unsigned int nmbrEnemies) dir=direction(rand()%4); } } -// kruegerzo72182> -/**Hauerch71498 Enemy Addprojectile**/ +// kruegerzo72182> ---------------------------------------------------------------------- + +// <hauerch71498 ---------------------------------------------------------------------- +/**Enemy Addprojectile**/ void Level::addEnemyProjectile(const EnemyProjectile& projectile) { projectileVector.push_back(std::make_unique<EnemyProjectile>(projectile)); }; -/**weberma73121 Player Addprojectile**/ +// hauerch71498> ---------------------------------------------------------------------- + +// <weberma73121 ---------------------------------------------------------------------- +/**Player Addprojectile**/ void Level::addPlayerProjectile(const PlayerProjectile& projectile) { projectileVector.push_back(std::make_unique<PlayerProjectile>(projectile)); }; -/*void Level::removeEnemyProjectile(const EnemyProjectile& projectile) -{ - projectileVector.erase(std::find(projectileVector.begin(),projectileVector.end(),projectile)); -}; -void Level::addPlayerProjectile(const EnemyProjectile& projectile) -{ - projectileVector.push_back(std::make_unique<Projectile>(projectile)); -};*/ -/****/ -// <kruegerzo72182 +// weberma73121> ---------------------------------------------------------------------- + +// <kruegerzo72182 ---------------------------------------------------------------------- std::unique_ptr<Enemy> Level::getTrooperSpawn() { if(trooperSpawner.back() != 0){ @@ -235,8 +233,10 @@ bool Level::checkCollision(float posX, float posY, int bufferWidth, int bufferHe } return false; } -// kruegerzo72182> -/*Hauerch71498 Hitdetection*/ +// kruegerzo72182> ---------------------------------------------------------------------- + +// <hauerch71498 ---------------------------------------------------------------------- +/*Hitdetection*/ bool Level::HitEnemy(float posX, float posY, int bufferWidth, int bufferHeigth) { if(collHelper(player.getTopLeft(),player.getSprite(),posX,posY,bufferWidth,bufferHeigth)) @@ -246,7 +246,10 @@ bool Level::HitEnemy(float posX, float posY, int bufferWidth, int bufferHeigth) } return false; } -//weberma73121 Hitdetection +// hauerch71498> ---------------------------------------------------------------------- + +// <weberma73121 ---------------------------------------------------------------------- +// Hitdetection bool Level::HitPlayer(float posX, float posY, int bufferWidth, int bufferHeigth) { for(auto &i : this->enemyVector){ @@ -265,8 +268,9 @@ bool Level::HitPlayer(float posX, float posY, int bufferWidth, int bufferHeigth) return false; } /*For projectiles, Gameover*/ +// weberma73121> ---------------------------------------------------------------------- -// <kruegerzo72182 +// <kruegerzo72182 ---------------------------------------------------------------------- bool Level::HitObstacle(float posX, float posY, Color hitColor, int bufferWidth, int bufferHeigth) { for(auto &i : wallVector){ @@ -310,12 +314,13 @@ DynamicPixelBuffer const& Level::draw() i->blit(this->levelBuffer); } } - // kruegerzo72182> - /**Hauerch71498**/ +// kruegerzo72182> ---------------------------------------------------------------------- + +// <hauerch71498 ---------------------------------------------------------------------- for(auto & i : this->projectileVector){ if(i != nullptr){ this->levelBuffer.blit_topleft({ static_cast<int>(i->getX()), static_cast<int>(i->getY()) }, i->getSprite());} } - /****/ +// hauerch71498> ---------------------------------------------------------------------- return this->levelBuffer; } diff --git a/Scoreb.cpp b/Scoreb.cpp index aa7589ad2efd06753db6d92c1cdcd74bb65c4966..d1b9df1c4585a2c97232c390cd09e22961ea5e6d 100644 --- a/Scoreb.cpp +++ b/Scoreb.cpp @@ -5,17 +5,17 @@ Score::Score(int W,int H) GameOverPos.x = W/2-16; GameOverPos.y = H/2-9; ScoreBoard[5].ScorePos.x = W-70; - ScoreBoard[5].ScorePos.y = 20; + ScoreBoard[5].ScorePos.y = scoreBoardHeigth; ScoreBoard[4].ScorePos.x = W-60; - ScoreBoard[4].ScorePos.y = 20; + ScoreBoard[4].ScorePos.y = scoreBoardHeigth; ScoreBoard[3].ScorePos.x = W-50; - ScoreBoard[3].ScorePos.y = 20; + ScoreBoard[3].ScorePos.y = scoreBoardHeigth; ScoreBoard[2].ScorePos.x = W-40; - ScoreBoard[2].ScorePos.y = 20; + ScoreBoard[2].ScorePos.y = scoreBoardHeigth; ScoreBoard[1].ScorePos.x = W-30; - ScoreBoard[1].ScorePos.y = 20; + ScoreBoard[1].ScorePos.y = scoreBoardHeigth; ScoreBoard[0].ScorePos.x = W-20; - ScoreBoard[0].ScorePos.y = 20; + ScoreBoard[0].ScorePos.y = scoreBoardHeigth; } ScoreB::ScoreB() { @@ -45,11 +45,11 @@ static StaticPixelBuffer<34,18> constexpr gameover= { static StaticPixelBuffer<4,6> constexpr eins= { {{ - {" 1 "}, - {"110 "}, - {" 10 "}, - {" 10 "}, - {" 10 "}, + {" B "}, + {"BB0 "}, + {" B0 "}, + {" B0 "}, + {" B0 "}, {" 0 "} }}}; static StaticPixelBuffer<4,6> constexpr zwei= { diff --git a/Scoreb.hpp b/Scoreb.hpp index 63a6c1ad926b81a8580209f2acec092aa42f5901..61062ab314473b1acb0b6f02ce50dc9d94038ddf 100644 --- a/Scoreb.hpp +++ b/Scoreb.hpp @@ -26,6 +26,7 @@ public: ScoreB ScoreBoard[6]; int screenwidth = 0; int screenheight = 0; + int scoreBoardHeigth = 3; }; diff --git a/main.cpp b/main.cpp index 8aa9c7d803ad0b7e46133092c90ab5fff7f065b0..07634e1a4e36580f9360e9c6de41db7b31bb61b5 100644 --- a/main.cpp +++ b/main.cpp @@ -14,23 +14,29 @@ #include "player.hpp" // weberma73121 //constexpr double PI = 3.14159265358979323846; -// <kruegerzo72182 +// <kruegerzo72182 ---------------------------------------------------------------------- bool debug = false; +// trooperspawner variables bool spawnTroopers = true; float trooperTimer = 0.0f; float trooperSpawnTime = 3.0f; int trooperSpawnX = 120; int trooperSpawnY = 170; int trooperSpawnCount = 1; // +1 +// bomberspawner variables float bomberTimer = 25.0f; float bomberSpawnTime = 30.0f; +float bomberSpawnDiffMod = 0.5f; +// tankspawner variables float tankTimer = 15.0f; float tankSpawnTime = 25.0f; +// difficulty variables float difficultyTimer = 0.0f; float difficultyChangeTime = 60.0f; +int difficulty = 0; +// screen int screenWidth = 320; int screenHeigth = 320; -int difficulty = 0; // global helper funktion to add "buildings" @@ -43,8 +49,8 @@ void addBuilding(float x, float y, int size, Level &level_ptr) level_ptr.addWall(size, thickness, { x, y }, Orientation::Vertical); level_ptr.addWall(size, thickness, { x + size - thickness, y }, Orientation::Vertical); } -// kruegerzo72182> -// <hoffmanncl72341 +// kruegerzo72182> ---------------------------------------------------------------------- +// <hoffmanncl72341 --------------------------------------------------------------------- class GameLoop { int frame = 0; FloatSeconds time_elapsed{ 0.0f }; @@ -79,13 +85,15 @@ public: " --- Player Y: " + std::to_string(std::lround(player_.getTopLeft().Y)) + " --- difficulty: " + std::to_string(difficulty) + - " --- trooperSpawnCount: " + std::to_string(trooperSpawnCount) + + " --- bomberSpawnTime: " + std::to_string(bomberSpawnTime) + + " --- bomberTimer: " + std::to_string(bomberTimer) + " --- debug>" ); } } - // hoffmanncl72341> - // <kruegerzo72182 +// hoffmanncl72341> --------------------------------------------------------------------- + +// <kruegerzo72182 ---------------------------------------------------------------------- //Spawn the troopers from the trooperspawner if(spawnTroopers){ trooperTimer = trooperTimer + frame_time.count(); @@ -97,6 +105,21 @@ public: } else{ spawnTroopers = false; + int trPosition = rand() % 2; + switch ( trPosition ) { + case 1: + trooperSpawnX = 120; + trooperSpawnY = 170; + break; + case 2: + trooperSpawnX = 200; + trooperSpawnY = 160; + break; + default: + trooperSpawnX = 270; + trooperSpawnY = 50; + break; + } level.fillTrooperSpawner(static_cast<float>(trooperSpawnX), static_cast<float>(trooperSpawnY), trooperSpawnCount); } } @@ -106,7 +129,7 @@ public: //Spawn bombers from different directions endlessly bomberTimer = bomberTimer + frame_time.count(); if(bomberTimer > bomberSpawnTime){ - direction dir=direction(rand()%4); + direction dir = direction(rand()%4); float bombX; float bombY; int offset = 20; @@ -115,11 +138,11 @@ public: bombX = player_.getTopLeft().X; bombY = static_cast<float>(screenHeigth + offset); break; - case direction::RIGHT: //left + case direction::LEFT: //left bombX = static_cast<float>(screenWidth + offset); bombY = player_.getTopLeft().Y; break; - case direction::LEFT: //right + case direction::RIGHT: //right bombX = static_cast<float>(-offset); bombY = player_.getTopLeft().Y; break; @@ -130,15 +153,9 @@ public: } level.enemyVector_PushBack(std::make_unique<Bomber>(Bomber(bombX, bombY, dir, 0))); bomberTimer = 0.0f; - if(difficulty < 25) - { - bomberSpawnTime = bomberSpawnTime - difficulty; - } - } - if(bomberSpawnTime < 4){ - bomberSpawnTime = 5; } + //Spawn tanks from different positions endlessly tankTimer = tankTimer + frame_time.count(); if(tankTimer > tankSpawnTime){ direction dir; @@ -184,9 +201,10 @@ public: //tankSpawnTime = tankSpawnTime - difficulty; } } - // kruegerzo72182> +// kruegerzo72182> ---------------------------------------------------------------------- - if(!GameOverFlag) //Hauerch71498 +// <hauerch71498 ---------------------------------------------------------------------- + if(!GameOverFlag) { // <kruegerzo72182 // player movement @@ -197,18 +215,32 @@ public: // enemy movement GameOverFlag = (level.doDoSteps(frame_time) == false); +// hauerch71498> ---------------------------------------------------------------------- +// <kruegerzo72182 ---------------------------------------------------------------------- difficultyTimer = difficultyTimer + frame_time.count(); if((difficultyTimer > difficultyChangeTime)) { difficulty++; difficultyTimer = 0.0f; spawnTroopers = true; + // raise troopers to spawn every 4 levels until max troppers to spawn is 12 if(trooperSpawnCount < 11 && difficulty%4 == 0){ trooperSpawnCount = trooperSpawnCount + 2; } + if(difficulty < 55) + { + if(bomberSpawnTime < 4){ + bomberSpawnTime = 5; + } + else{ + bomberSpawnTime = bomberSpawnTime - bomberSpawnDiffMod; + } + } } +// kruegerzo72182> ---------------------------------------------------------------------- +// <hoffmanncl72341 --------------------------------------------------------------------- // Output to the console, Gamelogic should happen before this auto const &levelBuffer = level.draw(); Highscore.SetScoreSprite(level.getScore()); @@ -231,8 +263,7 @@ public: framebuffer.blit_topleft(i.ScorePos,i.getScoreSprite()); } } - // kruegerzo72182> - // <hoffmanncl72341 + platform.render(framebuffer); ++frame; @@ -242,12 +273,13 @@ public: int run(Platform &platform) { - // hoffmanncl72341> + GameLoop gameloop; +// hoffmanncl72341> --------------------------------------------------------------------- + +// <kruegerzo72182 ---------------------------------------------------------------------- // add the player Player player(15, 15); - GameLoop gameloop; - // build the level layout Level level1(screenWidth, screenHeigth, player); // adds a Wall to the level (length, thickness, position X, position Y, orientation) @@ -284,9 +316,10 @@ int run(Platform &platform) // add enemies to the level level1.addEnemy(std::make_unique<Tank>(Tank(50, 150, direction::BACK, 0))); level1.addEnemy(std::make_unique<Tank>(Tank(200, 160, direction::LEFT, 0))); - level1.fillTrooperSpawner(120, 170, 4); - // kruegerzo72182> - // <hoffmanncl72341 + level1.fillTrooperSpawner(static_cast<float>(trooperSpawnX), static_cast<float>(trooperSpawnY), 3); +// kruegerzo72182> ---------------------------------------------------------------------- + +// <hoffmanncl72341 --------------------------------------------------------------------- while(true) { platform.frame([&](FloatSeconds const &frame_time) { gameloop.run(platform, frame_time, level1, player); @@ -301,4 +334,4 @@ int main() run(platform); platform.exit(); } -// hoffmanncl72341> +// hoffmanncl72341> ---------------------------------------------------------------------