diff --git a/src/main/java/lab/DrawingThread.java b/src/main/java/lab/DrawingThread.java
index af51eacecd31059ea67c309983b484db72beefd5..bac23778ca78f5778c11626505ba7a4420db604e 100755
--- a/src/main/java/lab/DrawingThread.java
+++ b/src/main/java/lab/DrawingThread.java
@@ -17,7 +17,7 @@ public class DrawingThread extends AnimationTimer {
public DrawingThread(Canvas canvas) {
this.canvas = canvas;
this.gc = canvas.getGraphicsContext2D();
- this.world = new World(canvas);
+ this.world = new World(canvas.getWidth(), canvas.getHeight());
}
/**
@@ -26,7 +26,7 @@ public class DrawingThread extends AnimationTimer {
@Override
public void handle(long now) {
gc.clearRect(0, 0, canvas.getWidth(), canvas.getHeight());
- world.draw();
+ world.draw(gc);
if (lasttime > 0) {
//time are in nanoseconds and method simulate expects seconds
world.simulate((now - lasttime) / 1e9);
diff --git a/src/main/java/lab/World.java b/src/main/java/lab/World.java
index c83521dac1b0f272d25c8c424b463d95a33bd1d1..32e29063760794dc58a65e7060e1ad47a5f17cf0 100644
--- a/src/main/java/lab/World.java
+++ b/src/main/java/lab/World.java
@@ -1,28 +1,27 @@
package lab;
import javafx.geometry.Point2D;
-import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
public class World {
+ private double width;
+ private double height;
private BulletAnimated bulletAnimatted;
private Cannon cannon;
- private final Canvas canvas;
-
- public World(Canvas canvas) {
- super();
- this.canvas = canvas;
+
+ 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);
}
public Point2D getCanvasPoint(Point2D worldPoint) {
- return new Point2D(worldPoint.getX(), canvas.getHeight() - worldPoint.getY());
+ return new Point2D(worldPoint.getX(), height - worldPoint.getY());
}
- public void draw() {
- GraphicsContext gc = canvas.getGraphicsContext2D();
- gc.clearRect(0, 0, canvas.getWidth(), canvas.getHeight());
+ public void draw(GraphicsContext gc) {
+ gc.clearRect(0, 0, width, height);
cannon.draw(gc);
bulletAnimatted.draw(gc);
}
@@ -33,11 +32,11 @@ public class World {
}
public double getWidth() {
- return canvas.getWidth();
+ return width;
}
public double getHeight() {
- return canvas.getHeight();
+ return height;
}
}