enemy.cpp 750 B

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