mirror of
https://github.com/Noratrieb/Java2DGame.git
synced 2026-01-14 14:05:01 +01:00
fixed Turret and DebugPos
This commit is contained in:
parent
9f460d499a
commit
e95bb798f4
12 changed files with 13 additions and 8 deletions
|
|
@ -4,7 +4,7 @@ package core.math;
|
|||
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 {
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package core.objects.base;
|
||||
|
||||
import core.math.Coords;
|
||||
import core.math.Vector2D;
|
||||
import core.objects.core.GameObject;
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
* {@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 {
|
||||
|
||||
|
|
@ -99,7 +99,12 @@ public abstract class GameObject implements Drawable {
|
|||
|
||||
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);
|
||||
|
||||
g2d.setPaint(mainColor);
|
||||
|
|
|
|||
|
|
@ -81,8 +81,8 @@ public class Turret extends GameObject {
|
|||
|
||||
Point msLoc = master.getMouseLocation();
|
||||
Vector2D mouseRel = Coords.getMapCoordsFromWorld(Vector2D.fromPoint(msLoc)); //100 correct
|
||||
Vector2D center = battleShip.getMapCoords(getCenterPosition());
|
||||
double targetRotation = -Math.atan2(center.x - mouseRel.x, center.y - mouseRel.y);
|
||||
Vector2D centerMap = battleShip.getMapCoords(getCenterPosition());
|
||||
double targetRotation = -Math.atan2(centerMap.x - mouseRel.x, centerMap.y - mouseRel.y);
|
||||
|
||||
rotation = ExMath.angleLerp(rotation, targetRotation, ROTATION_SPEED);
|
||||
|
||||
|
|
@ -98,10 +98,9 @@ public class Turret extends GameObject {
|
|||
lastShot = System.currentTimeMillis();
|
||||
|
||||
Vector2D shellVel = Vector2D.getUnitVector(rotation).negative().multiply(SHELL_SPEED);
|
||||
master.debugPos(battleShip.getMapCoords(center));
|
||||
master.debugPos(center);
|
||||
master.debugPos(centerMap);
|
||||
Vector2D pos = Vector2D.rotateAround(
|
||||
battleShip.getMapCoords(center),
|
||||
centerMap,
|
||||
spawnPosNR,
|
||||
rotation);
|
||||
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue