fixed Turret and DebugPos

This commit is contained in:
nora 2020-12-15 15:00:59 +01:00
parent 9f460d499a
commit e95bb798f4
12 changed files with 13 additions and 8 deletions

View file

@ -4,7 +4,7 @@ package core.math;
import java.awt.*; import java.awt.*;
/** /**
* A 2-dimensional Vector that can be used to store position or velocity * A 2-dimensional Vector that can be used to store position or velocity or size or whatever
*/ */
public class Vector2D { public class Vector2D {

View file

@ -1,5 +1,6 @@
package core.objects.base; package core.objects.base;
import core.math.Coords;
import core.math.Vector2D; import core.math.Vector2D;
import core.objects.core.GameObject; import core.objects.core.GameObject;

View file

@ -9,7 +9,7 @@ import java.awt.*;
/** /**
* The GameObject class is the superclass of every GameObject that can be displayed on screen. It has the 2 * The GameObject class is the superclass of every GameObject that can be displayed on screen. It has the 2
* {@link #update()} and {@link #draw(Graphics2D)} methods that have to be * {@link #update()} and {@link #draw(Graphics2D)} methods that have to be overridden
*/ */
public abstract class GameObject implements Drawable { public abstract class GameObject implements Drawable {
@ -99,7 +99,12 @@ public abstract class GameObject implements Drawable {
Vector2D abs; Vector2D abs;
abs = (arg.contains("center")) ? Coords.getWorldCoords(getCenterPosition()) : Coords.getWorldCoords(position); if(arg.contains("center")){
abs = Coords.getWorldCoords(new Vector2D(position.x - size.x / 2, position.y - size.y / 2));
} else {
abs = Coords.getWorldCoords(position);
}
Vector2D sizeAbs = Coords.getWorldCoords(size); Vector2D sizeAbs = Coords.getWorldCoords(size);
g2d.setPaint(mainColor); g2d.setPaint(mainColor);

View file

@ -81,8 +81,8 @@ public class Turret extends GameObject {
Point msLoc = master.getMouseLocation(); Point msLoc = master.getMouseLocation();
Vector2D mouseRel = Coords.getMapCoordsFromWorld(Vector2D.fromPoint(msLoc)); //100 correct Vector2D mouseRel = Coords.getMapCoordsFromWorld(Vector2D.fromPoint(msLoc)); //100 correct
Vector2D center = battleShip.getMapCoords(getCenterPosition()); Vector2D centerMap = battleShip.getMapCoords(getCenterPosition());
double targetRotation = -Math.atan2(center.x - mouseRel.x, center.y - mouseRel.y); double targetRotation = -Math.atan2(centerMap.x - mouseRel.x, centerMap.y - mouseRel.y);
rotation = ExMath.angleLerp(rotation, targetRotation, ROTATION_SPEED); rotation = ExMath.angleLerp(rotation, targetRotation, ROTATION_SPEED);
@ -98,10 +98,9 @@ public class Turret extends GameObject {
lastShot = System.currentTimeMillis(); lastShot = System.currentTimeMillis();
Vector2D shellVel = Vector2D.getUnitVector(rotation).negative().multiply(SHELL_SPEED); Vector2D shellVel = Vector2D.getUnitVector(rotation).negative().multiply(SHELL_SPEED);
master.debugPos(battleShip.getMapCoords(center)); master.debugPos(centerMap);
master.debugPos(center);
Vector2D pos = Vector2D.rotateAround( Vector2D pos = Vector2D.rotateAround(
battleShip.getMapCoords(center), centerMap,
spawnPosNR, spawnPosNR,
rotation); rotation);

Binary file not shown.

Binary file not shown.

Binary file not shown.