Advertisement
nawamkihafahd

Untitled

Dec 14th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. package RedHazard;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Graphics;
  5. import java.util.Random;
  6. public class Goal
  7. {
  8. public int x, y, width = 25, height = 25;
  9. public int yspeed;
  10. public Random random;
  11. private Redhazard rh;
  12. public Goal(Redhazard rh)
  13. {
  14. this.rh = rh;
  15. this.random = new Random();
  16. spawn();
  17. }
  18. public void update(Ship ship)
  19. {
  20. y += yspeed;
  21. if(CheckCollision(ship) > 0)
  22. {
  23. if(CheckCollision(ship) == 1)
  24. {
  25. ship.score += 1;
  26. }
  27. spawn();
  28. }
  29. }
  30. public void spawn()
  31. {
  32. this.x = random.nextInt(650);
  33. this.y = 0;
  34. yspeed = random.nextInt(2) + 2;
  35. }
  36. public int CheckCollision(Ship ship)
  37. {
  38. if(this.x + width > ship.x && this.x < ship.x + ship.width && this.y + height > ship.y && this.y < ship.y + ship.height)
  39. {
  40. return 1;
  41. }
  42. if(this.y > Redhazard.rh.height)
  43. {
  44. return 2;
  45. }
  46. return 0;
  47. }
  48. public void render(Graphics g)
  49. {
  50. g.setColor(Color.GREEN);
  51. g.fillRect(x, y, width, height);
  52. }
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement