diff --git a/2DGame.iml b/2DGame.iml deleted file mode 100644 index 78b2cc5..0000000 --- a/2DGame.iml +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/src/main/java/core/math/Coords.java b/src/main/java/core/math/Coords.java index ad3e83d..858f04e 100644 --- a/src/main/java/core/math/Coords.java +++ b/src/main/java/core/math/Coords.java @@ -22,8 +22,13 @@ public class Coords { public static Master master = Master.getMaster(); + /** + * Get the world coordinates of a point in map coordinates + * @param value A point in map coordinates + * @return The point in world coordinates + */ public static Vector2D getWorldCoords(Vector2D value) { - double x = (value.x / (Master.SCREEN_Y_COORDINATES * Master.SCREEN_RATIO) * master.getW()); + double x = (value.x / Master.SCREEN_Y_COORDINATES / Master.SCREEN_RATIO * master.getW()); double y = (value.y / Master.SCREEN_Y_COORDINATES * master.getH()); return new Vector2D(x, y); } @@ -39,11 +44,4 @@ public class Coords { double y = (value.y / master.getH()) * Master.SCREEN_Y_COORDINATES; return new Vector2D(x, y); } - - public static Vector2D getWorldCoordsSize(Vector2D value) { - double x = (value.x / Master.SCREEN_Y_COORDINATES * master.getH()); - double y = (value.y / Master.SCREEN_Y_COORDINATES * master.getH()); - return new Vector2D(x, y); - } - } diff --git a/src/main/java/core/physics/hitboxes/RectHitBox.java b/src/main/java/core/physics/hitboxes/RectHitBox.java index 2cae2b9..bab67d0 100644 --- a/src/main/java/core/physics/hitboxes/RectHitBox.java +++ b/src/main/java/core/physics/hitboxes/RectHitBox.java @@ -175,7 +175,7 @@ public class RectHitBox extends Hitbox { public void draw(Graphics2D g2d) { Vector2D abs = Coords.getWorldCoords(x1); - Vector2D sizeAbs = Coords.getWorldCoordsSize(Vector2D.subtract(y2, x1)); + Vector2D sizeAbs = Coords.getWorldCoords(Vector2D.subtract(y2, x1)); g2d.drawRect((int)abs.x, (int)abs.y, (int)sizeAbs.x, (int)sizeAbs.y); g2d.setPaint(Color.MAGENTA); diff --git a/src/main/java/objects/DebugPos.java b/src/main/java/objects/DebugPos.java index a5e31c7..cfc4559 100644 --- a/src/main/java/objects/DebugPos.java +++ b/src/main/java/objects/DebugPos.java @@ -17,7 +17,7 @@ public class DebugPos extends GameObject { @Override public void draw(Graphics2D g2d) { - drawOval(g2d); + drawOval(g2d, "center"); } @Override diff --git a/src/main/java/objects/core/GameObject.java b/src/main/java/objects/core/GameObject.java index 1bb293f..5bac81e 100644 --- a/src/main/java/objects/core/GameObject.java +++ b/src/main/java/objects/core/GameObject.java @@ -62,7 +62,7 @@ public abstract class GameObject implements Drawable { */ public void drawRect(Graphics2D g2d) { Vector2D abs = Coords.getWorldCoords(position); - Vector2D sizeAbs = Coords.getWorldCoordsSize(size); + Vector2D sizeAbs = Coords.getWorldCoords(size); g2d.setPaint(mainColor); g2d.fillRect((int) abs.x, (int) abs.y, (int) sizeAbs.x, (int) sizeAbs.y); @@ -75,20 +75,32 @@ public abstract class GameObject implements Drawable { */ public void fillOval(Graphics2D g2d) { Vector2D abs = Coords.getWorldCoords(position); - Vector2D sizeAbs = Coords.getWorldCoordsSize(size); + Vector2D sizeAbs = Coords.getWorldCoords(size); g2d.setPaint(mainColor); g2d.fillOval((int) abs.x, (int) abs.y, (int) sizeAbs.x, (int) sizeAbs.y); } /** - * This method draws a rectangle at the current position and size + * This method draws an oval at the current position and size * * @param g2d The Graphics2D object provided by the master */ public void drawOval(Graphics2D g2d) { - Vector2D abs = Coords.getWorldCoords(position); - Vector2D sizeAbs = Coords.getWorldCoordsSize(size); + drawOval(g2d, ""); + } + + /** + * This method draws an oval at the current position and size with arguments + * + * @param g2d The Graphics2D object provided by the master + */ + public void drawOval(Graphics2D g2d, String arg) { + + Vector2D abs; + + abs = (arg.contains("center")) ? Coords.getWorldCoords(getCenterPosition()) : Coords.getWorldCoords(position); + Vector2D sizeAbs = Coords.getWorldCoords(size); g2d.setPaint(mainColor); g2d.drawOval((int) abs.x, (int) abs.y, (int) sizeAbs.x, (int) sizeAbs.y); @@ -103,7 +115,7 @@ public abstract class GameObject implements Drawable { */ public void drawRoundRect(Graphics2D g2d, int arcW, int arcH) { Vector2D abs = Coords.getWorldCoords(position); - Vector2D sizeAbs = Coords.getWorldCoordsSize(size); + Vector2D sizeAbs = Coords.getWorldCoords(size); g2d.setPaint(mainColor); g2d.fillRoundRect((int) abs.x, (int) abs.y, (int) sizeAbs.x, (int) sizeAbs.y, arcW, arcH); @@ -116,8 +128,8 @@ public abstract class GameObject implements Drawable { public Vector2D getMapCoords(Vector2D value) { - double x = (position.x + value.x / 100d * size.x); - double y = (position.y + value.y / 100d * size.y); + double x = position.x + value.x; + double y = position.y + value.y; return new Vector2D(x, y); } @@ -134,7 +146,7 @@ public abstract class GameObject implements Drawable { } public Vector2D getWorldCoordsFromLocalSize(Vector2D value) { - return Coords.getWorldCoordsSize(getMapCoordsSize(value)); + return Coords.getWorldCoords(getMapCoordsSize(value)); } public Vector2D getCenterPosition(Vector2D position){ diff --git a/src/main/java/objects/ships/BattleShip.java b/src/main/java/objects/ships/BattleShip.java index 6848fec..9f10068 100644 --- a/src/main/java/objects/ships/BattleShip.java +++ b/src/main/java/objects/ships/BattleShip.java @@ -15,7 +15,7 @@ public class BattleShip extends GameObject { public BattleShip(Color mainColor) { this(20, 20, 10, 40, mainColor); //TODO turret size should use w and h but correct just like with world coords - turrets.add(new Turret(this, 25, 25, 50, 3)); + turrets.add(new Turret(this, 2.5, 10, 50, 3)); //turrets.add(new Turret(this, 25, 10, 50, 2)); //turrets.add(new Turret(this, 25, 70, 50, 2)); } diff --git a/src/main/java/objects/ships/Shell.java b/src/main/java/objects/ships/Shell.java index 5110a2b..4aaa38d 100644 --- a/src/main/java/objects/ships/Shell.java +++ b/src/main/java/objects/ships/Shell.java @@ -10,19 +10,18 @@ import java.awt.*; /** * A shell fired by a cannon */ -//TODO why tf do shells not use map coords... public class Shell extends GameObject { public Shell(Vector2D position, Vector2D size, Vector2D velocity) { super(position, size/*, new RectHitBox(position, size)*/); this.velocity = velocity; + this.mainColor = Color.ORANGE; } @Override public void draw(Graphics2D g2d) { - g2d.setPaint(Color.orange); - g2d.fillOval((int) position.x, (int) position.y, (int) size.x, (int) size.y); + fillOval(g2d); } @Override diff --git a/src/main/java/objects/ships/Turret.java b/src/main/java/objects/ships/Turret.java index 3cd9477..18f1dc7 100644 --- a/src/main/java/objects/ships/Turret.java +++ b/src/main/java/objects/ships/Turret.java @@ -1,13 +1,10 @@ package objects.ships; -import core.Master; import core.math.Coords; import core.math.ExMath; import core.math.Vector2D; -import jdk.swing.interop.SwingInterOpUtils; import objects.core.GameObject; -import javax.swing.*; import java.awt.*; /** @@ -17,7 +14,8 @@ public class Turret extends GameObject { private static final double ROTATION_SPEED = 0.05; private static final int SHOT_EFFECT_TIME = 300; - private static final int SHELL_SPEED = 10; + private static final int SHELL_SPEED = 1; + public static final double SHELL_SIZE = 2; BattleShip battleShip; @@ -113,7 +111,8 @@ public class Turret extends GameObject { Vector2D shellVel = Vector2D.getUnitVector(rotation).negative().multiply(SHELL_SPEED); Vector2D pos = Vector2D.rotateAround(new Vector2D(center.x, center.y), new Vector2D(barrelX, frontPosY), rotation, Vector2D.COUNTERCLOCKWISE); - master.create(new Shell(pos, new Vector2D(10, 10), shellVel)); + master.debugPos(pos); + master.create(new Shell(pos, new Vector2D(SHELL_SIZE, SHELL_SIZE), shellVel)); } } } diff --git a/target/classes/objects/ships/BattleShip.class b/target/classes/objects/ships/BattleShip.class index 56bb9a3..4318895 100644 Binary files a/target/classes/objects/ships/BattleShip.class and b/target/classes/objects/ships/BattleShip.class differ diff --git a/target/classes/objects/ships/Turret.class b/target/classes/objects/ships/Turret.class index 59ca635..4849663 100644 Binary files a/target/classes/objects/ships/Turret.class and b/target/classes/objects/ships/Turret.class differ