Browse Source

Load enemies before every match

I modified the load_enemies() function to clear the enemy list before
populating it: with this change, the function can be called before every
new match, so that if the user changes level, the mumber of enemies is
also changed.
Matteo Zeccoli Marazzini 4 years ago
parent
commit
910b8e0553
2 changed files with 4 additions and 1 deletions
  1. 1 0
      functions.cpp
  2. 3 1
      invaders.cpp

+ 1 - 0
functions.cpp

@@ -405,6 +405,7 @@ void change_commands(int* commands){
 	
 void load_enemies(e_list& enemies,int enemy_num)
 {
+	enemies.clear();
 	for(int i=0; i<enemy_num; ++i)     				//loading enemies
 	{
 		static int c=0, r=0;

+ 3 - 1
invaders.cpp

@@ -98,6 +98,7 @@ int main(int argc,char** argv)
 	WALLS_NUM=2;
 	
 	choose_level(shootrate, refresh_time, boss1, level, commands);     	//choose difficulty level and set game parameters and boss
+	load_enemies(enemies,ENEMY_NUM);
 	player1.set_commands(commands);
 	erase();
 	
@@ -108,7 +109,6 @@ int main(int argc,char** argv)
 	
 	Score=newwin(3,10,R/3,C+3);
 	BossHP=newwin(3,15,R/3-3,C+3);
-	load_enemies(enemies,ENEMY_NUM);
 	
 	int i=0;
 	for(w_vec::iterator it=walls.begin(); it!=walls.end(); ++it, ++i)				//creating walls (in a quite symmetric pattern)
@@ -262,6 +262,7 @@ int main(int argc,char** argv)
 				erase();
 				refresh();
 				choose_level(shootrate, refresh_time, boss1, level, commands);
+				load_enemies(enemies,ENEMY_NUM);
 				reset(player1, enemies, boss1, bullets, bombs, walls, powerups,rockets, level,chflag); // reset box, player, enemy and deletes all bullets and bombs
 				erase();
 				refresh();
@@ -292,6 +293,7 @@ int main(int argc,char** argv)
 				erase();
 				refresh();
 				choose_level(shootrate, refresh_time, boss1, level, commands);
+				load_enemies(enemies,ENEMY_NUM);
 				reset(player1, enemies, boss1, bullets, bombs, walls, powerups,rockets,level,chflag);       // reset box, player, enemy and delete all bullets and bombs
 				erase();
 				refresh();