From ff35f9215b973c102e651632a8ba63ac991c2b91 Mon Sep 17 00:00:00 2001 From: jez04 <david.jezek@post.cz> Date: Mon, 7 Oct 2024 02:57:17 +0200 Subject: [PATCH] fix: change canvas drawing --- pom.xml | 18 ++++++++++++++---- src/main/java/lab/Cannon.java | 4 ++-- src/main/java/lab/World.java | 26 ++++++++++++++++---------- 3 files changed, 32 insertions(+), 16 deletions(-) diff --git a/pom.xml b/pom.xml index 6a92250..06b4758 100644 --- a/pom.xml +++ b/pom.xml @@ -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> diff --git a/src/main/java/lab/Cannon.java b/src/main/java/lab/Cannon.java index d0248ce..0a1cf17 100644 --- a/src/main/java/lab/Cannon.java +++ b/src/main/java/lab/Cannon.java @@ -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; } } diff --git a/src/main/java/lab/World.java b/src/main/java/lab/World.java index 8266a75..3417a42 100644 --- a/src/main/java/lab/World.java +++ b/src/main/java/lab/World.java @@ -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 -- GitLab