Skip to content
Snippets Groups Projects
Commit 2f3f2b9a authored by jez04's avatar jez04
Browse files

feat: add world ref

parent f8410a18
No related merge requests found
......@@ -9,10 +9,12 @@ public class Bullet {
private final Point2D acceleration;
private final World world;
private Point2D position;
private Point2D velocity;
public Bullet(Point2D position, Point2D velocity, Point2D acceleration) {
public Bullet(World world, Point2D position, Point2D velocity, Point2D acceleration) {
this.world = world;
this.position = position;
this.velocity = velocity;
this.acceleration = acceleration;
......
......@@ -7,9 +7,11 @@ import javafx.scene.image.Image;
public class BulletAnimated {
private static final double SIZE = 40;
private final World world;
private Image image = new Image(this.getClass().getResourceAsStream("fireball-transparent.gif"));
public BulletAnimated(Point2D position, Point2D velocity, Point2D acceleration) {
public BulletAnimated(World world, Point2D position, Point2D velocity, Point2D acceleration) {
this.world = world;
this.position = position;
this.velocity = velocity;
this.acceleration = acceleration;
......
......@@ -10,17 +10,20 @@ public class Cannon {
private static final double LENGTH = 60;
private static final double WIDTH = 15;
private final World world;
private Point2D position;
private double angle;
private double angleDelta = 25;
public Cannon(Point2D position, double angle) {
public Cannon(World world, Point2D position, double angle) {
this.world = world;
this.position = position;
this.angle = angle;
}
public void draw(GraphicsContext gc) {
gc.save();
gc.transform(new Affine(Transform.rotate(angle, position.getX(), position.getY())));
gc.transform(new Affine(Transform.rotate(angle, position.getX(), position.getY() + WIDTH / 2)));
gc.setFill(Color.BROWN);
gc.fillRect(position.getX(), position.getY(), LENGTH, WIDTH);
gc.restore();
......@@ -28,6 +31,9 @@ public class Cannon {
public void simulate(double deltaT) {
// do nothing yet
angle += 25 * deltaT;
angle += angleDelta * deltaT;
if (angle >= 90 || angle <= 0) {
angleDelta = -angleDelta;
}
}
}
......@@ -16,9 +16,9 @@ public class World {
public World(double width, double hight) {
this.width = width;
this.hight = hight;
this.bullet = new Bullet(new Point2D(0, 0), new Point2D(30, 30), new Point2D(0, -9.81));
this.bullet2 = new BulletAnimated(new Point2D(0, 0), new Point2D(30, 70), new Point2D(0, -9.81));
this.cannon = new Cannon(new Point2D(0, 0), 45);
bullet = new Bullet(this, new Point2D(0, 0), new Point2D(30, 30), new Point2D(0, -9.81));
bullet2 = new BulletAnimated(this, new Point2D(0, 0), new Point2D(30, 70), new Point2D(0, -9.81));
cannon = new Cannon(this, new Point2D(0, 0), 45);
}
public void draw(GraphicsContext gc) {
......@@ -28,15 +28,15 @@ public class World {
// Change coordinate system to human like
gc.scale(1, -1);
gc.translate(0, -hight);
this.bullet.draw(gc);
this.bullet2.draw(gc);
this.cannon.draw(gc);
bullet.draw(gc);
bullet2.draw(gc);
cannon.draw(gc);
gc.restore();
}
public void simulate(double deltaT) {
this.bullet.simulate(deltaT);
this.bullet2.simulate(deltaT);
this.cannon.simulate(deltaT);
bullet.simulate(deltaT);
bullet2.simulate(deltaT);
cannon.simulate(deltaT);
}
}
\ No newline at end of file
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