mirror of
https://github.com/Noratrieb/Java2DGame.git
synced 2026-01-14 14:05:01 +01:00
rotational testing
This commit is contained in:
parent
fa911f501e
commit
7e90017e8f
8 changed files with 41 additions and 30 deletions
|
|
@ -118,8 +118,17 @@ public class Master extends JPanel {
|
||||||
*
|
*
|
||||||
* @param pos The position
|
* @param pos The position
|
||||||
*/
|
*/
|
||||||
public void debugPos(Vector2D pos) {
|
public static void debugPos(Vector2D pos) {
|
||||||
create(new DebugPos(pos, new Vector2D(2, 2)), 3);
|
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 pos The position
|
||||||
* @param lifeTime The lifetime of the {@code DebugPos} in ms
|
* @param lifeTime The lifetime of the {@code DebugPos} in ms
|
||||||
*/
|
*/
|
||||||
public void debugPos(Vector2D pos, long lifeTime) {
|
public static void debugPos(Vector2D pos, long lifeTime) {
|
||||||
create(new DebugPos(pos, new Vector2D(2, 2), lifeTime), 3);
|
master.debugPosObj(pos, lifeTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -251,9 +260,13 @@ public class Master extends JPanel {
|
||||||
|
|
||||||
public void destroy(GameObject gameObject) {
|
public void destroy(GameObject gameObject) {
|
||||||
objectBuffer.remove(gameObject);
|
objectBuffer.remove(gameObject);
|
||||||
|
gameObject.getParent().removeChild(gameObject);
|
||||||
|
|
||||||
drawables.get(gameObject.getLayer()).remove(gameObject);
|
drawables.get(gameObject.getLayer()).remove(gameObject);
|
||||||
|
|
||||||
if (gameObject instanceof Collidable) {
|
if (gameObject instanceof Collidable) {
|
||||||
collidablesBuffer.remove(gameObject);
|
collidablesBuffer.remove(gameObject);
|
||||||
|
|
||||||
if (Init.DEBUG_MODE) {
|
if (Init.DEBUG_MODE) {
|
||||||
drawables.get(Hitbox.HITBOX_RENDER_LAYER).remove(((CollGameObject) gameObject).getHitbox());
|
drawables.get(Hitbox.HITBOX_RENDER_LAYER).remove(((CollGameObject) gameObject).getHitbox());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,10 +15,6 @@ public class DebugPos extends GameObject {
|
||||||
private final long lifeTime;
|
private final long lifeTime;
|
||||||
private long spawnTime;
|
private long spawnTime;
|
||||||
|
|
||||||
public DebugPos(Vector2D position, Vector2D size) {
|
|
||||||
this(position, size, Long.MAX_VALUE);
|
|
||||||
}
|
|
||||||
|
|
||||||
public DebugPos(Vector2D position, Vector2D size, long lifeTime) {
|
public DebugPos(Vector2D position, Vector2D size, long lifeTime) {
|
||||||
super(position.copy(), size);
|
super(position.copy(), size);
|
||||||
this.velocity = new Vector2D();
|
this.velocity = new Vector2D();
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import core.math.Vector2D;
|
||||||
import core.renderer.Renderer;
|
import core.renderer.Renderer;
|
||||||
|
|
||||||
import java.awt.*;
|
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
|
* 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 Vector2D velocity;
|
||||||
|
|
||||||
protected Color mainColor;
|
protected Color mainColor;
|
||||||
|
|
||||||
protected Master master;
|
protected Master master;
|
||||||
|
|
||||||
protected int layer;
|
protected int layer;
|
||||||
|
private Renderer renderer;
|
||||||
|
|
||||||
protected GameObject parent;
|
protected GameObject parent;
|
||||||
|
protected ArrayList<GameObject> children = new ArrayList<>();
|
||||||
private Renderer renderer;
|
|
||||||
|
|
||||||
public GameObject(Vector2D position, Vector2D size) {
|
public GameObject(Vector2D position, Vector2D size) {
|
||||||
this.position = position;
|
this.position = position;
|
||||||
|
|
@ -78,19 +77,7 @@ public abstract class GameObject implements Drawable {
|
||||||
*
|
*
|
||||||
* @param g2d The Graphics2D object provided by the master
|
* @param g2d The Graphics2D object provided by the master
|
||||||
*/
|
*/
|
||||||
public void drawRect(Graphics2D g2d) {
|
@Deprecated
|
||||||
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
|
|
||||||
*/
|
|
||||||
public void fillOval(Graphics2D g2d) {
|
public void fillOval(Graphics2D g2d) {
|
||||||
Vector2D abs = Coordinates.getWorldCoordinates(position);
|
Vector2D abs = Coordinates.getWorldCoordinates(position);
|
||||||
Vector2D sizeAbs = Coordinates.getWorldCoordinates(size);
|
Vector2D sizeAbs = Coordinates.getWorldCoordinates(size);
|
||||||
|
|
@ -198,4 +185,16 @@ public abstract class GameObject implements Drawable {
|
||||||
protected void setRenderer(Renderer renderer) {
|
protected void setRenderer(Renderer renderer) {
|
||||||
this.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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package objects.ships;
|
package objects.ships;
|
||||||
|
|
||||||
import core.general.Input;
|
import core.general.Input;
|
||||||
|
import core.general.Master;
|
||||||
import core.math.Coordinates;
|
import core.math.Coordinates;
|
||||||
import core.math.ExMath;
|
import core.math.ExMath;
|
||||||
import core.math.Vector2D;
|
import core.math.Vector2D;
|
||||||
|
|
@ -40,11 +41,13 @@ public class Turret extends GameObject {
|
||||||
int xCenterAbs = (int) (abs.x + sizeAbs / 2);
|
int xCenterAbs = (int) (abs.x + sizeAbs / 2);
|
||||||
int yCenterAbs = (int) (abs.y + sizeAbs / 2);
|
int yCenterAbs = (int) (abs.y + sizeAbs / 2);
|
||||||
|
|
||||||
|
Master.debugPos(getMapCoords(position), 1);
|
||||||
|
|
||||||
g2d.rotate(rotation, xCenterAbs, yCenterAbs);
|
g2d.rotate(rotation, xCenterAbs, yCenterAbs);
|
||||||
|
|
||||||
g2d.fillOval((int) abs.x, (int) abs.y, sizeAbs, sizeAbs);
|
g2d.fillOval((int) abs.x, (int) abs.y, sizeAbs, sizeAbs);
|
||||||
|
|
||||||
master.debugPos(abs, 1000);
|
Master.debugPos(abs, 1000);
|
||||||
|
|
||||||
//BARRELS---------------------------------------
|
//BARRELS---------------------------------------
|
||||||
g2d.setStroke(new BasicStroke((int) Coordinates.getWorldCoordinates(new Vector2D(object.getSize().x / barrelAmount / BARREL_THICKNESS, 0)).x, BasicStroke.CAP_BUTT,
|
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
|
@Override
|
||||||
public void update() {
|
public void update() {
|
||||||
|
|
||||||
|
//TODO fix with everything haha
|
||||||
|
|
||||||
Point msLoc = master.getMouseLocation();
|
Point msLoc = master.getMouseLocation();
|
||||||
Vector2D mouseRel = Coordinates.getMapCoordinatesFromWorld(Vector2D.fromPoint(msLoc)); //100 correct
|
Vector2D mouseRel = Coordinates.getMapCoordinatesFromWorld(Vector2D.fromPoint(msLoc)); //100 correct
|
||||||
Vector2D centerMap = getMapCoords(getCenterPosition());
|
Vector2D centerMap = getMapCoords(getCenterPosition());
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import core.math.Vector2D;
|
||||||
import core.physics.hitboxes.Hitbox;
|
import core.physics.hitboxes.Hitbox;
|
||||||
import core.physics.hitboxes.RectHitBox;
|
import core.physics.hitboxes.RectHitBox;
|
||||||
import core.objects.core.CollGameObject;
|
import core.objects.core.CollGameObject;
|
||||||
|
import core.renderer.RectRenderer;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
|
||||||
|
|
@ -11,11 +12,8 @@ public class Wall extends CollGameObject {
|
||||||
|
|
||||||
public Wall(Vector2D position, Vector2D size) {
|
public Wall(Vector2D position, Vector2D size) {
|
||||||
super(position, size, new RectHitBox(position, size));
|
super(position, size, new RectHitBox(position, size));
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
setRenderer(new RectRenderer(Color.BLACK, this, this.size));
|
||||||
public void draw(Graphics2D g2d) {
|
|
||||||
drawRect(g2d);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue