Advertisement
Guest User

Problem Page 2.1

a guest
Jan 31st, 2015
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. import java.awt.Image;
  2. import java.util.ArrayList;
  3. import java.util.Random;
  4.  
  5. import javax.swing.ImageIcon;
  6.  
  7.  
  8. public class Asteroid {
  9. static ArrayList asteroids;
  10.  
  11. int x,y;
  12. Image img;
  13. Random number;
  14. boolean destroyed = false;
  15. int hp=100;
  16.  
  17. public Asteroid(){
  18. ImageIcon asteroidImage = new ImageIcon("Asteroid.png");
  19. img = asteroidImage.getImage();
  20. x=RandomPos.randomPosition(30, 630);
  21. y=RandomPos.randomPosition(-200,0);
  22. destroyed = false;
  23.  
  24.  
  25.  
  26. }
  27.  
  28.  
  29. public void move(){
  30. y+=1;
  31. if(y>500){
  32. y=-100;
  33. }
  34. }
  35.  
  36. public void playerCollision(int playerX,int playerY){
  37. if((playerX-10<=x&&playerX+10>=x)&&(playerY-10<=y&&playerY+10>=y)){
  38. hp-=50;
  39. if(hp==0){
  40. destroyed=true;
  41. }
  42. }
  43. }
  44. public void bulletCollision(int bulletX,int bulletY){
  45. if((bulletX-10<=x&&bulletX+10>=x)&&(bulletY-10<=y&&bulletY+10>=y)){
  46. hp-=50;
  47. if(hp==0){
  48. destroyed=true;
  49. }
  50. }
  51. }
  52.  
  53.  
  54.  
  55.  
  56.  
  57. public static ArrayList getAsteroids() {
  58. return asteroids;
  59. }
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67. public Image getImage() {
  68. return img;
  69. }
  70.  
  71.  
  72. public int getX() {
  73. return x;
  74. }
  75. public void setX(int x) {
  76. this.x = x;
  77. }
  78. public int getY() {
  79. return y;
  80. }
  81. public void setY(int y) {
  82. this.y = y;
  83. }
  84. public boolean isDestroyed() {
  85. return destroyed;
  86. }
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97. public static void main(String[] args){
  98. for (int i = 0; i < 10; i++) {
  99. Asteroid asteroid = new Asteroid();
  100. asteroids.add(asteroid);
  101.  
  102. }
  103. }
  104.  
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement