boss.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #include "boss.hpp"
  2. boss::boss(int x, int y, int life, int w, int h, std::string newname) : enemy(x,y), pic(w,h)
  3. {
  4. name = newname;
  5. health=life;
  6. healthmax=life;
  7. id=16;
  8. alive=false;
  9. }
  10. void boss::next_pos()
  11. {
  12. if((x==0 && direction==1) || (x==C-width-1 && direction==0))
  13. direction=2;
  14. switch(direction){
  15. case 0:
  16. x++;
  17. break;
  18. case 1:
  19. x--;
  20. break;
  21. case 2:
  22. y++;
  23. if(x==0)
  24. direction=0;
  25. else direction=1;
  26. break;
  27. }
  28. }
  29. void boss::set_life(int life){
  30. health=life;
  31. healthmax=life;
  32. }
  33. void boss::shoot(std::list<bullet> & bullets){ //random bomb-dropping
  34. for(std::list<bullet>::reverse_iterator it=bullets.rbegin(); it!=bullets.rend(); ++it)
  35. if((it->x==x+width/3 || it->x==x+2*width/3) && it->y==y+height)
  36. return;
  37. bullet new_bomb(x+width/3,y+height,8);
  38. bullets.push_back(new_bomb);
  39. bullet new_bomb2(x+2*width/3,y+height,8);
  40. bullets.push_back(new_bomb2);
  41. }
  42. boss& boss::operator=(boss& otherboss)
  43. {
  44. x=otherboss.x;
  45. y=otherboss.y;
  46. health=otherboss.health;
  47. healthmax=otherboss.health;
  48. width=otherboss.width;
  49. height=otherboss.height;
  50. name=otherboss.name;
  51. picture = new char* [otherboss.height];
  52. for(int i=0; i<height; ++i)
  53. picture[i] = new char[otherboss.width];
  54. for(int i=0;i<height;i++)
  55. for(int j=0;j<width;j++)
  56. picture[i][j] = otherboss.picture[i][j];
  57. return *this; //just to get rid of the compiler warning
  58. }