Advertisement
Guest User

Space Invaders Time (Ignore)

a guest
Mar 6th, 2015
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. Space[] invader= new Space [50];
  2. float t=0;
  3.  
  4. void setup(){
  5. size(500,500);
  6. for(int i=0; i<50; i=i+1){
  7. invader[i]= new Space();
  8. }
  9. t=0;
  10. }
  11.  
  12. void draw(){
  13. background(0);
  14. for(int i=0; i<50; i=i+1){
  15. invader[i].display();
  16. invader[i].move();
  17. invader[i].caught();
  18. }
  19. textSize(12);
  20. text("Time:"+t,425,500);
  21. t=t+.0167;
  22. }
  23. class Space{
  24. float x;
  25. float y;
  26. float speed;
  27. Space(){
  28. x=random(25/2,975/2);
  29. y=random(-1000,-10);
  30. speed=.8;
  31. }
  32. void move(){
  33. y=y+speed;
  34. }
  35. void display(){
  36. ellipse(x,y,25,25);
  37. }
  38. void caught(){
  39. if(mousePressed==true){
  40. if(mouseX > x-12.5 && mouseX < x+12.5){
  41. if(mouseY > y-12.5 && mouseY < y+12.5){
  42. y=-1000;
  43. x=random(25/2,975/2);
  44. speed=speed+.1;
  45.  
  46. }
  47. }
  48. }
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement