mirror of
https://github.com/Noratrieb/Java2DGame.git
synced 2026-01-14 14:05:01 +01:00
destroyed things
This commit is contained in:
parent
435de55eb1
commit
4fb5bcc543
14 changed files with 61 additions and 18 deletions
|
|
@ -1,9 +1,13 @@
|
|||
package objects.ships;
|
||||
|
||||
import core.Master;
|
||||
import core.math.Coords;
|
||||
import core.math.ExMath;
|
||||
import core.math.Vector2D;
|
||||
import jdk.swing.interop.SwingInterOpUtils;
|
||||
import objects.core.GameObject;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
|
|
@ -25,8 +29,6 @@ public class Turret extends GameObject {
|
|||
|
||||
private long lastShot = 0;
|
||||
|
||||
//private double rotation;
|
||||
|
||||
public Turret(BattleShip battleShip, double x, double y, double size, int barrelAmount) {
|
||||
super(x, y, size, size);
|
||||
this.battleShip = battleShip;
|
||||
|
|
@ -78,28 +80,38 @@ public class Turret extends GameObject {
|
|||
@Override
|
||||
public void update() {
|
||||
|
||||
Point msLoc = master.getMouseLocation();
|
||||
Vector2D mouseRel = Coords.getMapCoordsFromWorld(Vector2D.fromPoint(msLoc)); //100 correct
|
||||
|
||||
//TODO getCenter uses the wrong size
|
||||
Vector2D center = battleShip.getMapCoords(getCenterPosition(position));
|
||||
System.out.println(getCenterPosition(position));
|
||||
master.debugPos(battleShip.getMapCoords(position));
|
||||
master.debugPos(center);
|
||||
double targetRotation = -Math.atan2(center.x - mouseRel.x, center.y - mouseRel.y);
|
||||
|
||||
//---------------OLD IMPLEMENTATION
|
||||
Vector2D abs = battleShip.getWorldCoordsFromLocal(position);
|
||||
int sizeAbs = (int) battleShip.getWorldCoordsFromLocalSize(size).x;
|
||||
int xCenterAbs = (int) (abs.x + sizeAbs / 2);
|
||||
int yCenterAbs = (int) (abs.y + sizeAbs / 2);
|
||||
|
||||
Point msLoc = master.getMouseLocation();
|
||||
double targetRotation = -Math.atan2(xCenterAbs - msLoc.x, yCenterAbs - msLoc.y);
|
||||
double targetRotationOld = -Math.atan2(xCenterAbs - msLoc.x, yCenterAbs - msLoc.y);
|
||||
//----------------
|
||||
|
||||
|
||||
rotation = ExMath.angleLerp(rotation, targetRotation, ROTATION_SPEED);
|
||||
|
||||
int barrelSpacing = sizeAbs / (barrelAmount + 1);
|
||||
int barrelSpacing = (int) (size.x / (barrelAmount + 1));
|
||||
|
||||
for (int i = 0; i < barrelAmount; i++) {
|
||||
int barrelX = (int) (abs.x + (i + 1) * barrelSpacing);
|
||||
int frontPosY = (int) (abs.y - sizeAbs / 2);
|
||||
int barrelX = (int) (position.x + (i + 1) * barrelSpacing);
|
||||
int frontPosY = (int) (position.y - size.x / 2);
|
||||
|
||||
if (master.isMousePressed()) {
|
||||
lastShot = System.currentTimeMillis();
|
||||
|
||||
Vector2D shellVel = Vector2D.getUnitVector(rotation).negative().multiply(SHELL_SPEED);
|
||||
Vector2D pos = Vector2D.rotateAround(new Vector2D(xCenterAbs, yCenterAbs), new Vector2D(barrelX, frontPosY), rotation, Vector2D.COUNTERCLOCKWISE);
|
||||
Vector2D pos = Vector2D.rotateAround(new Vector2D(center.x, center.y), new Vector2D(barrelX, frontPosY), rotation, Vector2D.COUNTERCLOCKWISE);
|
||||
|
||||
master.create(new Shell(pos, new Vector2D(10, 10), shellVel));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue