enemy.cpp 955 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 "enemy.hpp"
  8. enemy::enemy() : game_object() { id=4; alive=true; direction=0; }
  9. enemy::enemy(int X,int Y) : game_object(X,Y,4) { alive=true; direction=0; }
  10. void enemy::next_pos(){
  11. if( (direction==0 && x==C-1) || (direction==1 && x==0) )
  12. direction=2;
  13. switch (direction){ //assegno a direction un valore 0,1,2
  14. case 0: //0 significa che si sta muovendo verso destra
  15. x++;
  16. break;
  17. case 1: //1 verso sinistra
  18. x--;
  19. break;
  20. case 2: //2 verso il basso (quando incontra la parete).
  21. y++;
  22. break;
  23. }
  24. if(direction==2)
  25. {
  26. if(x==0) direction=0;
  27. else direction=1;
  28. }
  29. }
  30. void enemy::shoot(std::list<bullet> & bombs){ //random bomb-dropping
  31. bullet new_bomb(x,y+1,8);
  32. bombs.push_back(new_bomb);
  33. }