Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Space[] invader= new Space [50];
- float t=0;
- void setup(){
- size(500,500);
- for(int i=0; i<50; i=i+1){
- invader[i]= new Space();
- }
- t=0;
- }
- void draw(){
- background(0);
- for(int i=0; i<50; i=i+1){
- invader[i].display();
- invader[i].move();
- invader[i].caught();
- }
- textSize(12);
- text("Time:"+t,425,500);
- t=t+.0167;
- }
- class Space{
- float x;
- float y;
- float speed;
- Space(){
- x=random(25/2,975/2);
- y=random(-1000,-10);
- speed=.8;
- }
- void move(){
- y=y+speed;
- }
- void display(){
- ellipse(x,y,25,25);
- }
- void caught(){
- if(mousePressed==true){
- if(mouseX > x-12.5 && mouseX < x+12.5){
- if(mouseY > y-12.5 && mouseY < y+12.5){
- y=-1000;
- x=random(25/2,975/2);
- speed=speed+.1;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement