mirror of
https://github.com/Noratrieb/Java2DGame.git
synced 2026-01-14 14:05:01 +01:00
cleanup
This commit is contained in:
parent
72b7c47a3e
commit
76ad24f96b
5 changed files with 25 additions and 99 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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<GameObject> objects;
|
||||
|
||||
|
||||
/**
|
||||
* All physics objects that exist
|
||||
*/
|
||||
private final List<Collidable> collidables;
|
||||
|
||||
/**
|
||||
* Stores all GameObjects that were created during a frame
|
||||
*/
|
||||
private final List<GameObject> objectBuffer;
|
||||
|
||||
/**
|
||||
* All physics objects that exist
|
||||
*/
|
||||
private final List<Collidable> 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 extends GameObject> 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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}
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue