mirror of
https://github.com/Noratrieb/Java2DGame.git
synced 2026-01-14 14:05:01 +01:00
fixed size scaling
This commit is contained in:
parent
adb8e185fb
commit
e841bb4188
11 changed files with 12 additions and 13 deletions
|
|
@ -42,7 +42,7 @@ public class Coords {
|
||||||
|
|
||||||
public static Vector2D getWorldCoordsSize(Vector2D value) {
|
public static Vector2D getWorldCoordsSize(Vector2D value) {
|
||||||
//TODO h not w
|
//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());
|
double y = (value.y / Master.SCREEN_Y_COORDINATES * master.getH());
|
||||||
return new Vector2D(x, y);
|
return new Vector2D(x, y);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,7 @@ public class Master extends JPanel {
|
||||||
|
|
||||||
|
|
||||||
BattleShip battleShip = new BattleShip(Color.DARK_GRAY);
|
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++) {
|
/*for (int i = 0; i < 10; i++) {
|
||||||
bs.addTurret(new Turret(bs, 25, 10 * i + 1, 50, i % 5));
|
bs.addTurret(new Turret(bs, 25, 10 * i + 1, 50, i % 5));
|
||||||
}*/
|
}*/
|
||||||
|
|
|
||||||
|
|
@ -11,12 +11,11 @@ import java.util.ArrayList;
|
||||||
*/
|
*/
|
||||||
public class BattleShip extends GameObject {
|
public class BattleShip extends GameObject {
|
||||||
|
|
||||||
private ArrayList<Turret> turrets;
|
private final ArrayList<Turret> turrets;
|
||||||
|
|
||||||
public BattleShip(Color mainColor) {
|
public BattleShip(Color mainColor) {
|
||||||
this(20, 20, 5, 40, mainColor);
|
this(20, 20, 10, 40, mainColor);
|
||||||
//TODO child x coords 100 not 100*16/9
|
turrets.add(new Turret(this, 25, 25, 50, 3));
|
||||||
turrets.add(new Turret(this, 100*16/9d/4, 25, 50, 3));
|
|
||||||
//turrets.add(new Turret(this, 25, 10, 50, 2));
|
//turrets.add(new Turret(this, 25, 10, 50, 2));
|
||||||
//turrets.add(new Turret(this, 25, 70, 50, 2));
|
//turrets.add(new Turret(this, 25, 70, 50, 2));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ import java.awt.*;
|
||||||
|
|
||||||
public class Submarine extends GameObject implements Collidable {
|
public class Submarine extends GameObject implements Collidable {
|
||||||
|
|
||||||
private RectHitBox hitbox;
|
private final RectHitBox hitbox;
|
||||||
|
|
||||||
public Submarine(Vector2D position, Vector2D size) {
|
public Submarine(Vector2D position, Vector2D size) {
|
||||||
super(position, size);
|
super(position, size);
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ public class Turret extends GameObject {
|
||||||
|
|
||||||
private double rotation;
|
private double rotation;
|
||||||
|
|
||||||
private Color mainColor;
|
private final Color mainColor;
|
||||||
|
|
||||||
private long lastShot = 0;
|
private long lastShot = 0;
|
||||||
|
|
||||||
|
|
@ -50,7 +50,7 @@ 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);
|
||||||
|
|
||||||
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,
|
g2d.setStroke(new BasicStroke((int) battleShip.getWorldCoordsFromLocalSize(new Vector2D(10, 0)).x, BasicStroke.CAP_BUTT,
|
||||||
BasicStroke.JOIN_BEVEL));
|
BasicStroke.JOIN_BEVEL));
|
||||||
|
|
@ -58,7 +58,7 @@ public class Turret extends GameObject {
|
||||||
//BARRELS---------------------------------------
|
//BARRELS---------------------------------------
|
||||||
|
|
||||||
g2d.setPaint(Color.BLACK);
|
g2d.setPaint(Color.BLACK);
|
||||||
int barrelSpacing = (int) (sizeAbs / (barrelAmount + 1));
|
int barrelSpacing = sizeAbs / (barrelAmount + 1);
|
||||||
g2d.rotate(rotation, xCenterAbs, yCenterAbs);
|
g2d.rotate(rotation, xCenterAbs, yCenterAbs);
|
||||||
|
|
||||||
for (int i = 0; i < barrelAmount; i++) {
|
for (int i = 0; i < barrelAmount; i++) {
|
||||||
|
|
@ -91,7 +91,7 @@ public class Turret extends GameObject {
|
||||||
|
|
||||||
rotation = ExMath.angleLerp(rotation, targetRotation, ROTATION_SPEED);
|
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++) {
|
for (int i = 0; i < barrelAmount; i++) {
|
||||||
int barrelX = (int) (abs.x + (i + 1) * barrelSpacing);
|
int barrelX = (int) (abs.x + (i + 1) * barrelSpacing);
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import java.awt.*;
|
||||||
*/
|
*/
|
||||||
public class Grid extends GameObject {
|
public class Grid extends GameObject {
|
||||||
|
|
||||||
private int gridSpacing = 50;
|
private final int gridSpacing = 50;
|
||||||
|
|
||||||
public Grid() {
|
public Grid() {
|
||||||
super(0, 0, 0, 0);
|
super(0, 0, 0, 0);
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ import java.awt.*;
|
||||||
|
|
||||||
public class Wall extends GameObject implements Collidable {
|
public class Wall extends GameObject implements Collidable {
|
||||||
|
|
||||||
private RectHitBox hitbox;
|
private final RectHitBox hitbox;
|
||||||
|
|
||||||
public Wall(double x, double y, double xSize, double ySize) {
|
public Wall(double x, double y, double xSize, double ySize) {
|
||||||
super(x, y, xSize, ySize);
|
super(x, y, xSize, ySize);
|
||||||
|
|
|
||||||
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