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

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

public class World {
	private double width;
	private double height;
Jan Kožusznik's avatar
Jan Kožusznik committed
	private BulletAnimated bulletAnimatted;
	private Cannon cannon;
koz01's avatar
koz01 committed
	private Dragon []dragons;
	
	public World(double width, double height) {
		this.width = width;
		this.height = height;
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);
koz01's avatar
koz01 committed
		/*
		  dragons = new Dragon[5];
		 
		dragons[0] = new Dragon(this, new Point2D(100, 100), new Point2D(40, 40));
		dragons[1] = new Dragon(this, new Point2D(120, 100), new Point2D(-40, 40));
		dragons[2] = new Dragon(this, new Point2D(120, 50), new Point2D(-70, 140));
		dragons[3] = new Dragon(this, new Point2D(20, 100), new Point2D(-40, 100));
		dragons[4] = new Dragon(this, new Point2D(120, 100), new Point2D(-40, 80));
		*/
		dragons = new Dragon[] {
				new Dragon(this, new Point2D(100, 100), new Point2D(40, 40)),
				new Dragon(this, new Point2D(120, 100), new Point2D(-40, 40)),
				new Dragon(this, new Point2D(120, 50), new Point2D(-70, 140)),
				new Dragon(this, new Point2D(20, 100), new Point2D(-40, 100)),
				new Dragon(this, new Point2D(120, 100), new Point2D(-40, 80))
		};
Jan Kožusznik's avatar
Jan Kožusznik committed
	}

	public Point2D getCanvasPoint(Point2D worldPoint) {
		return new Point2D(worldPoint.getX(), height - worldPoint.getY());
Jan Kožusznik's avatar
Jan Kožusznik committed
	}

	public void draw(GraphicsContext gc) {
		gc.clearRect(0, 0, width, height);
Jan Kožusznik's avatar
Jan Kožusznik committed
		cannon.draw(gc);
		bulletAnimatted.draw(gc);
koz01's avatar
koz01 committed
		for (Dragon dragon: dragons) {
			dragon.draw(gc);
		}
Jan Kožusznik's avatar
Jan Kožusznik committed
	}

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);
koz01's avatar
koz01 committed
		for (Dragon dragon: dragons) {
			dragon.simulate(timeDelta);
		}
		if (bulletAnimatted.isInCannon()) {
			return;
		}
		
		for (Dragon dragon: dragons) {
			if (dragon.getboundingBox().intersects(bulletAnimatted.getboundingBox())) {
				dragon.hit();
				bulletAnimatted.reload();
			}
		}
		
Jan Kožusznik's avatar
Jan Kožusznik committed
	}

	public double getWidth() {
		return width;
Jan Kožusznik's avatar
Jan Kožusznik committed

	public double getHeight() {
		return height;
Jan Kožusznik's avatar
Jan Kožusznik committed

}