Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-pages #13

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 52 additions & 3 deletions AsteroidsGame.pde
Original file line number Diff line number Diff line change
@@ -1,10 +1,59 @@
//your variable declarations here
Spaceship m = new Spaceship();
ArrayList <Asteroid> asteroids = new ArrayList <Asteroid>();


public void setup()
{
//your code here
for(int i = 0; i < 8; i++){
asteroids.add(new Asteroid());
}
size(500, 500);
background(150);
}
public void draw()
{
//your code here
background(0);
m.show();
m.myCenterX = m.myCenterX + m.myXspeed;
m.myCenterY = m.myCenterY + m.myYspeed;
if(m.myCenterX > 500){
m.myCenterX = 0;
}
if(m.myCenterX < 0){
m.myCenterX = 500;
}
if(m.myCenterY > 500){
m.myCenterY = 0;
}
if(m.myCenterY < 0){
m.myCenterY = 500;
}
for(int i = 0; i < asteroids.size(); i++){
Asteroid a = asteroids.get(i);
a.show();
a.move();
if(dist((float)a.getCenterX(), (float)a.getCenterY(), (float)m.myCenterX, (float)m.myCenterY) < 20){
asteroids.remove(i);
}
}
}
public void keyPressed(){
if(key == 'a'){
m.myPointDirection = m.myPointDirection - 15;
}
if(key == 'd'){
m.myPointDirection = m.myPointDirection + 15;
}
if(key == 'w'){
m.myXspeed = m.myXspeed + 0.3*Math.cos(m.myPointDirection*Math.PI/180);
m.myYspeed = m.myYspeed + 0.3*Math.sin(m.myPointDirection*Math.PI/180);
}
if(key == 'f'){
m.myXspeed = 0;
m.myYspeed = 0;
m.myCenterX = (Math.random()*500);
m.myCenterY = (Math.random()*500);
}

}

4 changes: 2 additions & 2 deletions Floater.pde
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Floater //Do NOT modify the Floater class! Make changes in the Spaceship c
}
}
public void show () //Draws the floater at the current position
{
{
fill(myColor);
stroke(myColor);

Expand All @@ -73,4 +73,4 @@ class Floater //Do NOT modify the Floater class! Make changes in the Spaceship c
rotate(-1*dRadians);
translate(-1*(float)myCenterX, -1*(float)myCenterY);
}
}
}
Loading