From 76ad24f96bbb1cf42b2f19099b35aa23a49f26c2 Mon Sep 17 00:00:00 2001 From: Nilstrieb Date: Fri, 1 Jan 2021 17:24:27 +0100 Subject: [PATCH] cleanup --- src/main/java/core/general/Input.java | 4 - src/main/java/core/general/Master.java | 84 +++++-------------- src/main/java/core/objects/base/Camera.java | 3 - .../java/core/objects/core/GameObject.java | 28 +------ .../core/physics/hitboxes/RectHitBox.java | 5 +- 5 files changed, 25 insertions(+), 99 deletions(-) diff --git a/src/main/java/core/general/Input.java b/src/main/java/core/general/Input.java index 27d9bf2..10990b6 100644 --- a/src/main/java/core/general/Input.java +++ b/src/main/java/core/general/Input.java @@ -1,16 +1,12 @@ package core.general; import java.awt.event.KeyEvent; -import java.util.ArrayList; /** * Handles easily accessible input for the objects */ public class Input { - public static final int AXIS_HORIZONTAL = 0; - public static final int AXIS_VERTICAL = 1; - public static final int KEY_HORIZONTAL_HIGH = KeyEvent.VK_D; public static final int KEY_HORIZONTAL_LOW = KeyEvent.VK_A; public static final int KEY_VERTICAL_HIGH = KeyEvent.VK_S; diff --git a/src/main/java/core/general/Master.java b/src/main/java/core/general/Master.java index 6855e7d..73b9b58 100644 --- a/src/main/java/core/general/Master.java +++ b/src/main/java/core/general/Master.java @@ -7,7 +7,6 @@ import core.physics.Collidable; import core.physics.Collision; import core.objects.base.DebugPos; import core.objects.core.GameObject; -import core.rendering.Drawable; import custom.Init; import javax.swing.*; @@ -20,51 +19,23 @@ import java.util.List; */ public class Master { - /** - * The ratio of height to width. - */ public static double SCREEN_RATIO = 16f / 9f; - /** - * The height of the relative coordinates shown on the screen. - */ public static final double SCREEN_Y_COORDINATES = 100d; - /** - * The master object - */ private static Master master; - /** - * All GameObjects that exist - */ private final List objects; - - /** - * All physics objects that exist - */ private final List collidables; - /** - * Stores all GameObjects that were created during a frame - */ private final List objectBuffer; - /** - * All physics objects that exist - */ private final List collidablesBuffer; - /** - * The {@code RenderEngine} that handles everything about rendering - */ private RenderEngine renderEngine; - /** - * Create a new master object - */ public Master() { master = this; @@ -95,15 +66,6 @@ public class Master { 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)); - } - /** * Debug a position, creates a green dot at the position * @@ -114,6 +76,10 @@ public class Master { master.debugPosObj(pos, lifeTime); } + private void debugPosObj(Vector2D pos, long lifeTime) { + create(new DebugPos(pos, new Vector2D(2, 2), lifeTime)); + } + /** * This method is the entry method for each frame. It handles everything about the frame @@ -136,7 +102,7 @@ public class Master { /** * Get the current location of the mouse relative to the frame * - * @return The location of the mouse, already normalized + * @return The location of the mouse, normalized in J2D coordinates */ public Point getMouseLocation() { Point p = MouseInfo.getPointerInfo().getLocation(); @@ -148,7 +114,7 @@ public class Master { /** * This method has to be called for every newly created GameObject * - * @param obj The new object + * @param obj The new object */ public T create(T obj) { objectBuffer.add(obj); @@ -163,16 +129,20 @@ public class Master { return obj; } - /** - * Add a new Drawable to the render list - * - * @param d The drawable - */ - @Deprecated - public void addDrawable(Drawable d) { - renderEngine.addRenderer(d); - } + public void destroy(GameObject gameObject) { + objectBuffer.remove(gameObject); + gameObject.getParent().removeChild(gameObject); + renderEngine.removeRenderer(gameObject.getRenderer()); + + if (gameObject instanceof Collidable) { + collidablesBuffer.remove(gameObject); + + if (Init.DEBUG_MODE) { + renderEngine.removeRenderer(((CollGameObject) gameObject).getHitbox()); + } + } + } /** * Check whether a collidables collide with another one @@ -212,23 +182,7 @@ public class Master { return renderEngine.getH(); } - public void destroy(GameObject gameObject) { - objectBuffer.remove(gameObject); - gameObject.getParent().removeChild(gameObject); - - renderEngine.removeRenderer(gameObject.getRenderer()); - - if (gameObject instanceof Collidable) { - collidablesBuffer.remove(gameObject); - - if (Init.DEBUG_MODE) { - renderEngine.removeRenderer(((CollGameObject) gameObject).getHitbox()); - } - } - } - public RenderEngine getRenderEngine() { return renderEngine; } - } \ No newline at end of file diff --git a/src/main/java/core/objects/base/Camera.java b/src/main/java/core/objects/base/Camera.java index a363292..1ee0193 100644 --- a/src/main/java/core/objects/base/Camera.java +++ b/src/main/java/core/objects/base/Camera.java @@ -1,12 +1,9 @@ package core.objects.base; -import core.general.Input; import core.math.Vector2D; import core.objects.core.GameObject; import core.rendering.renderer.EmptyRenderer; -import java.awt.event.KeyEvent; - /** * The base Camera that shifts all objects */ diff --git a/src/main/java/core/objects/core/GameObject.java b/src/main/java/core/objects/core/GameObject.java index c07223f..7e18525 100644 --- a/src/main/java/core/objects/core/GameObject.java +++ b/src/main/java/core/objects/core/GameObject.java @@ -69,19 +69,6 @@ public abstract class GameObject { this.position = target; } - /** - * 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); - - g2d.setPaint(mainColor); - g2d.fillOval((int) abs.x, (int) abs.y, (int) sizeAbs.x, (int) sizeAbs.y); - } /** * Destroy this {@code GameObject} @@ -90,6 +77,8 @@ public abstract class GameObject { master.destroy(this); } + + //COORDINATE METHODS------------------------------------------- /** * Returns the value as map coords * @@ -113,6 +102,7 @@ public abstract class GameObject { public Vector2D getWorldCoordsFromLocal(Vector2D value) { return Coordinates.getWorldCoordinates(getMapCoords(value)); } + //----------------------------------------------------------- /** * Get the center position of the object @@ -132,25 +122,15 @@ public abstract class GameObject { return new Vector2D(size.x / 2, size.y / 2); } - /** - * Get the render layer of the object - * - * @return The render layer - */ + public int getLayer() { return layer; } - /** - * Get the rotation of the object as a Vector2D - * - * @return The rotation - */ protected Vector2D getV2DRotation() { return Vector2D.getUnitVector(rotation); } - /** * Create a new {@code GameObject} * @param gameObject The {@code GameObject} diff --git a/src/main/java/core/physics/hitboxes/RectHitBox.java b/src/main/java/core/physics/hitboxes/RectHitBox.java index cde91b6..e588bf7 100644 --- a/src/main/java/core/physics/hitboxes/RectHitBox.java +++ b/src/main/java/core/physics/hitboxes/RectHitBox.java @@ -9,7 +9,6 @@ import java.awt.*; /** * A rectangular hitbox */ -//TODO hitbox position not calculated correctlyA public class RectHitBox extends Hitbox { /** @@ -168,10 +167,10 @@ public class RectHitBox extends Hitbox { return y2; } -/* @Override + @Override public String toString() { return "RectHitBox{" + x1 + " " + x2 + "\n" + y1 + " " + y2 + "}"; - }*/ + } @Override public void draw(Graphics2D g2d) {