|
@@ -759,7 +759,7 @@ void activate_combo(boss& boss1,e_list& enemies,b_list& bullets,b_list& bombs,b_
|
|
|
|
|
|
//=============BOX'S REPLACEMENT FUNCTIONS============================
|
|
|
|
|
|
-void draw(player& player1,b_list& bullets,b_list& bombs,e_list& enemies,w_vec& walls,b_list& powerups,r_list& rockets,boss& boss1, int& refresh_time, bool& keep_drawing,bool& kill_yourself){
|
|
|
+void draw(player& player1,b_list& bullets,b_list& bombs,e_list& enemies,w_vec& walls,b_list& powerups,r_list& rockets,boss& boss1){
|
|
|
|
|
|
struct point
|
|
|
{
|
|
@@ -768,154 +768,132 @@ void draw(player& player1,b_list& bullets,b_list& bombs,e_list& enemies,w_vec& w
|
|
|
int x,y;
|
|
|
};
|
|
|
|
|
|
- std::list<point> bullets_p, enemies_p, bombs_p, powerups_p, rockets_p, walls_p, player_p, boss_p;
|
|
|
-
|
|
|
- printw("STARTED");
|
|
|
- while(!kill_yourself)
|
|
|
- if(keep_drawing)
|
|
|
- {
|
|
|
- //REDRAW BULLETS
|
|
|
- m_bullets.lock();
|
|
|
- for(auto bullet_p: bullets_p)
|
|
|
- mvaddch(bullet_p.y,bullet_p.x,' ');
|
|
|
- bullets_p.clear();
|
|
|
-
|
|
|
- attron(COLOR_PAIR(3));
|
|
|
- for(auto bullet: bullets)
|
|
|
- {
|
|
|
- mvaddch(bullet.y,bullet.x,BULLET_SPRITE);
|
|
|
- bullets_p.push_back(point(bullet.x,bullet.y));
|
|
|
- }
|
|
|
- m_bullets.unlock();
|
|
|
-
|
|
|
- //REDRAW BOMBS
|
|
|
- m_bombs.lock();
|
|
|
- for(auto bomb_p: bombs_p)
|
|
|
- mvaddch(bomb_p.y,bomb_p.x,' ');
|
|
|
- bombs_p.clear();
|
|
|
-
|
|
|
- attron(COLOR_PAIR(6));
|
|
|
- for(auto bomb: bombs)
|
|
|
- {
|
|
|
- //if(bomb.y<R)
|
|
|
- mvaddch(bomb.y,bomb.x,BOMB_SPRITE);
|
|
|
- bombs_p.push_back(point(bomb.x,bomb.y));
|
|
|
- }
|
|
|
- m_bombs.unlock();
|
|
|
-
|
|
|
- //REDRAW ENEMIES
|
|
|
- m_enemies.lock();
|
|
|
- for(auto enemy_p: enemies_p)
|
|
|
- mvaddch(enemy_p.y,enemy_p.x,' ');
|
|
|
- enemies_p.clear();
|
|
|
-
|
|
|
- attron(COLOR_PAIR(2));
|
|
|
- for(auto enemy: enemies)
|
|
|
- {
|
|
|
- if(enemy.alive==true)
|
|
|
- {
|
|
|
- mvaddch(enemy.y,enemy.x,ENEMY_SPRITE);
|
|
|
- enemies_p.push_back(point(enemy.x,enemy.y));
|
|
|
- }
|
|
|
- }
|
|
|
- m_enemies.unlock();
|
|
|
-
|
|
|
- //REDRAW ROCKETS
|
|
|
- m_rockets.lock();
|
|
|
- for(auto rocket_p: rockets_p)
|
|
|
- mvaddch(rocket_p.y,rocket_p.x,' ');
|
|
|
- rockets_p.clear();
|
|
|
-
|
|
|
- attron(COLOR_PAIR(3));
|
|
|
- for(auto rocket: rockets)
|
|
|
- {
|
|
|
- mvaddch(rocket.y,rocket.x,ROCKET_SPRITE);
|
|
|
- rockets_p.push_back(point(rocket.x,rocket.y));
|
|
|
- }
|
|
|
- m_rockets.unlock();
|
|
|
-
|
|
|
-
|
|
|
- //REDRAW POWERUPS
|
|
|
- m_pow.lock();
|
|
|
- for(auto powerup_p: powerups_p)
|
|
|
- mvaddch(powerup_p.y,powerup_p.x,' ');
|
|
|
- powerups_p.clear();
|
|
|
-
|
|
|
- for(auto powerup: powerups){
|
|
|
- if(powerup.id == 64){
|
|
|
- attron(COLOR_PAIR(3));
|
|
|
- mvaddch(powerup.y,powerup.x,POWERUP1_SPRITE);
|
|
|
- }
|
|
|
- else if(powerup.id == 128){
|
|
|
- attron(COLOR_PAIR(1));
|
|
|
- mvaddch(powerup.y,powerup.x,POWERUP2_SPRITE);
|
|
|
- }
|
|
|
- else{
|
|
|
- attron(COLOR_PAIR(4));
|
|
|
- mvaddch(powerup.y,powerup.x,POWERUP3_SPRITE);
|
|
|
- }
|
|
|
- powerups_p.push_back(point(powerup.x,powerup.y));
|
|
|
- }
|
|
|
- m_pow.unlock();
|
|
|
-
|
|
|
- //REDRAW BOSS
|
|
|
- m_boss.lock();
|
|
|
- for(auto boss_point: boss_p)
|
|
|
- mvaddch(boss_point.y,boss_point.x,' ');
|
|
|
- boss_p.clear();
|
|
|
-
|
|
|
- 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]);
|
|
|
- boss_p.push_back(point(j,i));
|
|
|
- }
|
|
|
- m_boss.unlock();
|
|
|
-
|
|
|
-
|
|
|
- //REDRAW PLAYER
|
|
|
- m_player.lock();
|
|
|
- for(auto play_point: player_p)
|
|
|
- mvaddch(play_point.y,play_point.x,' ');
|
|
|
- player_p.clear();
|
|
|
-
|
|
|
- if(player1.godmode) attron(COLOR_PAIR(5));
|
|
|
- else attron(COLOR_PAIR(1));
|
|
|
- for(int i=player1.x;i<player1.x+player1.length;++i)
|
|
|
+ static std::vector<point> bullets_p, enemies_p, bombs_p, powerups_p, rockets_p, walls_p, player_p, boss_p;
|
|
|
+
|
|
|
+ //REDRAW BULLETS
|
|
|
+ for(auto bullet_p: bullets_p)
|
|
|
+ mvaddch(bullet_p.y,bullet_p.x,' ');
|
|
|
+ bullets_p.clear();
|
|
|
+
|
|
|
+ attron(COLOR_PAIR(3));
|
|
|
+ for(auto bullet: bullets)
|
|
|
+ {
|
|
|
+ mvaddch(bullet.y,bullet.x,BULLET_SPRITE);
|
|
|
+ bullets_p.push_back(point(bullet.x,bullet.y));
|
|
|
+ }
|
|
|
+
|
|
|
+ //REDRAW BOMBS
|
|
|
+ for(auto bomb_p: bombs_p)
|
|
|
+ mvaddch(bomb_p.y,bomb_p.x,' ');
|
|
|
+ bombs_p.clear();
|
|
|
+
|
|
|
+ attron(COLOR_PAIR(6));
|
|
|
+ for(auto bomb: bombs)
|
|
|
+ {
|
|
|
+ //if(bomb.y<R)
|
|
|
+ mvaddch(bomb.y,bomb.x,BOMB_SPRITE);
|
|
|
+ bombs_p.push_back(point(bomb.x,bomb.y));
|
|
|
+ }
|
|
|
+
|
|
|
+ //REDRAW ENEMIES
|
|
|
+ for(auto enemy_p: enemies_p)
|
|
|
+ mvaddch(enemy_p.y,enemy_p.x,' ');
|
|
|
+ enemies_p.clear();
|
|
|
+
|
|
|
+ attron(COLOR_PAIR(2));
|
|
|
+ for(auto enemy: enemies)
|
|
|
+ {
|
|
|
+ if(enemy.alive==true)
|
|
|
+ {
|
|
|
+ mvaddch(enemy.y,enemy.x,ENEMY_SPRITE);
|
|
|
+ enemies_p.push_back(point(enemy.x,enemy.y));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //REDRAW ROCKETS
|
|
|
+ for(auto rocket_p: rockets_p)
|
|
|
+ mvaddch(rocket_p.y,rocket_p.x,' ');
|
|
|
+ rockets_p.clear();
|
|
|
+
|
|
|
+ attron(COLOR_PAIR(3));
|
|
|
+ for(auto rocket: rockets)
|
|
|
+ {
|
|
|
+ mvaddch(rocket.y,rocket.x,ROCKET_SPRITE);
|
|
|
+ rockets_p.push_back(point(rocket.x,rocket.y));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //REDRAW POWERUPS
|
|
|
+ for(auto powerup_p: powerups_p)
|
|
|
+ mvaddch(powerup_p.y,powerup_p.x,' ');
|
|
|
+ powerups_p.clear();
|
|
|
+
|
|
|
+ for(auto powerup: powerups){
|
|
|
+ if(powerup.id == 64){
|
|
|
+ attron(COLOR_PAIR(3));
|
|
|
+ mvaddch(powerup.y,powerup.x,POWERUP1_SPRITE);
|
|
|
+ }
|
|
|
+ else if(powerup.id == 128){
|
|
|
+ attron(COLOR_PAIR(1));
|
|
|
+ mvaddch(powerup.y,powerup.x,POWERUP2_SPRITE);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ attron(COLOR_PAIR(4));
|
|
|
+ mvaddch(powerup.y,powerup.x,POWERUP3_SPRITE);
|
|
|
+ }
|
|
|
+ powerups_p.push_back(point(powerup.x,powerup.y));
|
|
|
+ }
|
|
|
+
|
|
|
+ //REDRAW BOSS
|
|
|
+ for(auto boss_point: boss_p)
|
|
|
+ mvaddch(boss_point.y,boss_point.x,' ');
|
|
|
+ boss_p.clear();
|
|
|
+
|
|
|
+ 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]);
|
|
|
+ boss_p.push_back(point(j,i));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //REDRAW PLAYER
|
|
|
+ for(auto play_point: player_p)
|
|
|
+ mvaddch(play_point.y,play_point.x,' ');
|
|
|
+ player_p.clear();
|
|
|
+
|
|
|
+ if(player1.godmode) attron(COLOR_PAIR(5));
|
|
|
+ else attron(COLOR_PAIR(1));
|
|
|
+ for(int i=player1.x;i<player1.x+player1.length;++i)
|
|
|
+ {
|
|
|
+ mvaddch(player1.y,i,PLAYER_SPRITE);
|
|
|
+ player_p.push_back(point(i,player1.y));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //REDRAW WALLS
|
|
|
+ for(auto wall_p: walls_p)
|
|
|
+ mvaddch(wall_p.y,wall_p.x,' ');
|
|
|
+ walls_p.clear();
|
|
|
+
|
|
|
+ for(int i=0;i<walls.size();i++)
|
|
|
+ for(int k=0;k<walls[i].width;k++)
|
|
|
+ for(int j=0;j<walls[i].height;j++){
|
|
|
+ if(walls[i].health[j][k]==1) attron(COLOR_PAIR(2));
|
|
|
+ else attron(COLOR_PAIR(4));
|
|
|
+ if(walls[i].health[j][k]>0)
|
|
|
{
|
|
|
- mvaddch(player1.y,i,PLAYER_SPRITE);
|
|
|
- player_p.push_back(point(i,player1.y));
|
|
|
+ mvaddch(j+walls[i].y,k+walls[i].x,WALL_SPRITE);
|
|
|
+ walls_p.push_back(point(k+walls[i].x,j+walls[i].y));
|
|
|
}
|
|
|
- m_player.unlock();
|
|
|
-
|
|
|
-
|
|
|
- //REDRAW WALLS
|
|
|
- m_walls.lock();
|
|
|
- for(auto wall_p: walls_p)
|
|
|
- mvaddch(wall_p.y,wall_p.x,' ');
|
|
|
- walls_p.clear();
|
|
|
-
|
|
|
- for(int i=0;i<walls.size();i++)
|
|
|
- for(int k=0;k<walls[i].width;k++)
|
|
|
- for(int j=0;j<walls[i].height;j++){
|
|
|
- if(walls[i].health[j][k]==1) attron(COLOR_PAIR(2));
|
|
|
- else attron(COLOR_PAIR(4));
|
|
|
- if(walls[i].health[j][k]>0)
|
|
|
- {
|
|
|
- mvaddch(j+walls[i].y,k+walls[i].x,WALL_SPRITE);
|
|
|
- walls_p.push_back(point(k+walls[i].x,j+walls[i].y));
|
|
|
- }
|
|
|
- }
|
|
|
- m_walls.unlock();
|
|
|
-
|
|
|
- napms(refresh_time/2);
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|
|
@@ -941,7 +919,6 @@ void drop_powerup(int x,int y,b_list& powerups)
|
|
|
void interactions(player& player1,b_list& bullets,b_list& bombs,e_list& enemies,w_vec& walls,b_list& powerups,r_list& rockets,boss& boss1,int& score){
|
|
|
bool should_continue;
|
|
|
|
|
|
- m_bullets.lock();
|
|
|
b_list::iterator it1=bullets.begin();
|
|
|
while(it1!=bullets.end())
|
|
|
{
|
|
@@ -953,7 +930,6 @@ void interactions(player& player1,b_list& bullets,b_list& bombs,e_list& enemies,
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- m_bombs.lock();
|
|
|
b_list::iterator it2 = bombs.begin();
|
|
|
while(it2!=bombs.end())
|
|
|
{
|
|
@@ -967,10 +943,8 @@ void interactions(player& player1,b_list& bullets,b_list& bombs,e_list& enemies,
|
|
|
else
|
|
|
++it2;
|
|
|
}
|
|
|
- m_bombs.unlock();
|
|
|
if(should_continue) continue;
|
|
|
|
|
|
- m_enemies.lock();
|
|
|
for(e_list::iterator it3=enemies.begin(); it3!=enemies.end(); ++it3)
|
|
|
if(it1->x==it3->x && it1->y==it3->y && it3->alive){ //bullet+enemy
|
|
|
it1=bullets.erase(it1);
|
|
@@ -981,30 +955,24 @@ void interactions(player& player1,b_list& bullets,b_list& bombs,e_list& enemies,
|
|
|
score+=100;
|
|
|
break;
|
|
|
}
|
|
|
- m_enemies.unlock();
|
|
|
if(should_continue) continue;
|
|
|
|
|
|
|
|
|
|
|
|
- m_boss.lock();
|
|
|
if((it1->x>=boss1.x+boss1.width/2-2 && it1->x<=boss1.x+boss1.width/2+2) && boss1.alive){ //bullet+boss
|
|
|
boss1.health--;
|
|
|
if(it1->y==boss1.y) it1=bullets.erase(it1); //bullet gets destroyed only when has reached boss's top
|
|
|
else
|
|
|
{
|
|
|
++it1;
|
|
|
- m_boss.unlock();
|
|
|
continue;
|
|
|
}
|
|
|
//(to make the boss lose life more quickly)
|
|
|
}
|
|
|
- m_boss.unlock();
|
|
|
|
|
|
++it1;
|
|
|
}
|
|
|
- m_bullets.unlock();
|
|
|
|
|
|
- m_rockets.lock();
|
|
|
r_list::iterator itr=rockets.begin();
|
|
|
while(itr != rockets.end())
|
|
|
{
|
|
@@ -1016,7 +984,6 @@ void interactions(player& player1,b_list& bullets,b_list& bombs,e_list& enemies,
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- m_bombs.lock();
|
|
|
b_list::iterator it2=bombs.begin(); //bomb+rocket
|
|
|
while(it2!=bombs.end())
|
|
|
{
|
|
@@ -1030,10 +997,8 @@ void interactions(player& player1,b_list& bullets,b_list& bombs,e_list& enemies,
|
|
|
else
|
|
|
++it2;
|
|
|
}
|
|
|
- m_bombs.unlock();
|
|
|
if(should_continue) continue;
|
|
|
|
|
|
- m_enemies.lock();
|
|
|
e_list::iterator it3 = enemies.begin();
|
|
|
while(it3!=enemies.end())
|
|
|
{
|
|
@@ -1046,27 +1011,21 @@ void interactions(player& player1,b_list& bullets,b_list& bombs,e_list& enemies,
|
|
|
else
|
|
|
++it3;
|
|
|
}
|
|
|
- m_enemies.unlock();
|
|
|
if(should_continue) continue;
|
|
|
|
|
|
- m_boss.lock();
|
|
|
if((itr->x>=boss1.x+boss1.width/2-2 && itr->x<=boss1.x+boss1.width/2+2) && boss1.alive) //rocket+boss
|
|
|
{
|
|
|
boss1.health--;
|
|
|
if(itr->y==boss1.y)
|
|
|
{
|
|
|
itr=rockets.erase(itr);
|
|
|
- m_boss.unlock();
|
|
|
continue;
|
|
|
}
|
|
|
}
|
|
|
- m_boss.unlock();
|
|
|
|
|
|
++itr;
|
|
|
}
|
|
|
- m_rockets.unlock();
|
|
|
|
|
|
- m_bombs.lock();
|
|
|
b_list::iterator itb=bombs.begin();
|
|
|
while(itb!=bombs.end()){
|
|
|
if(itb->y>=R) //bomb reached the floor
|
|
@@ -1083,10 +1042,7 @@ void interactions(player& player1,b_list& bullets,b_list& bombs,e_list& enemies,
|
|
|
|
|
|
++itb;
|
|
|
}
|
|
|
- m_bombs.unlock();
|
|
|
|
|
|
- m_pow.lock();
|
|
|
- m_player.lock();
|
|
|
b_list::iterator itp=powerups.begin();
|
|
|
while( itp!=powerups.end()){
|
|
|
if(itp->y==player1.y && itp->x>=player1.x && itp->x<player1.x+player1.length){
|
|
@@ -1117,17 +1073,13 @@ void interactions(player& player1,b_list& bullets,b_list& bombs,e_list& enemies,
|
|
|
|
|
|
++itp;
|
|
|
}
|
|
|
- m_pow.unlock();
|
|
|
- m_player.unlock();
|
|
|
|
|
|
- m_walls.lock();
|
|
|
for(int i=0;i<walls.size();i++)
|
|
|
for(int j=0;j<walls[i].width;j++)
|
|
|
for(int k=0;k<walls[i].height;k++)
|
|
|
{
|
|
|
if(walls[i].health[k][j]>0)
|
|
|
{
|
|
|
- m_bullets.lock();
|
|
|
b_list::iterator it1=bullets.begin();
|
|
|
while(it1!=bullets.end())
|
|
|
{
|
|
@@ -1138,9 +1090,7 @@ void interactions(player& player1,b_list& bullets,b_list& bombs,e_list& enemies,
|
|
|
else
|
|
|
++it1;
|
|
|
}
|
|
|
- m_bullets.unlock();
|
|
|
|
|
|
- m_bombs.lock();
|
|
|
b_list::iterator it2=bombs.begin();
|
|
|
while(it2!=bombs.end())
|
|
|
{
|
|
@@ -1151,9 +1101,7 @@ void interactions(player& player1,b_list& bullets,b_list& bombs,e_list& enemies,
|
|
|
else
|
|
|
++it2;
|
|
|
}
|
|
|
- m_bombs.unlock();
|
|
|
|
|
|
- m_rockets.lock();
|
|
|
r_list::iterator it3=rockets.begin();
|
|
|
while(it3!=rockets.end())
|
|
|
{
|
|
@@ -1164,9 +1112,7 @@ void interactions(player& player1,b_list& bullets,b_list& bombs,e_list& enemies,
|
|
|
else
|
|
|
++it3;
|
|
|
}
|
|
|
- m_rockets.unlock();
|
|
|
|
|
|
- m_pow.lock();
|
|
|
b_list::iterator it4=powerups.begin();
|
|
|
while(it4!=powerups.end())
|
|
|
{
|
|
@@ -1176,10 +1122,8 @@ void interactions(player& player1,b_list& bullets,b_list& bombs,e_list& enemies,
|
|
|
else
|
|
|
++it4;
|
|
|
}
|
|
|
- m_pow.unlock();
|
|
|
}
|
|
|
}
|
|
|
- m_walls.unlock();
|
|
|
}
|
|
|
|
|
|
|