diff --git a/src/main/java/lab/App.java b/src/main/java/lab/App.java index 210b19fff7db7570d4cba390ad44ff328fde7445..3bef520808ac9204053ab2be9951f75005e9b96f 100644 --- a/src/main/java/lab/App.java +++ b/src/main/java/lab/App.java @@ -52,10 +52,13 @@ public class App extends Application { private void drawScene() { //graphic context is used for a painting GraphicsContext gc = canvas.getGraphicsContext2D(); + World world = new World(canvas.getWidth(), canvas.getHeight()); int timeout = 10; while (!Routines.isEndOfThreadRequestedByJavaVM()) { + world.draw(gc); Routines.sleep(timeout); double deltaT = timeout / 1000.; + world.simulate(deltaT); } } diff --git a/src/main/java/lab/Bullet.java b/src/main/java/lab/Bullet.java new file mode 100644 index 0000000000000000000000000000000000000000..f41921cb50cc7411afa91934165b598540da3269 --- /dev/null +++ b/src/main/java/lab/Bullet.java @@ -0,0 +1,41 @@ +package lab; + +import javafx.geometry.Point2D; +import javafx.scene.canvas.GraphicsContext; +import javafx.scene.image.Image; +import javafx.scene.paint.Color; + +public class Bullet { + private World world; + private Point2D startPosition; + private Point2D velocity; + private double size; + private Point2D position; + private Image image; + public Bullet(World world, Point2D startPosition, Point2D velocity, double size) { + super(); + this.world = world; + this.startPosition = startPosition; + this.velocity = velocity; + this.size = size; + this.position = startPosition; + image = new Image(Bullet.class.getResourceAsStream("fireball-transparent.gif")); + + } + + 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.drawImage(image, 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)); + } + + +} diff --git a/src/main/java/lab/Canon.java b/src/main/java/lab/Canon.java new file mode 100644 index 0000000000000000000000000000000000000000..36646c7990dc98ed6aa7f130c2dc987ef8ba9ad0 --- /dev/null +++ b/src/main/java/lab/Canon.java @@ -0,0 +1,27 @@ +package lab; + +import javafx.geometry.Point2D; +import javafx.scene.canvas.GraphicsContext; +import javafx.scene.paint.Color; +import javafx.scene.transform.Affine; +import javafx.scene.transform.Transform; + +public class Canon { + + private Point2D position = new Point2D(10, 30); + + private int angle = 20; + + public void draw(GraphicsContext gc) { + gc.save(); + gc.setFill(Color.STEELBLUE); + gc.setTransform(new Affine(Transform.rotate(angle, position.getX(), position.getY() + 10))); + gc.fillRect(position.getX(), position.getY() + 6, 40, 12); + gc.restore(); + } + + + public void simulate(double deltaT) { + angle+= 5; + } +} diff --git a/src/main/java/lab/World.java b/src/main/java/lab/World.java new file mode 100644 index 0000000000000000000000000000000000000000..3d8019048a5bd0c807ce40f7414295a9149434db --- /dev/null +++ b/src/main/java/lab/World.java @@ -0,0 +1,42 @@ +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; + + private Canon canon; + + 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), 40); + this.canon = new Canon(); + } + + 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); + canon.draw(gc); + } + + public void simulate(double deltaT) { + this.bullet.simulate(deltaT); + this.canon.simulate(deltaT); + } +}