Skip to content
Snippets Groups Projects
Commit dad62155 authored by il0z's avatar il0z
Browse files

Spawn Enemies endlessly

parent ac6ccc13
No related branches found
No related tags found
No related merge requests found
......@@ -16,10 +16,21 @@
//constexpr double PI = 3.14159265358979323846;
// <kruegerzo72182
bool debug = false;
bool spawnTroopers = true;
float trooperTimer = 0.0f;
float trooperSpawnTime = 3.0f;
int trooperSpawnX = 120;
int trooperSpawnY = 170;
int trooperSpawnCount = 1; // +1
float bomberTimer = 25.0f;
float bomberSpawnTime = 30.0f;
float tankTimer = 15.0f;
float tankSpawnTime = 25.0f;
float difficultyTimer = 0.0f;
float difficultyChangeTime = 60.0f;
int screenWidth = 320;
int screenHeigth = 320;
int difficulty = 0;
// global helper funktion to add "buildings"
void addBuilding(float x, float y, int size, Level &level_ptr)
......@@ -62,26 +73,38 @@ public:
}
else {
platform.set_title(
"Player X: " +
std::to_string(std::lround(player_.getLeft())) +
"<Player X: " +
std::to_string(std::lround(player_.getTopLeft().X)) +
" --- Player Y: " +
std::to_string(std::lround(player_.getTop()))
std::to_string(std::lround(player_.getTopLeft().Y)) +
" --- difficulty: " + std::to_string(difficulty) +
" --- trooperSpawnCount: " + std::to_string(trooperSpawnCount) +
" --- debug>"
);
}
}
// hoffmanncl72341>
// <kruegerzo72182
//Spawn the troopers from the trooperspawner
if(spawnTroopers){
trooperTimer = trooperTimer + frame_time.count();
if(level.getEnemySpawnCount() != 0){
if(trooperTimer > 3.0f){
if(trooperTimer > trooperSpawnTime){
level.enemyVector_PushBack(level.getTrooperSpawn());
trooperTimer = 0.0f;
}
}
else{
spawnTroopers = false;
level.fillTrooperSpawner(static_cast<float>(trooperSpawnX), static_cast<float>(trooperSpawnY), trooperSpawnCount);
}
}
if(true){
}
//Spawn bombers from different directions endlessly
bomberTimer = bomberTimer + frame_time.count();
if(bomberTimer > 30.0f){
if(bomberTimer > bomberSpawnTime){
int direction = rand() % 4;
float bombX;
float bombY;
......@@ -106,6 +129,59 @@ public:
}
level.enemyVector_PushBack(std::make_unique<Bomber>(Bomber(bombX, bombY, direction, 0)));
bomberTimer = 0.0f;
if(difficulty < 25)
{
bomberSpawnTime = bomberSpawnTime - difficulty;
}
}
if(bomberSpawnTime < 4){
bomberSpawnTime = 5;
}
tankTimer = tankTimer + frame_time.count();
if(tankTimer > tankSpawnTime){
int direction = 0;
int position = rand() % 6;
float tankX;
float tankY;
switch ( position ) {
case 1:
tankX = static_cast<float>(50);
tankY = static_cast<float>(150);
direction = 0;
break;
case 2:
tankX = static_cast<float>(200);
tankY = static_cast<float>(160);
direction = 2;
break;
case 3:
tankX = static_cast<float>(270);
tankY = static_cast<float>(50);
direction = 1;
break;
case 4:
tankX = static_cast<float>(15);
tankY = static_cast<float>(225);
direction = 3;
break;
case 5:
tankX = static_cast<float>(170);
tankY = static_cast<float>(210);
direction = 2;
break;
default:
tankX = static_cast<float>(20);
tankY = static_cast<float>(25);
direction = 3;
break;
}
level.enemyVector_PushBack(std::make_unique<Tank>(Tank(tankX, tankY, direction, 0)));
tankTimer = 0.0f;
if(difficulty < 25)
{
//tankSpawnTime = tankSpawnTime - difficulty;
}
}
// kruegerzo72182>
......@@ -121,6 +197,17 @@ public:
// enemy movement
GameOverFlag = (level.doDoSteps(frame_time) == false);
difficultyTimer = difficultyTimer + frame_time.count();
if((difficultyTimer > difficultyChangeTime))
{
difficulty++;
difficultyTimer = 0.0f;
spawnTroopers = true;
if(trooperSpawnCount < 11 && difficulty%4 == 0){
trooperSpawnCount = trooperSpawnCount + 2;
}
}
// Output to the console, Gamelogic should happen before this
auto const &levelBuffer = level.draw();
if(GameOverFlag) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment