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

fix: change canvas drawing

parent 2f3f2b9a
No related merge requests found
......@@ -3,7 +3,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>vsb-cs-java1</groupId>
<artifactId>lab02</artifactId>
<artifactId>lab03</artifactId>
<version>0.0.1-SNAPHOST</version>
<packaging>jar</packaging>
<properties>
......@@ -22,26 +22,36 @@
<artifactId>javafx-fxml</artifactId>
<version>23</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api -->
<!--
https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.11.0</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-engine -->
<!--
https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-engine -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.11.0</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-params -->
<!--
https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-params -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.11.0</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.reflections/reflections -->
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.10.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
......@@ -13,7 +13,7 @@ public class Cannon {
private final World world;
private Point2D position;
private double angle;
private double angleDelta = 25;
private double angleDelta = -25;
public Cannon(World world, Point2D position, double angle) {
this.world = world;
......@@ -32,7 +32,7 @@ public class Cannon {
public void simulate(double deltaT) {
// do nothing yet
angle += angleDelta * deltaT;
if (angle >= 90 || angle <= 0) {
if (angle >= 0 || angle <= -90) {
angleDelta = -angleDelta;
}
}
......
......@@ -7,27 +7,24 @@ public class World {
private final double width;
private final double hight;
private final double height;
private final Bullet bullet;
private final BulletAnimated bullet2;
private final Cannon cannon;
public World(double width, double hight) {
public World(double width, double height) {
this.width = width;
this.hight = hight;
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);
this.height = height;
bullet = new Bullet(this, new Point2D(0, height), new Point2D(30, -30), new Point2D(0, 9.81));
bullet2 = new BulletAnimated(this, new Point2D(0, height), new Point2D(50, -80), new Point2D(0, 9.81));
cannon = new Cannon(this, new Point2D(0, height-20), -45);
}
public void draw(GraphicsContext gc) {
gc.clearRect(0, 0, width, hight);
gc.clearRect(0, 0, width, height);
gc.save();
// Change coordinate system to human like
gc.scale(1, -1);
gc.translate(0, -hight);
bullet.draw(gc);
bullet2.draw(gc);
cannon.draw(gc);
......@@ -39,4 +36,13 @@ public class World {
bullet2.simulate(deltaT);
cannon.simulate(deltaT);
}
public double getWidth() {
return width;
}
public double getHeight() {
return height;
}
}
\ 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