Skip to content
Snippets Groups Projects
Commit 5ee57b7e authored by koz01's avatar koz01
Browse files

fix speed of Cannon

parent 555cdf03
Branches
No related merge requests found
......@@ -13,7 +13,7 @@ public class Cannon {
private Point2D size;
private World world;
private final double speed = 20;
public Cannon(World world, Point2D position, Point2D size) {
......@@ -24,7 +24,7 @@ public class Cannon {
}
public void simulate(double timeStep) {
angle = angle + direction*0.8;
angle = angle + direction*speed*timeStep;
if(angle <=-90 || angle >= 0) {
direction*=-1;
}
......
package lab;
import javafx.geometry.Point2D;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.image.Image;
public class Dragon {
private static final int SIZE_OF_DRAGON = 50;
private final World world;
private Point2D position;
private final Point2D velocity;
private final Point2D dimension;
private final Image image;
public Dragon(World world, Point2D position, Point2D velocity) {
this(world, position, velocity, new Point2D(SIZE_OF_DRAGON, SIZE_OF_DRAGON));
}
public Dragon(World world, Point2D position, Point2D velocity, Point2D dimension) {
this.world = world;
this.position = position;
this.velocity = velocity;
this.dimension = dimension;
this.image = Constants.DRAGON_IMAGE;
}
public void draw(GraphicsContext gc) {
Point2D p = world.getCanvasPoint(position);
gc.drawImage(image, p.getX(), p.getY(), dimension.getX(), dimension.getY());
}
public void simulate(double deltaT) {
position = position.add(velocity.multiply(deltaT));
}
}
......@@ -8,12 +8,14 @@ public class World {
private double height;
private BulletAnimated bulletAnimatted;
private Cannon cannon;
private Dragon dragon;
public World(double width, double height) {
this.width = width;
this.height = height;
cannon = new Cannon(this, new Point2D(50, 50), new Point2D(100, 20));
bulletAnimatted = new BulletAnimated(this, cannon, new Point2D(30, 60), new Point2D(0, 0), 40);
dragon = new Dragon(this, new Point2D(100, 100), new Point2D(40, 40));
}
public Point2D getCanvasPoint(Point2D worldPoint) {
......@@ -24,11 +26,13 @@ public class World {
gc.clearRect(0, 0, width, height);
cannon.draw(gc);
bulletAnimatted.draw(gc);
dragon.draw(gc);
}
public void simulate(double timeDelta) {
bulletAnimatted.simulate(timeDelta);
cannon.simulate(timeDelta);
dragon.simulate(timeDelta);
}
public double getWidth() {
......
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