forked from APCSLowell/AsteroidsGame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Asteroids.pde
34 lines (32 loc) · 994 Bytes
/
Asteroids.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import java.util.Map;
import java.util.HashMap;
import java.util.List;
public static Map<Asteroid, Integer> asteroids = new HashMap<Asteroid, Integer>();
public static Map<Bullet, Integer> bullets = new HashMap<Bullet, Integer>();
public void setup() {
size(1000, 600);
strokeWeight(4);
strokeCap(ROUND);
stroke(0xffffffff);
noFill();
textAlign(LEFT, TOP);
}
public void draw() {
background(0);
for (Asteroid a : asteroids.keySet()) a.draw();
for (Bullet b : bullets.keySet()) b.draw();
spaceship.draw();
List<SpaceObject> collidables = new ArrayList<SpaceObject>();
collidables.add(spaceship);
collidables.addAll(bullets.keySet());
collidables.addAll(asteroids.keySet());
for (int a = 0; a < collidables.size()-1; a++) {
for (int b = a+1; b < collidables.size(); b++) {
collidables.get(a).checkCollision(collidables.get(b));
}
}
}
public void keyPressed() {
spaceship.onKeyPressed(key);
if (key == 'x') asteroids.put(new Asteroid(), 0);
}