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

Generate dragons randomly

parent 74a8d91c
Branches
No related merge requests found
package lab; package lab;
import java.util.Random;
import javafx.geometry.Point2D; import javafx.geometry.Point2D;
import javafx.scene.canvas.Canvas; import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext; import javafx.scene.canvas.GraphicsContext;
public class World { public class World {
private final static int NUMBER_OF_DRAGONS = 5;
private double width; private double width;
private double height; private double height;
private DrawableSimulable []entities; private DrawableSimulable []entities;
...@@ -14,11 +19,18 @@ public class World { ...@@ -14,11 +19,18 @@ public class World {
this.width = width; this.width = width;
this.height = height; this.height = height;
Cannon cannon = new Cannon(this, new Point2D(50, 50), new Point2D(100, 20)); Cannon cannon = new Cannon(this, new Point2D(50, 50), new Point2D(100, 20));
entities = new DrawableSimulable[] { cannon, entities = new DrawableSimulable[2 + NUMBER_OF_DRAGONS];
new BulletAnimated(this, cannon, new Point2D(30, 60), new Point2D(0, 0), 40), entities[0] = cannon;
new Dragon(this, new Point2D(50, 200), new Point2D(100, 5)), entities[1] = new BulletAnimated(this, cannon, new Point2D(30, 60), new Point2D(0, 0), 40);
new Dragon(this, new Point2D(50, 230), new Point2D(60, 5)), Random rnd = new Random();
new Dragon(this, new Point2D(50, 270), new Point2D(-50, 20)) };
for (int i = 2; i < entities.length; i++) {
int x = rnd.nextInt((int) width);
int y = rnd.nextInt((int) height);
int vel_x = (rnd.nextInt(10) - 5) * 10;
int vel_y = (rnd.nextInt(10) - 5) * 10;
entities[i] = new Dragon(this, new Point2D(x, y), new Point2D(vel_x, vel_y));
}
} }
public Point2D getCanvasPoint(Point2D worldPoint) { public Point2D getCanvasPoint(Point2D worldPoint) {
......
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