Advertisement
xatzisktv

Untitled

Feb 20th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. package game2;
  2.  
  3. import java.awt.*;
  4. import java.util.Random;
  5.  
  6. import static utilities.Constants.*;
  7.  
  8. public class Asteroid extends GameObject{
  9. public static final int RADIUS = 10;
  10. public static final double MAX_SPEED = 100;
  11.  
  12. private double x, y;
  13. private double vx, vy;
  14.  
  15. public Asteroid(double x, double y, double vx, double vy) {
  16. this.x = x;
  17. this.y = y;
  18. this.vx = vx;
  19. this.vy = vy;
  20. }
  21.  
  22.  
  23. public static Asteroid makeRandomAsteroid() {
  24. Random rand = new Random();
  25. Asteroid x = new Asteroid((rand.nextInt()%FRAME_WIDTH), (rand.nextInt()%FRAME_HEIGHT), (rand.nextInt()%MAX_SPEED), (rand.nextInt()%MAX_SPEED));
  26. return x;
  27. }
  28.  
  29.  
  30. public void update() {
  31. x += vx * DT;
  32. y += vy * DT;
  33. x = (x + FRAME_WIDTH) % FRAME_WIDTH;
  34. y = (y + FRAME_HEIGHT) % FRAME_HEIGHT;
  35. }
  36.  
  37. public void draw(Graphics2D g) {
  38. g.setColor(Color.red);
  39. g.fillOval((int) x - RADIUS, (int) y - RADIUS, 2 * RADIUS, 2 * RADIUS);
  40. }
  41.  
  42. @Override
  43. int radius() {
  44. return 0;
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement