rotational testing

This commit is contained in:
nora 2020-12-30 15:48:07 +01:00
parent fa911f501e
commit 7e90017e8f
8 changed files with 41 additions and 30 deletions

View file

@ -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());
}

View file

@ -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();

View file

@ -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<GameObject> 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;
}
}

View file

@ -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());

View file

@ -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