Your browser does not support the canvas tag.

previous        Show / Hide Source    Download        next
//Meteor Locations: Starting at 70 pixels, 100 pixels distance between each meteor after that
PVector meteorLocation = new PVector (70,-20);
PVector meteorLocation2 = new PVector (170,-20);
PVector meteorLocation3 = new PVector (270,-20);
PVector meteorLocation4 = new PVector (370,-20);

void setup()
{
  size(400, 400);
 
}

void draw() 
{ 
  // DISPLAY

  background(0);

  //SPACESHIP: 1 Circular body with 2 rectangular Rockets and a circular window. 
  //Spaceship Body Location must = Location of Mouse Cursor
  //Spaceship Rockets
  fill(255);
  rectMode(CORNER);
  rect(mouseX +5, mouseY +1, 5, 25);
  rect(mouseX -10, mouseY +1, 5, 25);

  //Spaceship Body
  fill(255);
  ellipse(mouseX, mouseY, 20, 40);

  //Spaceship Window
  fill(0);
  ellipse(mouseX, mouseY -10, 10, 5);

  //METEORS
  //Meteors: Must be grey
  fill(175, 175, 175);
  
  //Meteor Sizes: All must be similar sizes
  ellipse(meteorLocation.x,meteorLocation.y,95, 95);
  ellipse(meteorLocation2.x,meteorLocation2.y,92, 92);
  ellipse(meteorLocation3.x,meteorLocation3.y,94, 94);
  ellipse(meteorLocation4.x,meteorLocation4.y,93, 93);

  //Meteor Speeds: Varying speeds between +3 and +6
  meteorLocation.y = meteorLocation.y + 4;
  meteorLocation2.y = meteorLocation2.y + 6;
  meteorLocation3.y = meteorLocation3.y + 5;
  meteorLocation4.y = meteorLocation4.y + 3;

//Meteor Reset times: Start at 20 pixels above canvas, reset when reaching 20 pixels below canvas
if(meteorLocation.y >= height +20){
  meteorLocation.y = -20;
}
  
if(meteorLocation2.y >= height +20){
  meteorLocation2.y = -20;
} 

if(meteorLocation3.y >= height +20){
  meteorLocation3.y = -20;
}
  
if(meteorLocation4.y >= height +20){
  meteorLocation4.y = -20;
}
  
}