boss.cpp 1.6 KB

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