This commit is contained in:
nora 2021-01-01 17:24:27 +01:00
parent 72b7c47a3e
commit 76ad24f96b
5 changed files with 25 additions and 99 deletions

View file

@ -1,16 +1,12 @@
package core.general; package core.general;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.util.ArrayList;
/** /**
* Handles easily accessible input for the objects * Handles easily accessible input for the objects
*/ */
public class Input { 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_HIGH = KeyEvent.VK_D;
public static final int KEY_HORIZONTAL_LOW = KeyEvent.VK_A; public static final int KEY_HORIZONTAL_LOW = KeyEvent.VK_A;
public static final int KEY_VERTICAL_HIGH = KeyEvent.VK_S; public static final int KEY_VERTICAL_HIGH = KeyEvent.VK_S;

View file

@ -7,7 +7,6 @@ import core.physics.Collidable;
import core.physics.Collision; import core.physics.Collision;
import core.objects.base.DebugPos; import core.objects.base.DebugPos;
import core.objects.core.GameObject; import core.objects.core.GameObject;
import core.rendering.Drawable;
import custom.Init; import custom.Init;
import javax.swing.*; import javax.swing.*;
@ -20,51 +19,23 @@ import java.util.List;
*/ */
public class Master { public class Master {
/**
* The ratio of height to width.
*/
public static double SCREEN_RATIO = 16f / 9f; 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; public static final double SCREEN_Y_COORDINATES = 100d;
/**
* The master object
*/
private static Master master; private static Master master;
/**
* All GameObjects that exist
*/
private final List<GameObject> objects; private final List<GameObject> objects;
/**
* All physics objects that exist
*/
private final List<Collidable> collidables; private final List<Collidable> collidables;
/**
* Stores all GameObjects that were created during a frame
*/
private final List<GameObject> objectBuffer; private final List<GameObject> objectBuffer;
/**
* All physics objects that exist
*/
private final List<Collidable> collidablesBuffer; private final List<Collidable> collidablesBuffer;
/**
* The {@code RenderEngine} that handles everything about rendering
*/
private RenderEngine renderEngine; private RenderEngine renderEngine;
/**
* Create a new master object
*/
public Master() { public Master() {
master = this; master = this;
@ -95,15 +66,6 @@ public class Master {
debugPos(pos, Long.MAX_VALUE); 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 * Debug a position, creates a green dot at the position
* *
@ -114,6 +76,10 @@ public class Master {
master.debugPosObj(pos, lifeTime); 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 * 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 * 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() { public Point getMouseLocation() {
Point p = MouseInfo.getPointerInfo().getLocation(); Point p = MouseInfo.getPointerInfo().getLocation();
@ -163,16 +129,20 @@ public class Master {
return obj; return obj;
} }
/** public void destroy(GameObject gameObject) {
* Add a new Drawable to the render list objectBuffer.remove(gameObject);
* gameObject.getParent().removeChild(gameObject);
* @param d The drawable
*/
@Deprecated
public void addDrawable(Drawable d) {
renderEngine.addRenderer(d);
}
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 * Check whether a collidables collide with another one
@ -212,23 +182,7 @@ public class Master {
return renderEngine.getH(); 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() { public RenderEngine getRenderEngine() {
return renderEngine; return renderEngine;
} }
} }

View file

@ -1,12 +1,9 @@
package core.objects.base; package core.objects.base;
import core.general.Input;
import core.math.Vector2D; import core.math.Vector2D;
import core.objects.core.GameObject; import core.objects.core.GameObject;
import core.rendering.renderer.EmptyRenderer; import core.rendering.renderer.EmptyRenderer;
import java.awt.event.KeyEvent;
/** /**
* The base Camera that shifts all objects * The base Camera that shifts all objects
*/ */

View file

@ -69,19 +69,6 @@ public abstract class GameObject {
this.position = target; 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} * Destroy this {@code GameObject}
@ -90,6 +77,8 @@ public abstract class GameObject {
master.destroy(this); master.destroy(this);
} }
//COORDINATE METHODS-------------------------------------------
/** /**
* Returns the value as map coords * Returns the value as map coords
* *
@ -113,6 +102,7 @@ public abstract class GameObject {
public Vector2D getWorldCoordsFromLocal(Vector2D value) { public Vector2D getWorldCoordsFromLocal(Vector2D value) {
return Coordinates.getWorldCoordinates(getMapCoords(value)); return Coordinates.getWorldCoordinates(getMapCoords(value));
} }
//-----------------------------------------------------------
/** /**
* Get the center position of the object * Get the center position of the object
@ -132,25 +122,15 @@ public abstract class GameObject {
return new Vector2D(size.x / 2, size.y / 2); return new Vector2D(size.x / 2, size.y / 2);
} }
/**
* Get the render layer of the object
*
* @return The render layer
*/
public int getLayer() { public int getLayer() {
return layer; return layer;
} }
/**
* Get the rotation of the object as a Vector2D
*
* @return The rotation
*/
protected Vector2D getV2DRotation() { protected Vector2D getV2DRotation() {
return Vector2D.getUnitVector(rotation); return Vector2D.getUnitVector(rotation);
} }
/** /**
* Create a new {@code GameObject} * Create a new {@code GameObject}
* @param gameObject The {@code GameObject} * @param gameObject The {@code GameObject}

View file

@ -9,7 +9,6 @@ import java.awt.*;
/** /**
* A rectangular hitbox * A rectangular hitbox
*/ */
//TODO hitbox position not calculated correctlyA
public class RectHitBox extends Hitbox { public class RectHitBox extends Hitbox {
/** /**
@ -168,10 +167,10 @@ public class RectHitBox extends Hitbox {
return y2; return y2;
} }
/* @Override @Override
public String toString() { public String toString() {
return "RectHitBox{" + x1 + " " + x2 + "\n" + y1 + " " + y2 + "}"; return "RectHitBox{" + x1 + " " + x2 + "\n" + y1 + " " + y2 + "}";
}*/ }
@Override @Override
public void draw(Graphics2D g2d) { public void draw(Graphics2D g2d) {