#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; kalive){ 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; i0){ 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.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=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[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.weaponclass2){ 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; } }