Use floats for less precision (we don't need doubles).
This commit is contained in:
parent
8551012cac
commit
a54d54d993
14
build.xml
14
build.xml
@ -4,16 +4,20 @@
|
|||||||
<property name="classes.dir" value="${bin.dir}/classes" />
|
<property name="classes.dir" value="${bin.dir}/classes" />
|
||||||
<property name="jar.dir" value="${bin.dir}/jar" />
|
<property name="jar.dir" value="${bin.dir}/jar" />
|
||||||
<property name="main-class" value="spaceshipsim.SpaceShipSim" />
|
<property name="main-class" value="spaceshipsim.SpaceShipSim" />
|
||||||
|
|
||||||
<target name="clean" >
|
<target name="clean" >
|
||||||
<delete dir="bin" />
|
<delete dir="bin" />
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
<target name="compile" >
|
<target name="compile" >
|
||||||
<mkdir dir="${classes.dir}" />
|
<mkdir dir="${classes.dir}" />
|
||||||
<javac includeantruntime="false" srcdir="${src.dir}" destdir="${classes.dir}" />
|
<javac includeantruntime="false" srcdir="${src.dir}" destdir="${classes.dir}" >
|
||||||
|
<!-- Strict compiler -->
|
||||||
|
<!--<compilerarg value="-Xlint:all" />-->
|
||||||
|
<!--<compilerarg value="-Werror" />-->
|
||||||
|
</javac>
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
<target name="jar" depends="compile" >
|
<target name="jar" depends="compile" >
|
||||||
<mkdir dir="${jar.dir}" />
|
<mkdir dir="${jar.dir}" />
|
||||||
<jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}" >
|
<jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}" >
|
||||||
@ -24,7 +28,7 @@
|
|||||||
</target>
|
</target>
|
||||||
|
|
||||||
<target name="main" depends="jar" />
|
<target name="main" depends="jar" />
|
||||||
|
|
||||||
<target name="run" depends="jar" >
|
<target name="run" depends="jar" >
|
||||||
<java jar="${jar.dir}/${ant.project.name}.jar" fork="true" />
|
<java jar="${jar.dir}/${ant.project.name}.jar" fork="true" />
|
||||||
</target>
|
</target>
|
||||||
|
@ -12,45 +12,45 @@ import java.awt.Shape;
|
|||||||
public class BaseVectorShape {
|
public class BaseVectorShape {
|
||||||
private Shape shape;
|
private Shape shape;
|
||||||
private boolean alive;
|
private boolean alive;
|
||||||
private double x, y;
|
private float x, y;
|
||||||
private double velX, velY;
|
private float velX, velY;
|
||||||
private double moveAngle, faceAngle;
|
private float moveAngle, faceAngle;
|
||||||
|
|
||||||
// Constructor:
|
// Constructor:
|
||||||
public BaseVectorShape() {
|
public BaseVectorShape() {
|
||||||
setShape(null);
|
setShape(null);
|
||||||
setAlive(false);
|
setAlive(false);
|
||||||
setX(0.0);
|
setX(0.0f);
|
||||||
setY(0.0);
|
setY(0.0f);
|
||||||
setVelX(0.0);
|
setVelX(0.0f);
|
||||||
setVelY(0.0);
|
setVelY(0.0f);
|
||||||
setMoveAngle(0.0);
|
setMoveAngle(0.0f);
|
||||||
setFaceAngle(0.0);
|
setFaceAngle(0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Accessor methods:
|
// Accessor methods:
|
||||||
public Shape getShape() { return shape; }
|
public Shape getShape() { return shape; }
|
||||||
public boolean isAlive() { return alive; }
|
public boolean isAlive() { return alive; }
|
||||||
public double getX() { return x; }
|
public float getX() { return x; }
|
||||||
public double getY() { return y; }
|
public float getY() { return y; }
|
||||||
public double getVelX() { return velX; }
|
public float getVelX() { return velX; }
|
||||||
public double getVelY() { return velY; }
|
public float getVelY() { return velY; }
|
||||||
public double getMoveAngle() { return moveAngle; }
|
public float getMoveAngle() { return moveAngle; }
|
||||||
public double getFaceAngle() { return faceAngle; }
|
public float getFaceAngle() { return faceAngle; }
|
||||||
|
|
||||||
// Setter methods:
|
// Setter methods:
|
||||||
public void setShape(Shape shape) { this.shape = shape; }
|
public void setShape(Shape shape) { this.shape = shape; }
|
||||||
public void setAlive(boolean alive) { this.alive = alive; }
|
public void setAlive(boolean alive) { this.alive = alive; }
|
||||||
public void setX(double x) { this.x = x; }
|
public void setX(float x) { this.x = x; }
|
||||||
public void incX(double iX) { this.x += iX; }
|
public void incX(float iX) { this.x += iX; }
|
||||||
public void setY(double y) { this.y = y; }
|
public void setY(float y) { this.y = y; }
|
||||||
public void incY(double iY) { this.y += iY; }
|
public void incY(float iY) { this.y += iY; }
|
||||||
public void setVelX(double velX) { this.velX = velX; }
|
public void setVelX(float velX) { this.velX = velX; }
|
||||||
public void incVelX(double iVX) { this.velX += iVX; }
|
public void incVelX(float iVX) { this.velX += iVX; }
|
||||||
public void setVelY(double velY) { this.velY = velY; }
|
public void setVelY(float velY) { this.velY = velY; }
|
||||||
public void incVelY(double iVY) { this.velY += iVY; }
|
public void incVelY(float iVY) { this.velY += iVY; }
|
||||||
public void setMoveAngle(double nMA) { this.moveAngle = nMA; }
|
public void setMoveAngle(float nMA) { this.moveAngle = nMA; }
|
||||||
public void incMoveAngle(double iMA) { this.moveAngle += iMA; }
|
public void incMoveAngle(float iMA) { this.moveAngle += iMA; }
|
||||||
public void setFaceAngle(double nFA) { this.faceAngle = nFA; }
|
public void setFaceAngle(float nFA) { this.faceAngle = nFA; }
|
||||||
public void incFaceAngle(double iFA) { this.faceAngle += iFA; }
|
public void incFaceAngle(float iFA) { this.faceAngle += iFA; }
|
||||||
}
|
}
|
||||||
|
@ -20,11 +20,11 @@ public class Ship extends BaseVectorShape {
|
|||||||
private boolean turnRight = false;
|
private boolean turnRight = false;
|
||||||
|
|
||||||
// Acceleration variables
|
// Acceleration variables
|
||||||
private double accelerateX;
|
private float accelerateX;
|
||||||
private double accelerateY;
|
private float accelerateY;
|
||||||
|
|
||||||
// Constructor:
|
// Constructor:
|
||||||
public Ship(double nx, double ny) {
|
public Ship(float nx, float ny) {
|
||||||
setX(nx);
|
setX(nx);
|
||||||
setY(ny);
|
setY(ny);
|
||||||
setShape(new Polygon(shipx, shipy, shipx.length));
|
setShape(new Polygon(shipx, shipy, shipx.length));
|
||||||
@ -35,8 +35,8 @@ public class Ship extends BaseVectorShape {
|
|||||||
public void update() {
|
public void update() {
|
||||||
if(accelerate) {
|
if(accelerate) {
|
||||||
setMoveAngle(getFaceAngle() - 90);
|
setMoveAngle(getFaceAngle() - 90);
|
||||||
accelerateX = calcAngleMoveX(getMoveAngle()) * 0.1;
|
accelerateX = calcAngleMoveX(getMoveAngle()) * 0.1f;
|
||||||
accelerateY = calcAngleMoveY(getMoveAngle()) * 0.1;
|
accelerateY = calcAngleMoveY(getMoveAngle()) * 0.1f;
|
||||||
incVelX(accelerateX);
|
incVelX(accelerateX);
|
||||||
incVelY(accelerateY);
|
incVelY(accelerateY);
|
||||||
} else {
|
} else {
|
||||||
@ -63,19 +63,19 @@ public class Ship extends BaseVectorShape {
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getAccelX() { return accelerateX; }
|
public float getAccelX() { return accelerateX; }
|
||||||
public double getAccelY() { return accelerateY; }
|
public float getAccelY() { return accelerateY; }
|
||||||
|
|
||||||
// Setter methods:
|
// Setter methods:
|
||||||
public void setAccelerate(boolean accel) { this.accelerate = accel; }
|
public void setAccelerate(boolean accel) { this.accelerate = accel; }
|
||||||
public void setAccelX(double aX) { this.accelerateX = aX; }
|
public void setAccelX(float aX) { this.accelerateX = aX; }
|
||||||
public void setAccelY(double aY) { this.accelerateY = aY; }
|
public void setAccelY(float aY) { this.accelerateY = aY; }
|
||||||
public void incAccelX(double iaX) { this.accelerateX += iaX; }
|
public void incAccelX(float iaX) { this.accelerateX += iaX; }
|
||||||
public void incAccelY(double iaY) { this.accelerateY += iaY; }
|
public void incAccelY(float iaY) { this.accelerateY += iaY; }
|
||||||
public void setTurnLeft(boolean tL) { this.turnLeft = tL; }
|
public void setTurnLeft(boolean tL) { this.turnLeft = tL; }
|
||||||
public void setTurnRight(boolean tR) { this.turnRight = tR; }
|
public void setTurnRight(boolean tR) { this.turnRight = tR; }
|
||||||
|
|
||||||
// Methods used for calculations:
|
// Methods used for calculations:
|
||||||
public double calcAngleMoveX(double angle) { return (double) (Math.cos(angle * Math.PI / 180)); }
|
public float calcAngleMoveX(float angle) { return (float)Math.cos(angle * Math.PI / 180); }
|
||||||
public double calcAngleMoveY(double angle) { return (double) (Math.sin(angle * Math.PI / 180)); }
|
public float calcAngleMoveY(float angle) { return (float)Math.sin(angle * Math.PI / 180); }
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user