Browse Source

Merge branch 'cleanup' of lcmstaff/invaders into master

blue 4 years ago
parent
commit
f3a408991a
6 changed files with 10 additions and 749 deletions
  1. 0 300
      box.cpp
  2. 0 40
      box.hpp
  3. 0 77
      definitions.hpp.bu
  4. 6 1
      functions.hpp
  5. 0 324
      invaders_fork.cpp
  6. 4 7
      makefile

+ 0 - 300
box.cpp

@@ -1,300 +0,0 @@
-#include "box.hpp"
-
-void Box::refresh(b_list& bullets, b_list& bombs, e_list& enemies, player& player1, int &score, boss& boss1,w_vec &walls, b_list& powerups,r_list& rockets)
-{
-	clear();			//Empty matrix
-	upload(bullets, bombs, enemies, player1, boss1, walls, powerups, rockets);	//writes id values on matrix
-	kill(bullets, bombs, enemies, score, boss1, walls, powerups, player1, rockets);	//evaluates interactions and removes what should be removed
-	clear();			//empty again
-	upload(bullets, bombs, enemies, player1, boss1, walls, powerups, rockets);	//rewrites survived game objects' id
-}
-
-
-
-void Box::print()		//this method is used for debugging purposes, not in game
-{
-	for(int k=0; k<R; k++)
-	{
-		for(int l=0; l<C; l++)
-			cout << matrix[k][l] << " ";
-		cout << endl;
-	}
-	cout << endl;
-}
-
-
-
-void Box::clear()
-{
-	for(int i=0; i<R; i++)
-		for(int j=0; j<C; j++)
-			matrix[i][j]=0;			
-}
-
-
-
-void Box::upload(b_list & bullets, b_list& bombs, e_list& enemies, player& player1, boss& boss1, w_vec &walls, b_list & powerups,r_list& rockets)	//writes on the box the IDs of all game objects (even if superimposed). Also uploads curses's window 
-{
-
-	e_list::const_iterator e_end = enemies.end();
-	for(e_list::iterator it=enemies.begin(); it!=e_end; ++it)
-		if(it->alive){
-			attron(COLOR_PAIR(2));
-			mvaddch(it->y,it->x,ENEMY_SPRITE);			
-			matrix[it->y][it->x]+=it->id;
-		}
-	
-	if(!bullets.empty())
-		for(b_list::iterator it=bullets.begin(); it!=bullets.end(); ++it){
-			attron(COLOR_PAIR(3));
-			mvaddch(it->y,it->x,BULLET_SPRITE);
-			matrix[it->y][it->x]+=it->id;
-		}
-		
-	if(!rockets.empty())
-		for(r_list::iterator it=rockets.begin(); it!=rockets.end(); ++it){
-			attron(COLOR_PAIR(4));
-			mvaddch(it->y,it->x,ROCKET_SPRITE);
-			matrix[it->y][it->x]+=it->id;
-		}
-
-	if(!bombs.empty())
-		for(b_list::iterator it=bombs.begin(); it!=bombs.end(); ++it){
-			attron(COLOR_PAIR(6));
-			mvaddch(it->y,it->x,BOMB_SPRITE);
-			matrix[it->y][it->x]+=it->id;
-		}
-		
-	if(!powerups.empty())
-		for(b_list::iterator it=powerups.begin(); it!=powerups.end(); ++it){
-			if(it->id==64){
-				attron(COLOR_PAIR(3));
-				mvaddch(it->y,it->x,POWERUP1_SPRITE);
-			}
-			else if(it->id==128){
-				attron(COLOR_PAIR(1));
-				mvaddch(it->y,it->x,POWERUP2_SPRITE);
-			}
-			else{
-				attron(COLOR_PAIR(4));
-				mvaddch(it->y,it->x,POWERUP3_SPRITE);
-			}
-			matrix[it->y][it->x]+=it->id;
-		}
-				
-	for(int i=player1.x; i<player1.x+player1.length; ++i){
-		attron(COLOR_PAIR(1));
-		mvaddch(player1.y,i,PLAYER_SPRITE);
-		matrix[player1.y][i]+=player1.id;
-	}
-	
-	for(unsigned int i=0;i<walls.size();i++)
-		for(int k=0;k<walls[i].height;k++)
-			for(int j=0;j<walls[i].width;j++)
-				if(walls[i].health[k][j]>0){
-					attron(COLOR_PAIR(4));
-					if(walls[i].health[k][j]==1)
-						attron(COLOR_PAIR(2));
-					mvaddch(walls[i].y+k,walls[i].x+j,WALL_SPRITE);
-					matrix[walls[i].y+k][walls[i].x+j]+=walls[i].id;
-				}
-				
-	if(boss1.alive)					
-		for(int i=boss1.y; i<boss1.y+boss1.height; i++)
-			for(int j=boss1.x; j<boss1.x+boss1.width; j++){
-				if(boss1.health>.5*boss1.healthmax)
-					attron(COLOR_PAIR(5));
-				else if(boss1.health>.25*boss1.healthmax)
-					attron(COLOR_PAIR(3));
-				else
-					attron(COLOR_PAIR(2));
-				mvaddch(i,j,boss1.picture[i-boss1.y][j-boss1.x]);
-				matrix[i][j]+=boss1.id;
-			}
-	
-}
-
-
-
-void Box::kill(b_list & bullets, b_list& bombs, e_list& enemies, int &score, boss& boss1, w_vec &walls, b_list & powerups, player& player1,r_list& rockets)   //controls what changes the box's elements must undergo
-{	
-	
-	for(int i=0; i<R; i++)
-		for(int j=0; j<C; j++)
-		{
-			if(i==0 || i==R-1)
-				switch(matrix[i][j])					//destroys bullets and bombs at box's limits
-				{		              			//DESTRUCTION SHOULD HAPPEN AFTER THEY'VE BEEN PRINTED ONCE!!
-					case 2:
-					case 8:
-					case 64:
-					case 128:
-					case 256:
-					case 512:
-						destroy(i,j,bullets,bombs,enemies,powerups,rockets);
-						break;
-					default:
-						break;
-				}
-			if(!boss1.alive && matrix[i][j]==16) destroy(i,j,bullets,bombs,enemies,powerups,rockets);
-				
-				switch (matrix[i][j])     //id player=1 bullet=2 enemy=4 bomb=8 boss=16 wall=32 powerup+=64, powerup-=128, rocket=256, powerupX=512
-				{		                   
-					case 2:               //destruction cases: 6=enemy+bullet; 10=bomb+bullet; 14=bomb+enemy+bullet; and so on...
-						if(i!=0)
-							if(matrix[i-1][j]==8)	//to make the bullets less 'transparent'...
-							{
-								destroy(i, j, bullets,bombs, enemies,powerups,rockets);
-								destroy(i-1, j, bullets,bombs,enemies,powerups,rockets);
-								score+=50;
-							}
-						break; 
-
-					case 6:			//enemy+bullet
-						score+=100;
-						destroy(i,j,bullets,bombs,enemies,powerups,rockets);
-						if((double)rand()/RAND_MAX<(double)AVERAGE_DROP/ENEMY_NUM)	//a powerup is dropped (AVERAGE_DROP is the mean number of powerups dropped per play in Normal mode)
-						{
-							if((double)rand()/RAND_MAX<1./POWERUP_RATIO){		//1 powerup out of POWERUP_RATIO is either a "-" (with ID 128 instead of 64) or a "X"
-								if((double)rand()/RAND_MAX<1./ROCKET_RATIO){ 	//1 powerup out of ROCKET_RATIO*POWERUP_RATIO is a "X" (ID 512)
-									powerup newpowerup(j,i+1,512);		
-									powerups.push_back(newpowerup);
-								}
-								else{
-									powerup newpowerup(j,i+1,128);		
-									powerups.push_back(newpowerup);
-								}
-							}
-							else{
-								powerup newpowerup(j,i+1);		//otherwise, it is a "+"
-								powerups.push_back(newpowerup);
-							}
-								
-						}
-						break;
-					case 10:			//bomb+bullet
-						score+=50;
-						destroy(i,j,bullets,bombs,enemies,powerups,rockets);
-						break;
-					case 14:			//bomb+enemy+bullet
-						score+=150;
-						destroy(i,j,bullets,bombs,enemies,powerups,rockets);
-						break;
-					case 18:			//boss+bullet
-					case 272:
-						if(j>=boss1.x+boss1.width/2-2 && j<=boss1.x+boss1.width/2+2)
-							boss1.health--;
-						break;	
-					case 34:			//wall+bullet
-					case 40:			//wall+bomb
-					case 288:			//wall+rocket
-						destroy(i,j,bullets,bombs,enemies,powerups,rockets);
-						for(unsigned int k=0;k<walls.size();k++)
-							if(j>=walls[k].x && j<=walls[k].x+walls[k].width && i>=walls[k].y && i<=walls[k].y+walls[k].height)	//finds out what wall has been hit
-								walls[k].health[i-walls[k].y][j-walls[k].x]--;		//subtracts 1 HP to the hit wall's correct health matrix's element 
-						break;
-					case 65:			//"+" powerup+player
-						if(player1.weaponclass<MAX_WEAPONCLASS)
-							player1.weaponclass++;
-						destroy(i,j,bullets,bombs,enemies,powerups,rockets);
-						break;
-					case 68:			//"+" powerup+enemy
-					case 72:			//"+" powerup+bomb
-					case 80:			//"+" powerup+boss
-					case 132:			//"-" powerup+enemy [etc.]
-					case 136:
-					case 144:
-					case 516:			//"X" powerup+enemy [etc.]
-					case 520:
-					case 528:
-						destroy(i,j,bullets,bombs,enemies,powerups,rockets);
-						break;
-					case 129:			//"-" powerup+player
-						if(player1.length>2){
-							mvaddch(player1.y,player1.x+player1.length-1,' ');
-							player1.length--;
-						}
-						destroy(i,j,bullets,bombs,enemies,powerups,rockets);
-						break;
-					case 260:			//enemy+rocket
-					case 264:			//bomb+rocket
-						destroy(i,j,bullets,bombs,enemies,powerups,rockets);
-						break;
-					case 513:			//player+"X" powerup
-						player1.rocketlauncher=TRUE;
-						destroy(i,j,bullets,bombs,enemies,powerups,rockets);
-						break;
-				}
-		}
-}
-
-void Box::destroy(int Y, int X, b_list & bullets, b_list& bombs, e_list& enemies, b_list & powerups,r_list& rockets)	 //destroys any bomb/enemy/bullet/powerup/rocket found in matrix[Y][X]
-{
-
-	b_list::iterator it;
-	r_list::iterator itr;
-	
-	if(!bullets.empty()){
-		it=bullets.begin();                         //we could use remove_if() if i could just think of a way...
-		while(it!=bullets.end())
-		{
-			if(it->x==X && it->y==Y)
-			{
-				mvaddch(it->y,it->x,' ');
-				it = bullets.erase(it);
-				break;
-			} else ++it;
-		}
-	}
-
-	if(!rockets.empty()){
-		itr=rockets.begin();                        
-		while(itr!=rockets.end())
-		{
-			if(itr->x==X && itr->y==Y)
-			{
-				mvaddch(itr->y,itr->x,' ');
-				itr = rockets.erase(itr);
-				break;
-			} else ++itr;
-		}
-	}
-
-	if(!bombs.empty()){
-		it=bombs.begin();                         
-		while(it!=bombs.end())
-		{
-			if(it->x==X && it->y==Y)
-			{
-				mvaddch(it->y,it->x,' ');
-				it = bombs.erase(it);
-				break;
-			} else ++it;
-		}
-	}
-		
-	if(!powerups.empty()){
-		it=powerups.begin();            	     
-		while(it!=powerups.end())
-		{
-			if(it->x==X && it->y==Y)
-			{
-				mvaddch(it->y,it->x,' ');
-				it = powerups.erase(it);
-				break;
-			}else ++it;
-		}
-	}
-
-	e_list::const_iterator e_end = enemies.end();
-	
-	for(e_list::iterator it=enemies.begin(); it!=e_end; ++it)	       //this cycle destroys an enemy in X,Y (quite unefficiently?)
-		if(it->x==X && it->y==Y)
-		{
-			it->alive=false;
-			break;
-		}
-}
-
-
-

+ 0 - 40
box.hpp

@@ -1,40 +0,0 @@
-#ifndef _box_
-#define _box_
-
-#include "player.hpp"
-#include "rocket.hpp"
-#include "enemy.hpp" 	
-#include "boss.hpp"
-#include "wall.hpp"
-#include "powerup.hpp"
-#include "definitions.hpp"
-
-using std::cout; using std::endl;
-
-typedef std::list<bullet> b_list;
-typedef std::list<enemy> e_list;
-typedef std::vector<wall> w_vec;
-typedef std::list<rocket> r_list;
-
-class Box
-{
-	
-	public:
-	Box() { clear(); }
-	~Box() {}
-	
-	int matrix[R][C];                                                 		 //the position matrix
-	void refresh(b_list&, b_list&, e_list&, player&, int &score, boss& boss1,w_vec &walls, b_list & powerups,r_list&);  	 //empties, uploads, kills, empties again, uploads again matrix
-	void print();                                                   		  //prints the position matrix
-	void clear();                                                    		 //fills matrix with 0's
-	void destroy(int X, int Y, b_list & bullets, b_list& bombs, e_list& enemies, b_list & powerups,r_list&);     //destroys bullets, bombs and enemies in (X,Y)
-	
-	private:	                                                   
-	void upload(b_list & bullets, b_list& bombs, e_list& enemies, player& player1, boss& boss1,w_vec &walls, b_list & powerups,r_list&);    //fills matrix with objects id's
-	void kill(b_list & bullets, b_list& bombs, e_list& enemies, int &score, boss& spole,w_vec &walls, b_list & powerups, player & player1,r_list&);           //checks where there's something to destroy
-	
-
-};
-
-#endif
-

+ 0 - 77
definitions.hpp.bu

@@ -1,77 +0,0 @@
-#ifndef _definitions_
-#define _definitions_
-
-//MAIN LIBRARIES INCLUDES
-#include <cstdlib>
-#include <ctime>
-#include <fstream>
-#include <sstream>
-#include <algorithm>
-#include <iostream>
-#include <iomanip>
-#include <list>
-#include <vector>
-#include <cmath>
-//#include <unistd.h>
-#include <pthread.h>
-#include <ncurses.h>
-
-//GAME BOX DIMENSIONS
-#define R 30	//rows (Y)
-#define C 60	//columns (X)
-
-//GAME DEFINES
-#define AVERAGE_DROP 2
-#define POWERUP_RATIO 2
-#define ROCKET_RATIO 3
-#define MAX_WEAPONCLASS 5
-#define MAX_WEAPONCLASSRKT 5
-#define MAX_LENGTH 20
-#ifdef R
-#define MAX_WIDTH R
-#endif
-#ifdef C
-#define MAX_HEIGHT C
-#endif
-#define CHEAT_CODE "pinkie"
-#define BOSS_FILE1 "myboss"
-#define BOSS_FILE2 "palombo"
-#define BOSS_FILE3 "maderna"
-#define BOSS_FILE4 "maero"
-#define BOSS_FILE5 "big_alienboss"
-#define PLAYER_SPRITE '='
-#define ENEMY_SPRITE '#'
-#define BULLET_SPRITE '|'
-#define BOMB_SPRITE 'o'
-#define POWERUP1_SPRITE '+'
-#define POWERUP2_SPRITE '-'
-#define POWERUP3_SPRITE 'X'
-#define WALL_SPRITE '@'
-#define ROCKET_SPRITE '^'
-
-//THREAD DEFINES
-#define THREADS_NUM 5
-
-//COLORS
-#define red "\033[31m" 
-#define crimson "\033[1;31m"
-#define magenta "\033[35m" 
-#define violet "\033[1;35m"  
-#define green "\033[32m" 
-#define lightgreen "\033[1;32m" 
-#define blue "\033[34m" 
-#define lightblue "\033[1;34m" 
-#define none "\033[0m" 
-#define yellow "\033[33m" 
-#define orange "\033[1;33m"
-#define cyan "\033[36m"
-#define azure "\033[1;36m"
-#define grey "\e[1;30m"
-#define backred "\033[41m" 
-#define backcyan "\033[46m"
-#define backgreen "\033[1;42m" 
-
-static int ENEMY_NUM=40;
-static int WALLS_NUM;
-	
-#endif

+ 6 - 1
functions.hpp

@@ -3,13 +3,18 @@
 
 //#includes here
 #include "definitions.hpp"
-#include "box.hpp"
 #include "player.hpp"
 #include "bullet.hpp"
+#include "powerup.hpp"
 #include "enemy.hpp"
 #include "wall.hpp"
 #include "boss.hpp"
 
+typedef std::list<bullet> b_list;
+typedef std::list<enemy> e_list;
+typedef std::vector<wall> w_vec;
+typedef std::list<rocket> r_list;
+
 class record
 {
 	public:

+ 0 - 324
invaders_fork.cpp

@@ -1,324 +0,0 @@
-#include "bullet.hpp"
-#include "enemy.hpp"
-#include "player.hpp"
-#include "box.hpp"
-#include "boss.hpp"
-#include "powerup.hpp"
-#include "definitions.hpp"
-#include "functions.hpp"
-#include "wall.hpp"
-
-using std::cout;
-using std::endl; 
-using std::min;
-
-int main()
-{
-	
-  	typedef std::list<bullet> b_list;
-  	typedef std::list<enemy> e_list;
-  	typedef std::vector<wall> w_vec;
-	srand(time(NULL));
-	
-	//OBJECTS INIZIALIZATION
-	Box box1;
-	player player1;						//player is automatically created in [C/2][R]
-	e_list enemies;						//vector of enemies
-	b_list bullets;                				//list of player's bullets
-	b_list bombs;						//list of enemies' bombs
-	b_list powerups;					//list of powerups
-	int refresh_time;          				//how long the program waits before refreshing the screen
-	int chflag=0;						//cheat flag: 0=normal, 1=cheats allowed, 2=special mode activated, 3=both special mode and cheats.
-	boss boss1;
-	WINDOW *Score,*BossHP;
-	
-	//PARAMETERS/UTILITIES
-	double shootrate;				  	//probability of an enemy shooting a bomb 
-	int command;						//keyboard input
-	int score=0;					   	//score: gain +100 when an enemy is destroyed and +50 when a bomb is destroyed
-	char level='1';	
-	bool sound=true;					//difficulty level
-
-
-	//NCURSES STUFF
-	initscr();
-	curs_set(0);
-	noecho();	
-	cbreak();
-	keypad(stdscr,TRUE);
-	start_color();
-	init_pair(0,COLOR_WHITE,COLOR_BLACK);
-	init_pair(1,COLOR_GREEN,COLOR_BLACK);	//PLAYER
-	init_pair(2,COLOR_RED,COLOR_BLACK);	//ENEMY
-	init_pair(3,COLOR_YELLOW,COLOR_BLACK);	//BULLETS-POWERUPS
-	init_pair(4,COLOR_MAGENTA,COLOR_BLACK);	//WALLS
-	init_pair(5,COLOR_CYAN,COLOR_BLACK);	//BOSS
-	init_pair(6,COLOR_BLUE,COLOR_BLACK);	//BOMBS
-	init_pair(7,COLOR_RED,COLOR_RED);
-	init_pair(8,COLOR_GREEN,COLOR_GREEN);
-	
-	//////////PROGRAM START: creation of game objects and set of parameters
-		
-	WALLS_NUM=2;
-	
-	ENEMY_NUM=choose_level(shootrate, refresh_time, boss1, level);     	//choose difficulty level and set game parameters and boss
-	
-	erase();
-	
-	if(atoi(&level)==1) WALLS_NUM=3;
-	
-	w_vec walls(WALLS_NUM);
-	
-	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)
-		it->create((i+1)*(C/(3*WALLS_NUM+1))+i*(2*C/(3*WALLS_NUM+1)),2*R/3,(int)min(6,2*C/(3*WALLS_NUM+1)),2,3);
-
-	box1.refresh(bullets, bombs, enemies, player1, score, boss1, walls, powerups);   //matrix is loaded for the first time
-
-	
-	/////////ENTERING MAIN LOOP
-	
-	int childPID0=fork();
-	if(childPID0==0 && sound){
-		music();
-		return 0;
-	}
-	while(1)
-	{
-		napms(refresh_time);					//ncurses sleep function (ms)
-		timeout(0);
-	    	command = getch();
-	    	              
-	    	if(command!=ERR)                        		//READING INPUT
-	    		command = tolower(command);     
-		    		           
-	    	if(command == 'q'){ 						//q = exit game
-	    		endwin();
-	    		kill_music(childPID0);
-	    		cout<<lightgreen<<"Game exited correctly."<<none<<endl;
-	    		return 1;
-	    	}  
-
-	    	if(command == 'p')
-	    		pause_game(chflag);						//p = pause game
-
-	    	if(chflag==1 || chflag==3){								//cheats
-	    		if(command == '+' && player1.weaponclass<5) player1.weaponclass++;	//increase weaponclass
-	    		if(command == '\\' && player1.weaponclass>1) player1.weaponclass--;	//decrease weaponclass
-	    		if(command == '-' && player1.length>2){					//decrease size
-				mvaddch(player1.y,player1.x+player1.length-1,' ');
-	    			player1.length--;
-	    		}
-	    		if(command == '\'' && player1.length<20) player1.length++;		//increase size
-			if(command == 'n')							//nuke enemies
-				for(e_list::iterator it=enemies.begin();it!=enemies.end();it++){
-					it->alive=false;
-					mvaddch(it->y,it->x,' ');
-				}
-	    	}
-
-	    	if(chflag!=2 && chflag!=3)
-			get_KonamiCode(command,chflag,boss1,enemies,bullets,bombs,powerups,box1);
-			    
-	    	if(command == 'a' || command == KEY_LEFT || command == 'd' || command == KEY_RIGHT ||
-		((command == 'w'|| command == KEY_UP || command == 's' || command == KEY_DOWN) &&
-		(chflag==1 || chflag==3))){   	//a or d = move player (if cheats are triggered, also w and s)
-	    		for(int i=player1.x;i<player1.x+player1.length;i++) mvaddch(player1.y,i,' ');	
-	    		player1.next_pos(command);	
-	    	}	    
-		    		
-		if(command==' '){                		//spacebar = shoot!
-			if(sound){
-				int childPID=fork();
-				if(childPID==0){
-					system("beep -f 1000 -l 30 -n -f 850 -l 30");
-					return 0;
-				}
-			}
-			player1.shoot(bullets);
-		}
-		
-		if(command=='m'){				//mute/unmute
-			if(sound) kill_music(childPID0);
-			else{
-				childPID0=fork();
-				if(childPID0==0){
-					music();
-					return 0;
-				}
-			}
-			sound=!sound;
-		}
-		
-		if(enemyalive(enemies))					//if there's at least one enemy alive:
-		{
-			int n_enemies=0;
-			e_list::const_iterator e_end = enemies.end();
-			
-			for(e_list::iterator it=enemies.begin(); it!=e_end; ++it)
-				if(it->alive) n_enemies++;				//counts alive enemies
-		
-			for(e_list::iterator it=enemies.begin(); it!=e_end; ++it)         
-			{
-				mvaddch(it->y,it->x,' ');
-				it->next_pos();                                        //evaluate new positions
-				if(it->alive && (double)rand()/RAND_MAX<(shootrate*ENEMY_NUM/n_enemies)){     //try a bomb-dropping
-						if(sound){
-							int childPID=fork();
-							if(childPID==0){
-								system("beep -f 1500 -l 30 -n -f 1000 -l 30");
-								return 0;
-							}
-						}
-						it->shoot(bombs);
-				}
-			}
-		}
-		else boss1.alive = true;					//if no enemy is alive, boss spawns
-				
-		if(boss1.alive)							//if boss is alive, moves and shoots
-		{
-			for(int i=0;i<boss1.width;i++) mvaddch(boss1.y,boss1.x+i,' ');
-			for(int j=0;j<boss1.height;j++){
-				mvaddch(boss1.y+j,boss1.x,' ');
-				mvaddch(boss1.y+j,boss1.x+boss1.width-1,' ');
-			}
-			boss1.next_pos();
-			if((double)rand()/RAND_MAX<shootrate*25.){		//boss's shootrate is 25 times the one of normal enemies
-				if(sound){
-					int childPID=fork();
-					if(childPID==0){
-						system("beep -f 1500 -l 30 -n -f 1000 -l 30");
-						return 0;
-					}
-				}
-				boss1.shoot(bombs);	
-			}
-		}
-		
-		if(!bullets.empty())						//evaluate new bullets' positions
-			for(b_list::iterator it=bullets.begin(); it!=bullets.end(); ++it){
-				mvaddch(it->y,it->x,' ');
-				it->next_pos();
-			}
-				
-		bullets.unique();      					//remove duplicates of bullets (i.e. player can't shoot enemies)
-
-		if(!bombs.empty())						//evaluate new bombs' positions
-			for(b_list::iterator it=bombs.begin(); it!=bombs.end(); ++it){
-				mvaddch(it->y,it->x,' ');
-				it->next_pos();
-			}
-				  	
-		bombs.unique();						//remove duplicates of bombs
-
-		if(!powerups.empty())						//new powerups' positions
-			for(b_list::iterator it=powerups.begin(); it!=powerups.end(); ++it){
-				mvaddch(it->y,it->x,' ');
-				it->next_pos();
-			}
-				
-		powerups.unique(); 	 //FIXME: THIS ONLY WORKS ON CONSECUTIVE ELEMENTS OF THE LIST!! we should at least sort powerups before calling unique()
-		
-		box1.refresh(bullets, bombs, enemies, player1, score, boss1, walls, powerups);		
-
-		///////ENDGAME CHECKS               
-		if(boss1.health<1)  					//YOU WON!!
-		{
-			if(sound){
-				kill_music(childPID0);
-				int childPID=fork();
-				if(childPID==0){
-					system("beep -f 1000 -l 150 -n -f 800 -l 150 -n -f 1000 -l 150 -n -f 1500 -l 600");
-					return 0;
-				}
-			}
-				
-			Victory(boss1.name,score,level,chflag);
-			
-			WINDOW *replay;
-			
-			replay=newwin(3,25,26,20);
-			box(replay,ACS_VLINE,ACS_HLINE);
-		
-			if(playagain(replay))                           //playagain() returns true if player wants to play again, false otherwise
-			{
-				delwin(replay);
-				timeout(500);
-				score=0;
-				erase();
-				refresh();
-				choose_level(shootrate, refresh_time, boss1, level);
-				reset(box1, player1, enemies, boss1, bullets, bombs, walls, powerups, level,chflag); // reset box, player, enemy and deletes all bullets and bombs
-				erase();
-				refresh();
-				continue;  
-			}
-			else { 
-				endwin();
-				cout<<lightgreen<<"Game exited correctly."<<none<<endl;
-				return 0;
-			}	
-		}
-				
-			
-		if(gameover(box1,player1))
-		{	
-			if(sound){	
-				kill_music(childPID0);
-				int childPID=fork();
-				if(childPID==0){
-					system("beep -f 700 -l 150 -n -f 585 -l 150 -n -f 550 -l 150 -n -f 520 -l 600");
-					return 0;
-				}
-			}
-				
-			Defeat(score);
-			
-			WINDOW* replay;
-		
-			replay=newwin(3,25,17,20);
-			box(replay,ACS_VLINE,ACS_HLINE);
-			
-			if(playagain(replay))                                        //playagain() returns true if player wants to play again, false otherwise
-			{
-				delwin(replay);
-				timeout(500);
-				score=0;
-				erase();
-				refresh();
-				choose_level(shootrate, refresh_time, boss1, level);
-				reset(box1, player1, enemies, boss1, bullets, bombs, walls, powerups, level,chflag);       // reset box, player, enemy and delete all bullets and bombs
-				erase();
-				refresh();
-				continue;  
-			}
-			else { 
-				endwin();
-				cout<<lightgreen<<"Game exited correctly."<<none<<endl;
-				return 0;
-			}		
-		}
-		
-		write_score(Score,score);
-	
-		if(boss1.alive){
-			write_bosshp(BossHP,boss1.health,boss1.healthmax,boss1.name);
-			wrefresh(BossHP);
-		}
-		
-		wrefresh(Score);
-		refresh();
-	}  
-////////END OF MAIN LOOP
-
-	endwin();
-	
-	return -1;  //program never really reaches here, but compiler is happy
-}
-
-

+ 4 - 7
makefile

@@ -19,22 +19,19 @@ OPTIONS := $(CURSES) $(THREADS)
 
 #TARGETS
 
-all: invaders #bossrush
+all: invaders bossrush
 
 invaders: game_object.o bullet.o enemy.o player.o functions.o pic.o body.o boss.o wall.o powerup.o rocket.o invaders.o
 	$(CXX) $(CXX_FLAGS) $^ -o $@ $(OPTIONS)
 bossrush: game_object.o bullet.o enemy.o player.o functions.o pic.o body.o boss.o wall.o powerup.o rocket.o bossrush.o
 	$(CXX) $(CXX_FLAGS) $^ -o $@ $(OPTIONS) 
 
-invaders.o: invaders.cpp bullet.hpp enemy.hpp player.hpp box.hpp rocket.hpp definitions.hpp functions.hpp
+invaders.o: invaders.cpp bullet.hpp enemy.hpp player.hpp rocket.hpp definitions.hpp functions.hpp
 	$(CXX) $(CXX_FLAGS) -c $<
 	
-bossrush.o: bossrush.cpp bullet.hpp enemy.hpp player.hpp box.hpp rocket.hpp definitions.hpp functions.hpp
+bossrush.o: bossrush.cpp bullet.hpp enemy.hpp player.hpp rocket.hpp definitions.hpp functions.hpp
 	$(CXX) $(CXX_FLAGS) -c $<
 
-#box.o: box.cpp box.hpp definitions.hpp player.hpp rocket.hpp bullet.hpp enemy.hpp boss.hpp
-#	$(CXX) $(CXX_FLAGS) -c $<
-
 game_object.o: game_object.cpp game_object.hpp
 	$(CXX) $(CXX_FLAGS) -c $<
 
@@ -47,7 +44,7 @@ enemy.o: enemy.cpp enemy.hpp game_object.hpp bullet.hpp definitions.hpp
 player.o: player.cpp player.hpp game_object.hpp bullet.hpp rocket.hpp definitions.hpp
 	$(CXX) $(CXX_FLAGS) -c $<
 
-functions.o: functions.cpp functions.hpp definitions.hpp box.hpp player.hpp bullet.hpp enemy.hpp wall.hpp boss.hpp
+functions.o: functions.cpp functions.hpp definitions.hpp powerup.hpp player.hpp bullet.hpp enemy.hpp wall.hpp boss.hpp
 	$(CXX) $(CXX_FLAGS) -c $<
 
 body.o: body.cpp body.hpp