Skip to content
Snippets Groups Projects
Verified Commit cf4ad40e authored by Jan Kožusznik's avatar Jan Kožusznik
Browse files

Prepare for UI

parent cf0c6b55
No related merge requests found
......@@ -15,7 +15,7 @@ public class BulletAnimated implements DrawableSimulable, Collisionable{
private double mass = 2;
private double strenghtOfCannon = 100;
private double cannonLength = 100;
private boolean accelerate = true;
private boolean accelerate = false;
private boolean hitToGround = false;
private double crossSectionalArea;
......@@ -49,6 +49,9 @@ public class BulletAnimated implements DrawableSimulable, Collisionable{
}
public void simulate(double deltaT) {
if (!accelerate && start == position) {
return;
}
if (accelerate && start.distance(position) < cannonLength) {
double cannonAngle = cannon.getAngle();
speed = speed
......@@ -70,7 +73,8 @@ public class BulletAnimated implements DrawableSimulable, Collisionable{
position = new Point2D(position.getX(), size / 2);
}
} else {
reload();
fire();
}
}
......@@ -90,6 +94,15 @@ public class BulletAnimated implements DrawableSimulable, Collisionable{
position = start;
speed = initialSpeed;
hitToGround = false;
}
public void setCanonPower(double value) {
strenghtOfCannon = value;
}
public void fire() {
reload();
accelerate = true;
}
......
......@@ -7,7 +7,7 @@ import javafx.scene.transform.Affine;
public class Cannon implements DrawableSimulable {
private int direction=-1;
//private int direction=-1;
private double angle = 0;
private Point2D position;
private Point2D size;
......@@ -24,12 +24,13 @@ public class Cannon implements DrawableSimulable {
}
public void simulate(double timeStep) {
angle = angle + direction*0.8;
/*angle = angle + direction*0.8;
if(angle <=-90 || angle >= 0) {
direction*=-1;
}
}*/
}
public void draw(GraphicsContext gc) {
gc.save();
Point2D worldPosition = world.getCanvasPoint(position);
......@@ -46,4 +47,9 @@ public class Cannon implements DrawableSimulable {
public double getAngle() {
return (angle * -1) / 180 * Math.PI;
}
public void setAngle(double value) {
angle = value;
}
}
......@@ -18,6 +18,11 @@ public class GameController {
//Draw scene on a separate thread to avoid blocking UI.
animationTimer = new DrawingThread(canvas, world);
animationTimer.start();
world.setCannonAngle(-45d);
world.setCannonPower(100.);
world.fireBullet();
}
......
......@@ -78,4 +78,29 @@ public class World {
this.height = height;
}
public void setCannonAngle(double value) {
for (DrawableSimulable entity: entities) {
if (entity instanceof Cannon cannon) {
cannon.setAngle(value);
}
}
}
public void setCannonPower(double value) {
for (DrawableSimulable entity: entities) {
if (entity instanceof BulletAnimated bullet) {
bullet.setCanonPower(value);
}
}
}
public void fireBullet() {
for (DrawableSimulable entity: entities) {
if (entity instanceof BulletAnimated bullet) {
bullet.fire();
}
}
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment