Use floats for less precision (we don't need doubles).

This commit is contained in:
Nicolás A. Ortega 2016-09-18 16:17:34 +02:00
parent 8551012cac
commit a54d54d993
No known key found for this signature in database
GPG Key ID: 2A5A4F4171C6373C
3 changed files with 50 additions and 46 deletions

View File

@ -11,7 +11,11 @@
<target name="compile" >
<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 name="jar" depends="compile" >

View File

@ -12,45 +12,45 @@ import java.awt.Shape;
public class BaseVectorShape {
private Shape shape;
private boolean alive;
private double x, y;
private double velX, velY;
private double moveAngle, faceAngle;
private float x, y;
private float velX, velY;
private float moveAngle, faceAngle;
// Constructor:
public BaseVectorShape() {
setShape(null);
setAlive(false);
setX(0.0);
setY(0.0);
setVelX(0.0);
setVelY(0.0);
setMoveAngle(0.0);
setFaceAngle(0.0);
setX(0.0f);
setY(0.0f);
setVelX(0.0f);
setVelY(0.0f);
setMoveAngle(0.0f);
setFaceAngle(0.0f);
}
// Accessor methods:
public Shape getShape() { return shape; }
public boolean isAlive() { return alive; }
public double getX() { return x; }
public double getY() { return y; }
public double getVelX() { return velX; }
public double getVelY() { return velY; }
public double getMoveAngle() { return moveAngle; }
public double getFaceAngle() { return faceAngle; }
public float getX() { return x; }
public float getY() { return y; }
public float getVelX() { return velX; }
public float getVelY() { return velY; }
public float getMoveAngle() { return moveAngle; }
public float getFaceAngle() { return faceAngle; }
// Setter methods:
public void setShape(Shape shape) { this.shape = shape; }
public void setAlive(boolean alive) { this.alive = alive; }
public void setX(double x) { this.x = x; }
public void incX(double iX) { this.x += iX; }
public void setY(double y) { this.y = y; }
public void incY(double iY) { this.y += iY; }
public void setVelX(double velX) { this.velX = velX; }
public void incVelX(double iVX) { this.velX += iVX; }
public void setVelY(double velY) { this.velY = velY; }
public void incVelY(double iVY) { this.velY += iVY; }
public void setMoveAngle(double nMA) { this.moveAngle = nMA; }
public void incMoveAngle(double iMA) { this.moveAngle += iMA; }
public void setFaceAngle(double nFA) { this.faceAngle = nFA; }
public void incFaceAngle(double iFA) { this.faceAngle += iFA; }
public void setX(float x) { this.x = x; }
public void incX(float iX) { this.x += iX; }
public void setY(float y) { this.y = y; }
public void incY(float iY) { this.y += iY; }
public void setVelX(float velX) { this.velX = velX; }
public void incVelX(float iVX) { this.velX += iVX; }
public void setVelY(float velY) { this.velY = velY; }
public void incVelY(float iVY) { this.velY += iVY; }
public void setMoveAngle(float nMA) { this.moveAngle = nMA; }
public void incMoveAngle(float iMA) { this.moveAngle += iMA; }
public void setFaceAngle(float nFA) { this.faceAngle = nFA; }
public void incFaceAngle(float iFA) { this.faceAngle += iFA; }
}

View File

@ -20,11 +20,11 @@ public class Ship extends BaseVectorShape {
private boolean turnRight = false;
// Acceleration variables
private double accelerateX;
private double accelerateY;
private float accelerateX;
private float accelerateY;
// Constructor:
public Ship(double nx, double ny) {
public Ship(float nx, float ny) {
setX(nx);
setY(ny);
setShape(new Polygon(shipx, shipy, shipx.length));
@ -35,8 +35,8 @@ public class Ship extends BaseVectorShape {
public void update() {
if(accelerate) {
setMoveAngle(getFaceAngle() - 90);
accelerateX = calcAngleMoveX(getMoveAngle()) * 0.1;
accelerateY = calcAngleMoveY(getMoveAngle()) * 0.1;
accelerateX = calcAngleMoveX(getMoveAngle()) * 0.1f;
accelerateY = calcAngleMoveY(getMoveAngle()) * 0.1f;
incVelX(accelerateX);
incVelY(accelerateY);
} else {
@ -63,19 +63,19 @@ public class Ship extends BaseVectorShape {
return r;
}
public double getAccelX() { return accelerateX; }
public double getAccelY() { return accelerateY; }
public float getAccelX() { return accelerateX; }
public float getAccelY() { return accelerateY; }
// Setter methods:
public void setAccelerate(boolean accel) { this.accelerate = accel; }
public void setAccelX(double aX) { this.accelerateX = aX; }
public void setAccelY(double aY) { this.accelerateY = aY; }
public void incAccelX(double iaX) { this.accelerateX += iaX; }
public void incAccelY(double iaY) { this.accelerateY += iaY; }
public void setAccelX(float aX) { this.accelerateX = aX; }
public void setAccelY(float aY) { this.accelerateY = aY; }
public void incAccelX(float iaX) { this.accelerateX += iaX; }
public void incAccelY(float iaY) { this.accelerateY += iaY; }
public void setTurnLeft(boolean tL) { this.turnLeft = tL; }
public void setTurnRight(boolean tR) { this.turnRight = tR; }
// Methods used for calculations:
public double calcAngleMoveX(double angle) { return (double) (Math.cos(angle * Math.PI / 180)); }
public double calcAngleMoveY(double angle) { return (double) (Math.sin(angle * Math.PI / 180)); }
public float calcAngleMoveX(float angle) { return (float)Math.cos(angle * Math.PI / 180); }
public float calcAngleMoveY(float angle) { return (float)Math.sin(angle * Math.PI / 180); }
}