diff --git a/src/main/java/core/general/Master.java b/src/main/java/core/general/Master.java index 86865e8..4467245 100644 --- a/src/main/java/core/general/Master.java +++ b/src/main/java/core/general/Master.java @@ -118,8 +118,17 @@ public class Master extends JPanel { * * @param pos The position */ - public void debugPos(Vector2D pos) { - create(new DebugPos(pos, new Vector2D(2, 2)), 3); + public static void debugPos(Vector2D pos) { + debugPos(pos, Long.MAX_VALUE); + } + + /** + * Debug a position, creates a green dot at the position + * + * @param pos The position + */ + private void debugPosObj(Vector2D pos, long lifeTime) { + create(new DebugPos(pos, new Vector2D(2, 2), lifeTime), 3); } /** @@ -128,8 +137,8 @@ public class Master extends JPanel { * @param pos The position * @param lifeTime The lifetime of the {@code DebugPos} in ms */ - public void debugPos(Vector2D pos, long lifeTime) { - create(new DebugPos(pos, new Vector2D(2, 2), lifeTime), 3); + public static void debugPos(Vector2D pos, long lifeTime) { + master.debugPosObj(pos, lifeTime); } @@ -251,9 +260,13 @@ public class Master extends JPanel { public void destroy(GameObject gameObject) { objectBuffer.remove(gameObject); + gameObject.getParent().removeChild(gameObject); + drawables.get(gameObject.getLayer()).remove(gameObject); + if (gameObject instanceof Collidable) { collidablesBuffer.remove(gameObject); + if (Init.DEBUG_MODE) { drawables.get(Hitbox.HITBOX_RENDER_LAYER).remove(((CollGameObject) gameObject).getHitbox()); } diff --git a/src/main/java/core/objects/base/DebugPos.java b/src/main/java/core/objects/base/DebugPos.java index f6b39c3..37fcfd2 100644 --- a/src/main/java/core/objects/base/DebugPos.java +++ b/src/main/java/core/objects/base/DebugPos.java @@ -15,10 +15,6 @@ public class DebugPos extends GameObject { private final long lifeTime; private long spawnTime; - public DebugPos(Vector2D position, Vector2D size) { - this(position, size, Long.MAX_VALUE); - } - public DebugPos(Vector2D position, Vector2D size, long lifeTime) { super(position.copy(), size); this.velocity = new Vector2D(); diff --git a/src/main/java/core/objects/core/GameObject.java b/src/main/java/core/objects/core/GameObject.java index 42138a4..c0d5167 100644 --- a/src/main/java/core/objects/core/GameObject.java +++ b/src/main/java/core/objects/core/GameObject.java @@ -7,6 +7,7 @@ import core.math.Vector2D; import core.renderer.Renderer; import java.awt.*; +import java.util.ArrayList; /** * The GameObject class is the superclass of every {@code GameObject} that can be displayed on screen. It has the 2 @@ -22,14 +23,12 @@ public abstract class GameObject implements Drawable { protected Vector2D velocity; protected Color mainColor; - protected Master master; - protected int layer; + private Renderer renderer; protected GameObject parent; - - private Renderer renderer; + protected ArrayList children = new ArrayList<>(); public GameObject(Vector2D position, Vector2D size) { this.position = position; @@ -78,19 +77,7 @@ public abstract class GameObject implements Drawable { * * @param g2d The Graphics2D object provided by the master */ - public void drawRect(Graphics2D g2d) { - Vector2D abs = Coordinates.getWorldCoordinates(position); - Vector2D sizeAbs = Coordinates.getWorldCoordinates(size); - - g2d.setPaint(mainColor); - g2d.fillRect((int) abs.x, (int) abs.y, (int) sizeAbs.x, (int) sizeAbs.y); - } - - /** - * This method draws a rectangle at the current position and size - * - * @param g2d The Graphics2D object provided by the master - */ + @Deprecated public void fillOval(Graphics2D g2d) { Vector2D abs = Coordinates.getWorldCoordinates(position); Vector2D sizeAbs = Coordinates.getWorldCoordinates(size); @@ -198,4 +185,16 @@ public abstract class GameObject implements Drawable { protected void setRenderer(Renderer renderer) { this.renderer = renderer; } + + public void addChild(GameObject obj){ + children.add(obj); + } + + public void removeChild(GameObject obj){ + children.remove(obj); + } + + public GameObject getParent() { + return parent; + } } diff --git a/src/main/java/objects/ships/Turret.java b/src/main/java/objects/ships/Turret.java index 923f806..252804b 100644 --- a/src/main/java/objects/ships/Turret.java +++ b/src/main/java/objects/ships/Turret.java @@ -1,6 +1,7 @@ package objects.ships; import core.general.Input; +import core.general.Master; import core.math.Coordinates; import core.math.ExMath; import core.math.Vector2D; @@ -40,11 +41,13 @@ public class Turret extends GameObject { int xCenterAbs = (int) (abs.x + sizeAbs / 2); int yCenterAbs = (int) (abs.y + sizeAbs / 2); + Master.debugPos(getMapCoords(position), 1); + g2d.rotate(rotation, xCenterAbs, yCenterAbs); g2d.fillOval((int) abs.x, (int) abs.y, sizeAbs, sizeAbs); - master.debugPos(abs, 1000); + Master.debugPos(abs, 1000); //BARRELS--------------------------------------- g2d.setStroke(new BasicStroke((int) Coordinates.getWorldCoordinates(new Vector2D(object.getSize().x / barrelAmount / BARREL_THICKNESS, 0)).x, BasicStroke.CAP_BUTT, @@ -74,6 +77,8 @@ public class Turret extends GameObject { @Override public void update() { + //TODO fix with everything haha + Point msLoc = master.getMouseLocation(); Vector2D mouseRel = Coordinates.getMapCoordinatesFromWorld(Vector2D.fromPoint(msLoc)); //100 correct Vector2D centerMap = getMapCoords(getCenterPosition()); diff --git a/src/main/java/objects/world/Wall.java b/src/main/java/objects/world/Wall.java index d9581ce..e77db36 100644 --- a/src/main/java/objects/world/Wall.java +++ b/src/main/java/objects/world/Wall.java @@ -4,6 +4,7 @@ import core.math.Vector2D; import core.physics.hitboxes.Hitbox; import core.physics.hitboxes.RectHitBox; import core.objects.core.CollGameObject; +import core.renderer.RectRenderer; import java.awt.*; @@ -11,11 +12,8 @@ public class Wall extends CollGameObject { public Wall(Vector2D position, Vector2D size) { super(position, size, new RectHitBox(position, size)); - } - @Override - public void draw(Graphics2D g2d) { - drawRect(g2d); + setRenderer(new RectRenderer(Color.BLACK, this, this.size)); } @Override diff --git a/target/classes/objects/ships/BattleShip.class b/target/classes/objects/ships/BattleShip.class index f25ab33..0b3e7d7 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 9be3d55..00b6360 100644 Binary files a/target/classes/objects/ships/Turret.class and b/target/classes/objects/ships/Turret.class differ diff --git a/target/classes/objects/world/Grid.class b/target/classes/objects/world/Grid.class index 0bae6b2..1c7718f 100644 Binary files a/target/classes/objects/world/Grid.class and b/target/classes/objects/world/Grid.class differ