fixed size scaling

This commit is contained in:
nora 2020-12-13 12:13:27 +01:00
parent adb8e185fb
commit e841bb4188
11 changed files with 12 additions and 13 deletions

View file

@ -42,7 +42,7 @@ public class Coords {
public static Vector2D getWorldCoordsSize(Vector2D value) {
//TODO h not w
double x = (value.x / Master.SCREEN_Y_COORDINATES * master.getW());
double x = (value.x / Master.SCREEN_Y_COORDINATES * master.getH());
double y = (value.y / Master.SCREEN_Y_COORDINATES * master.getH());
return new Vector2D(x, y);
}

View file

@ -79,7 +79,7 @@ public class Master extends JPanel {
BattleShip battleShip = new BattleShip(Color.DARK_GRAY);
BattleShip bs = new BattleShip(70, 10, 5, 80, Color.GREEN);
BattleShip bs = new BattleShip(140, 10, 10, 80, Color.GREEN);
/*for (int i = 0; i < 10; i++) {
bs.addTurret(new Turret(bs, 25, 10 * i + 1, 50, i % 5));
}*/

View file

@ -11,12 +11,11 @@ import java.util.ArrayList;
*/
public class BattleShip extends GameObject {
private ArrayList<Turret> turrets;
private final ArrayList<Turret> turrets;
public BattleShip(Color mainColor) {
this(20, 20, 5, 40, mainColor);
//TODO child x coords 100 not 100*16/9
turrets.add(new Turret(this, 100*16/9d/4, 25, 50, 3));
this(20, 20, 10, 40, mainColor);
turrets.add(new Turret(this, 25, 25, 50, 3));
//turrets.add(new Turret(this, 25, 10, 50, 2));
//turrets.add(new Turret(this, 25, 70, 50, 2));
}

View file

@ -12,7 +12,7 @@ import java.awt.*;
public class Submarine extends GameObject implements Collidable {
private RectHitBox hitbox;
private final RectHitBox hitbox;
public Submarine(Vector2D position, Vector2D size) {
super(position, size);

View file

@ -22,7 +22,7 @@ public class Turret extends GameObject {
private double rotation;
private Color mainColor;
private final Color mainColor;
private long lastShot = 0;
@ -50,7 +50,7 @@ public class Turret extends GameObject {
int xCenterAbs = (int) (abs.x + sizeAbs / 2);
int yCenterAbs = (int) (abs.y + sizeAbs / 2);
g2d.fillOval((int) abs.x, (int) abs.y, (int) sizeAbs, (int) sizeAbs);
g2d.fillOval((int) abs.x, (int) abs.y, sizeAbs, sizeAbs);
g2d.setStroke(new BasicStroke((int) battleShip.getWorldCoordsFromLocalSize(new Vector2D(10, 0)).x, BasicStroke.CAP_BUTT,
BasicStroke.JOIN_BEVEL));
@ -58,7 +58,7 @@ public class Turret extends GameObject {
//BARRELS---------------------------------------
g2d.setPaint(Color.BLACK);
int barrelSpacing = (int) (sizeAbs / (barrelAmount + 1));
int barrelSpacing = sizeAbs / (barrelAmount + 1);
g2d.rotate(rotation, xCenterAbs, yCenterAbs);
for (int i = 0; i < barrelAmount; i++) {
@ -91,7 +91,7 @@ public class Turret extends GameObject {
rotation = ExMath.angleLerp(rotation, targetRotation, ROTATION_SPEED);
int barrelSpacing = (int) (sizeAbs / (barrelAmount + 1));
int barrelSpacing = sizeAbs / (barrelAmount + 1);
for (int i = 0; i < barrelAmount; i++) {
int barrelX = (int) (abs.x + (i + 1) * barrelSpacing);

View file

@ -10,7 +10,7 @@ import java.awt.*;
*/
public class Grid extends GameObject {
private int gridSpacing = 50;
private final int gridSpacing = 50;
public Grid() {
super(0, 0, 0, 0);

View file

@ -11,7 +11,7 @@ import java.awt.*;
public class Wall extends GameObject implements Collidable {
private RectHitBox hitbox;
private final RectHitBox hitbox;
public Wall(double x, double y, double xSize, double ySize) {
super(x, y, xSize, ySize);

Binary file not shown.