Skip to content
Snippets Groups Projects
Commit 4810e11f authored by koz01's avatar koz01
Browse files

solution_Wed_7-15

parent 5ee57b7e
Branches
No related merge requests found
Pipeline #69 failed with stages
in 0 seconds
package lab;
import javafx.geometry.Point2D;
import javafx.geometry.Rectangle2D;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.image.Image;
......@@ -75,4 +76,12 @@ public class BulletAnimated {
accelerate = true;
}
public Rectangle2D getboundingBox() {
return new Rectangle2D(position.getX(), position.getY(), size, size);
}
public boolean isInCannon() {
return accelerate;
}
}
package lab;
import javafx.geometry.Point2D;
import javafx.geometry.Rectangle2D;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.image.Image;
......@@ -11,7 +12,7 @@ public class Dragon {
private Point2D position;
private final Point2D velocity;
private Point2D velocity;
private final Point2D dimension;
......@@ -37,5 +38,14 @@ public class Dragon {
public void simulate(double deltaT) {
position = position.add(velocity.multiply(deltaT));
position = new Point2D((position.getX() + world.getWidth()) % world.getWidth(), (position.getY() + world.getHeight()) % world.getHeight());
}
public Rectangle2D getboundingBox() {
return new Rectangle2D(position.getX(), position.getY(), dimension.getX(), dimension.getY());
}
public void hit() {
velocity = new Point2D(-velocity.getX(), -velocity.getY());
}
}
......@@ -8,14 +8,29 @@ public class World {
private double height;
private BulletAnimated bulletAnimatted;
private Cannon cannon;
private Dragon dragon;
private Dragon []dragons;
public World(double width, double height) {
this.width = width;
this.height = height;
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);
dragon = new Dragon(this, new Point2D(100, 100), new Point2D(40, 40));
/*
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))
};
}
public Point2D getCanvasPoint(Point2D worldPoint) {
......@@ -26,13 +41,28 @@ public class World {
gc.clearRect(0, 0, width, height);
cannon.draw(gc);
bulletAnimatted.draw(gc);
dragon.draw(gc);
for (Dragon dragon: dragons) {
dragon.draw(gc);
}
}
public void simulate(double timeDelta) {
bulletAnimatted.simulate(timeDelta);
cannon.simulate(timeDelta);
dragon.simulate(timeDelta);
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();
}
}
}
public double getWidth() {
......
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