Skip to content

Commit 6f7d5d7

Browse files
committed
yipeee
1 parent aa79983 commit 6f7d5d7

File tree

5 files changed

+24
-18
lines changed

5 files changed

+24
-18
lines changed

Asteroid.pde

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Asteroid extends SpaceObject {
99
}
1010

1111
private Asteroid(float[] loc, double[] components, int mass) {
12-
super(loc, Math.atan(components[1]/components[0]), (float)Math.sqrt(components[0]*components[0]+components[1]*components[1]), mass);
12+
super(loc, Math.atan(components[1]/components[0]) * (components[0]<0&&components[1]<0 ? -1 : 1), (float)Math.sqrt(components[0]*components[0]+components[1]*components[1]), mass);
1313
this.angVel = 0; // yeah not touching that
1414
this.birth = millis();
1515
}
@@ -38,15 +38,15 @@ class Asteroid extends SpaceObject {
3838

3939
protected float getRadius() {return millis()-this.birth > 1000 ? this.getMass()*3 : -1000;}
4040

41-
private static final int mult = 12;
41+
private static final int mult = 16;
4242
public void collide(float[] momentum) {
4343
asteroids.remove(this);
4444
if (this.getMass() < 3) return;
4545
momentum[0] += Math.cos(this.getDir()) * super.vel * this.getMass();
4646
momentum[1] += Math.sin(this.getDir()) * super.vel * this.getMass();
47-
double ratio = Math.random()*mult-(mult/2f);
47+
double ratio = (Math.random()*0.5+0.5)*mult-(mult/2f);
4848
int[] masses = {(int)Math.floor(this.getMass()/2f), (int)Math.ceil(this.getMass()/2f)};
49-
asteroids.add(new Asteroid(super.loc, new double[]{(momentum[0] * ratio)/masses[0], (momentum[1] * ratio)/masses[0]}, masses[0]));
50-
asteroids.add(new Asteroid(super.loc, new double[]{(momentum[0] * (-ratio))/masses[1], (momentum[1] * (-ratio))/masses[1]}, masses[1]));
49+
asteroids.add(new Asteroid(this.getLoc(), new double[]{(momentum[0] * ratio)/masses[0], (momentum[1] * ratio)/masses[0]}, masses[0]));
50+
asteroids.add(new Asteroid(this.getLoc(), new double[]{(momentum[0] * (-ratio))/masses[1], (momentum[1] * (-ratio))/masses[1]}, masses[1]));
5151
}
5252
}

Bullet.pde

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ public class Bullet extends SpaceObject {
33
private long deathTime;
44

55
public Bullet(float[] loc, double dir, float vel) {
6-
super(loc, dir, vel, 0.03f);
6+
super(loc, dir, vel, 0.5f);
77
this.deathTime = millis()+2000;
88
}
99

Floater.pde

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
abstract class SpaceObject {
1+
abstract class SpaceObject {
2+
private static final long c = 10000; // lightspeed
23
private float[] loc;
34
private float vel;
45
private double dir;
@@ -21,7 +22,7 @@ abstract class SpaceObject {
2122
}
2223

2324
protected void update(float dt) {
24-
this.vel = Math.max(0, this.vel);
25+
this.vel = Math.min(Math.max(0, this.vel), c);
2526
double mult = this.vel * dt;
2627
this.dir += this.angVel * dt;
2728
this.loc[0] += Math.cos(dir) * mult;

Spaceship.pde

+13-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
public final Spaceship spaceship = new Spaceship();
22
class Spaceship extends SpaceObject {
33
private float acceleration;
4+
private long invincibility = 0;
45
private long lastTime = -1;
56

67
private Spaceship() {
78
super(new float[]{1000, 500});
89
this.acceleration = 0;
10+
this.invincibility = millis() + 1000;
911
}
1012

1113
protected void update() {
@@ -22,6 +24,8 @@ class Spaceship extends SpaceObject {
2224

2325
public void draw() {
2426
this.update();
27+
long ti = this.invincibility-millis();
28+
if (ti > 0 && ti/75f % 2 < 1) return;
2529
pushMatrix();
2630
translate(super.loc[0], super.loc[1]);
2731
rotate((float)super.dir-HALF_PI);
@@ -32,7 +36,7 @@ class Spaceship extends SpaceObject {
3236
popMatrix();
3337
}
3438

35-
protected float getRadius() {return 4;}
39+
protected float getRadius() {return this.invincibility-millis()>0?0:4;}
3640

3741
public void collide(float[] momentum) { // placeholder for death
3842
super.angVel = 69;
@@ -44,6 +48,14 @@ class Spaceship extends SpaceObject {
4448
bullets.add(new Bullet(this.getLoc(), this.getDir(), this.getVel()+600));
4549
}
4650

51+
public void hyperspeed() {
52+
super.loc = new float[]{(float)Math.random()*displayWidth, (float)Math.random()*displayHeight};
53+
super.vel = 0;
54+
this.angVel = 0;
55+
this.acceleration = 0;
56+
this.invincibility = millis() + 1000;
57+
}
58+
4759
private void onKey(char c, float dt) {
4860
switch (c) {
4961
case 'w':
@@ -59,12 +71,6 @@ class Spaceship extends SpaceObject {
5971
case 'd':
6072
super.angVel += dt*2;
6173
break;
62-
case 'v':
63-
super.loc = new float[]{(float)Math.random()*displayWidth, (float)Math.random()*displayHeight};
64-
this.angVel = 0;
65-
super.vel = 0;
66-
this.acceleration = 0;
67-
break;
6874
}
6975
}
7076

Star.pde

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
class Star //note that this class does NOT extend Floater
2-
{
3-
//your code here
1+
class Star {
2+
43
}

0 commit comments

Comments
 (0)