Skip to content

Instantly share code, notes, and snippets.

@medecau
Created April 26, 2011 18:34
Show Gist options
  • Save medecau/942818 to your computer and use it in GitHub Desktop.
Save medecau/942818 to your computer and use it in GitHub Desktop.
Earth Savers
int position, speed, health, pSize;
int asteroidInterval, asteroidCounter;
ArrayList asteroids, bullets;
void setup(){
size(400,600);
smooth();
// SET UP PLAYER VALUES
position = width/2;
speed = 5;
health = 100;
pSize = 20;
asteroids=new ArrayList();
asteroidCounter=0;
asteroidInterval=1500;
}
void draw(){
background(63);
text(millis()/1000,20,20);
// ASTEROID CONTROL CENTER :)
if (asteroids.size()<10 && millis()/asteroidInterval>asteroidCounter){
asteroids.add(new Asteroid(int(random(0,width))));
asteroidCounter+=1;
}
for (int i=0;i<asteroids.size();i++){
Asteroid a=(Asteroid)asteroids.get(i);
if (a.y-a.aSize>height)
asteroids.remove(i);
a.tick();
a.draw();
}
// MAKE CHANGES TO THE PLAYER
if (keyPressed){
if (keyCode == LEFT){
if (position-speed>=0)
position-=speed;
}
if (keyCode == RIGHT){
if (position+speed<=width)
position+=speed;
}
}
// DRAW PLAYER
rect(position-pSize/2, height-pSize,pSize,pSize);
}
class Asteroid{
int x,y,aSize;
Asteroid(int initPos){
aSize=10;
x=initPos;
y=0-aSize;
}
void tick(){
y+=3;
}
void draw(){
ellipse(x,y,aSize,aSize);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment