#include "definitions.hpp" #include "rocket.hpp" #include "enemy.hpp" #include "player.hpp" #include "boss.hpp" #include "powerup.hpp" #include "functions.hpp" #include "wall.hpp" #include #include std::mutex m_player; std::mutex m_enemies; std::mutex m_bombs; std::mutex m_bullets; std::mutex m_rockets; std::mutex m_pow; std::mutex m_boss; std::mutex m_walls; using std::cout; using std::endl; using std::min; using std::max; int ENEMY_NUM=1; // This variable isn't used, but we have to define it since it is decleared in definitions.hpp" int main(int argc,char** argv) { if(argc>1){ if(strcmp(argv[1],"--uber-debug")!=0 && strcmp(argv[1],"--info")!=0){ cout<<"Usage: "< b_list; typedef std::vector w_vec; typedef std::list r_list; srand(time(NULL)); //OBJECTS INIZIALIZATION player player1; //player is automatically created in [C/2][R] boss bosses[5]; //vector of bosses b_list bullets; //list of player's bullets b_list bombs; //list of enemies' bombs b_list powerups; //list of powerups r_list rockets; //list of rockets boss boss1; std::list enemies; int refresh_time=100; //how long the program waits before refreshing the screen int chflag=0; //cheat flag: 0=normal, 1=cheats allowed. int num=0; int commands[CMD_NUM]={'a','d','w','s','p',' ','l','m','q'}; 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 int level=1; //difficulty level create_std_bosses(); std::string bossname1=getenv("HOME"); bossname1=bossname1+RECORD_DIR+BOSS_FILE1+".dat"; boss newboss1(1,1,100,9,6,BOSS_FILE1); newboss1.loadpicture(bossname1.c_str()); std::string bossname2=getenv("HOME"); bossname2=bossname2+RECORD_DIR+BOSS_FILE2+".dat"; boss newboss2(1,1,200,11,5,BOSS_FILE2); newboss2.loadpicture(bossname2.c_str()); std::string bossname3=getenv("HOME"); bossname3=bossname3+RECORD_DIR+BOSS_FILE3+".dat"; boss newboss3(1,1,300,9,6,BOSS_FILE3); newboss3.loadpicture(bossname3.c_str()); std::string bossname4=getenv("HOME"); bossname4=bossname4+RECORD_DIR+BOSS_FILE4+".dat"; boss newboss4(1,1,400,11,6,BOSS_FILE4); newboss4.loadpicture(bossname4.c_str()); std::string bossname5=getenv("HOME"); bossname5=bossname5+RECORD_DIR+BOSS_FILE5+".dat"; boss newboss5(1,1,500,17,5,BOSS_FILE5); newboss5.loadpicture(bossname5.c_str()); bosses[0]=newboss1; bosses[1]=newboss2; bosses[2]=newboss3; bosses[3]=newboss4; bosses[4]=newboss5; boss1=bosses[0]; boss1.alive=true; player1.weaponclass=1; //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); init_pair(9,COLOR_BLACK,COLOR_GREEN); 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); 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); level = choose_level_bossrush(commands); setup_level_bossrush(level, shootrate, refresh_time); player1.set_commands(commands); if(level<3) player1.weaponclass=2; erase(); if(argc>1) if(strcmp(argv[1],"--uber-debug")==0){ player1.weaponclass=5; player1.weaponclassrkt=5; player1.rocketlauncher=true; player1.length=MAX_LENGTH; } std::thread t_draw(draw,std::ref(player1),std::ref(bullets),std::ref(bombs),std::ref(enemies),std::ref(walls),std::ref(powerups),std::ref(rockets),std::ref(boss1)); /////////ENTERING MAIN LOOP while(1) { napms(refresh_time); //ncurses sleep function (ms) timeout(0); command = getch(); if(command!=ERR) //READING INPUT command = tolower(command); if(command == commands[8]){ //q = exit game endwin(); cout<y,it->x,' '); it->next_pos(); } bullets.unique(); //remove duplicates of bullets (i.e. player can't shoot enemies) if(!rockets.empty()) //evaluate new bullets' positions for(r_list::iterator it=rockets.begin(); it!=rockets.end(); ++it){ mvaddch(it->y,it->x,' '); it->next_pos(); } rockets.unique(); 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() interactions(player1,bullets,bombs,enemies,walls,powerups,rockets,boss1,score); if(boss1.health<=0) if(num<4){ score+=250*level*(num+1); for(int i=max(0,boss1.y-1);i