Skip to content
Snippets Groups Projects
World.java 928 B
Newer Older
Jan Kožusznik's avatar
Jan Kožusznik committed
package lab;

import javafx.geometry.Point2D;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;

public class World {
	private BulletAnimated bulletAnimatted;
	private Cannon cannon;
Jan Kožusznik's avatar
Jan Kožusznik committed
	private final Canvas canvas;
Jan Kožusznik's avatar
Jan Kožusznik committed

Jan Kožusznik's avatar
Jan Kožusznik committed
	public World(Canvas canvas) {
Jan Kožusznik's avatar
Jan Kožusznik committed
		super();
Jan Kožusznik's avatar
Jan Kožusznik committed
		this.canvas = canvas;
Jan Kožusznik's avatar
Jan Kožusznik committed
		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) {
Jan Kožusznik's avatar
Jan Kožusznik committed
		return new Point2D(worldPoint.getX(), canvas.getHeight() - worldPoint.getY());
Jan Kožusznik's avatar
Jan Kožusznik committed
	}

Jan Kožusznik's avatar
Jan Kožusznik committed
	public void draw() {
Jan Kožusznik's avatar
Jan Kožusznik committed
		GraphicsContext gc = canvas.getGraphicsContext2D();
		gc.clearRect(0, 0, canvas.getWidth(), canvas.getHeight());
		cannon.draw(gc);
		bulletAnimatted.draw(gc);
	}

Jan Kožusznik's avatar
Jan Kožusznik committed
	public void simulate(double timeDelta) {
Jan Kožusznik's avatar
Jan Kožusznik committed
		bulletAnimatted.simulate(timeDelta);
		cannon.simulate(timeDelta);
	}



}