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

Delete classes World and Bullet

parent f319b003
No related merge requests found
package lab;
import javafx.geometry.Point2D;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
public class Bullet {
private World world;
private Point2D velocity;
private double size;
private Point2D position;
public Bullet(World world, Point2D startPosition, Point2D velocity, double size) {
super();
this.world = world;
this.velocity = velocity;
this.size = size;
this.position = startPosition;
}
public void draw(GraphicsContext gc) {
gc.save();
gc.setFill(Color.BROWN);
Point2D p = world.getCanvasPoint(position);
gc.fillOval(p.getX() - size /2, p.getY() - size/2, size, size);
gc.restore();
}
public void simulate(double deltaT) {
// TODO Auto-generated method stub
position = position.add(velocity.multiply(deltaT));
}
}
......@@ -7,12 +7,10 @@ import javafx.scene.canvas.GraphicsContext;
public class DrawingThread extends AnimationTimer {
private final GraphicsContext gc;
private final World world;
private long lastTime;
public DrawingThread(Canvas canvas) {
this.gc = canvas.getGraphicsContext2D();
this.world = new World(canvas.getWidth(), canvas.getHeight());
}
/**
......@@ -22,9 +20,9 @@ public class DrawingThread extends AnimationTimer {
public void handle(long now) {
if (lastTime > 0) {
double deltaT = (now - lastTime) / 1e9;
world.simulate(deltaT);
// call simulate on world
}
world.draw(gc);
//call draw on world
lastTime= now;
}
......
package lab;
import javafx.geometry.Point2D;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.paint.Color;
public class World {
private double width;
private double height;
private Bullet bullet;
public World(double width, double height) {
this.width = width;
this.height = height;
this.bullet = new Bullet(this, new Point2D(10, 10), new Point2D(10, 30), 15);
}
public Point2D getCanvasPoint(Point2D in) {
Point2D result = new Point2D(in.getX(), height - in.getY());
return result;
}
public void draw(GraphicsContext gc) {
gc.save();
gc.setFill(Color.LIGHTGREY);
gc.fillRect(0, 0, width, height);
gc.restore();
bullet.draw(gc);
}
public void simulate(double deltaT) {
this.bullet.simulate(deltaT);
}
}
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