diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..26d3352
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,3 @@
+# Default ignored files
+/shelf/
+/workspace.xml
diff --git a/.idea/.name b/.idea/.name
new file mode 100644
index 0000000..4bd3a9a
--- /dev/null
+++ b/.idea/.name
@@ -0,0 +1 @@
+2DGame
\ No newline at end of file
diff --git a/.idea/Java2DGame.iml b/.idea/Java2DGame.iml
new file mode 100644
index 0000000..78b2cc5
--- /dev/null
+++ b/.idea/Java2DGame.iml
@@ -0,0 +1,2 @@
+
+
\ No newline at end of file
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 0000000..c2cf4bf
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/discord.xml b/.idea/discord.xml
new file mode 100644
index 0000000..cd711a0
--- /dev/null
+++ b/.idea/discord.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
new file mode 100644
index 0000000..c2bae49
--- /dev/null
+++ b/.idea/encodings.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
new file mode 100644
index 0000000..c8a1523
--- /dev/null
+++ b/.idea/jarRepositories.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/2DGame.xml b/.idea/libraries/2DGame.xml
new file mode 100644
index 0000000..6866d02
--- /dev/null
+++ b/.idea/libraries/2DGame.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..0f9e86a
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml
new file mode 100644
index 0000000..e96534f
--- /dev/null
+++ b/.idea/uiDesigner.xml
@@ -0,0 +1,124 @@
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/2DGame.iml b/2DGame.iml
new file mode 100644
index 0000000..78b2cc5
--- /dev/null
+++ b/2DGame.iml
@@ -0,0 +1,2 @@
+
+
\ No newline at end of file
diff --git a/2DGame.zip b/2DGame.zip
deleted file mode 100644
index 0e7bf77..0000000
Binary files a/2DGame.zip and /dev/null differ
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..bb8f0f3
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,31 @@
+
+
+ 4.0.0
+
+ org.example
+ 2DGame
+ 1.0-SNAPSHOT
+
+
+ 14
+ 14
+
+
+
+ org.junit.jupiter
+ junit-jupiter-api
+ 5.6.1
+ test
+
+
+ org.junit.jupiter
+ junit-jupiter-engine
+ 5.6.1
+ test
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/BasicEx.java b/src/main/java/BasicEx.java
new file mode 100644
index 0000000..eaca85b
--- /dev/null
+++ b/src/main/java/BasicEx.java
@@ -0,0 +1,47 @@
+import core.Master;
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+
+class BasicEx extends JFrame {
+
+ Master master;
+ Timer timer;
+
+ public BasicEx() {
+ initUI();
+ timer = new Timer(1000/60, e -> {
+ master.refresh();
+ });
+ timer.start();
+ }
+
+ private void initUI() {
+
+ master = new Master();
+ add(master);
+
+ setTitle("Points");
+ setSize(1600, 900);
+ setLocationRelativeTo(null);
+ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+
+ addMouseListener(new MouseAdapter() {
+ @Override
+ public void mousePressed(MouseEvent e) {
+ master.mousePressed();
+ }
+ });
+ }
+
+ public static void main(String[] args) {
+
+ EventQueue.invokeLater(() -> {
+
+ BasicEx ex = new BasicEx();
+ ex.setVisible(true);
+ });
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/core/Master.java b/src/main/java/core/Master.java
new file mode 100644
index 0000000..f739bd8
--- /dev/null
+++ b/src/main/java/core/Master.java
@@ -0,0 +1,123 @@
+package core;
+
+import objects.DebugPos;
+import objects.ships.BattleShip;
+import objects.GameObject;
+import objects.world.Grid;
+
+import javax.swing.*;
+import java.awt.*;
+import java.util.ArrayList;
+
+/**
+ * The main object that controls everything
+ */
+public class Master extends JPanel {
+
+ /**
+ * All GameObjects that exist
+ */
+ private final ArrayList objects;
+
+ /**
+ * Stores all GameObjects that were created during a frame
+ */
+ private final ArrayList objectBuffer;
+
+ private boolean mousePressed = false;
+
+ /**
+ * Create a new master object
+ */
+ public Master() {
+ objects = new ArrayList<>();
+ objectBuffer = new ArrayList<>();
+
+ objects.add(new Grid());
+
+
+ BattleShip battleShip = new BattleShip(Color.DARK_GRAY);
+ BattleShip bs = new BattleShip(70, 10, 5, 80, Color.GREEN);
+ /*for (int i = 0; i < 10; i++) {
+ bs.addTurret(new Turret(bs, 25, 10 * i + 1, 50, i % 5));
+ }*/
+ objects.add(bs);
+ objects.add(battleShip);
+ }
+
+ /**
+ * The mein drawing method, handles everything about drawing
+ * @param g
+ */
+ private void doDrawing(Graphics g) {
+
+ //TODO w/h fields
+ int w, h;
+ if (getWidth() * 9 > getHeight() * 16) {
+ h = getHeight();
+ w = h / 9 * 16;
+ } else {
+ w = getWidth();
+ h = w / 16 * 9;
+ }
+
+ Graphics2D g2d = (Graphics2D) g.create();
+
+ objects.forEach(o -> o.draw(g2d, w, this));
+ }
+
+
+ @Override
+ public void paintComponent(Graphics g) {
+ super.paintComponent(g);
+ doDrawing(g);
+ }
+
+ /**
+ * Debug a position, creates a green dot at the position
+ * @param pos
+ */
+ public void debugPos(Vector2D pos){
+ create(new DebugPos(pos, new Vector2D(10, 10)));
+ }
+
+ /**
+ * Call this method when the user pressed the left mouse button
+ */
+ public void mousePressed() {
+ mousePressed = true;
+ }
+
+ /**
+ * This method is the entry method for each frame. It handles everything about the frame
+ */
+ public void refresh() {
+ objects.addAll(objectBuffer);
+ objectBuffer.clear();
+ objects.forEach(t -> t.update(this));
+ mousePressed = false;
+ repaint();
+ }
+
+ /**
+ * Get the current location of the mouse relative to the frame
+ * @return The location of the mouse, already normalized
+ */
+ public Point getMouseLocation() {
+ Point p = MouseInfo.getPointerInfo().getLocation();
+ SwingUtilities.convertPointFromScreen(p, this);
+ return p;
+ }
+
+ public boolean isMousePressed() {
+ return mousePressed;
+ }
+
+ /**
+ * This method has to be called for every newly created GameObject
+ * @param obj
+ */
+ public void create(GameObject obj) {
+ objectBuffer.add(obj);
+ }
+}
diff --git a/src/main/java/core/Vector2D.java b/src/main/java/core/Vector2D.java
new file mode 100644
index 0000000..26167fc
--- /dev/null
+++ b/src/main/java/core/Vector2D.java
@@ -0,0 +1,158 @@
+package core;
+
+/**
+ * A 2-dimensional Vector that can be used to store position or velocity
+ */
+public class Vector2D {
+
+ public static final int CLOCKWISE = -1;
+ public static final int COUNTERCLOCKWISE = 1;
+
+ /**
+ * The x and y values of the vector
+ */
+ public double x, y;
+
+ /**
+ * Create a new Vector2D object
+ *
+ * @param x the x value
+ * @param y the y value
+ */
+ public Vector2D(double x, double y) {
+ this.x = x;
+ this.y = y;
+ }
+
+ /**
+ * Create a new empty Vector2D object
+ */
+ public Vector2D() {
+ x = 0;
+ y = 0;
+ }
+
+ /**
+ * Add another Vector to this vector, modifies this object
+ *
+ * @param a The other Vector2D
+ * @return this after the addition
+ */
+ public Vector2D add(Vector2D a) {
+ x += a.x;
+ y += a.y;
+ return this;
+ }
+
+ /**
+ * Mulitply this vector with a simple scalar, modifies this object
+ *
+ * @param a The scalar
+ * @return this after the multiplication
+ */
+ public Vector2D multiply(double a) {
+ x *= a;
+ y *= a;
+ return this;
+ }
+
+ /**
+ * Get the magnitude of the vector
+ *
+ * @return The magnitude of this vector
+ */
+ public double magnitude() {
+ return Math.sqrt(x * x + y * y);
+ }
+
+ /**
+ * Get the normalized value of this vector, with magnitude 1, does not modify this object
+ *
+ * @return The normalized value
+ */
+ public Vector2D normalized() {
+ double mag = magnitude();
+ if (mag == 0) {
+ return new Vector2D();
+ } else {
+ return new Vector2D(x / mag, y / mag);
+ }
+ }
+
+ /**
+ * Get the negative value of this vector, does not modify this object
+ *
+ * @return The negative value
+ */
+ public Vector2D negative() {
+ return new Vector2D(-x, -y);
+ }
+
+
+ /**
+ * Add two Vectors
+ * @param a Vector a
+ * @param b Vector b
+ * @return The result
+ */
+ public static Vector2D add(Vector2D a, Vector2D b) {
+ return new Vector2D(a.x + b.x, a.y + b.y);
+ }
+
+ /**
+ * Subtract two Vectors
+ * @param a Vector a
+ * @param b Vector b
+ * @return The result
+ */
+ public static Vector2D subtract(Vector2D a, Vector2D b) {
+ return new Vector2D(a.x - b.x, a.y - b.y);
+ }
+
+ /**
+ * Rotate a point around another point
+ * @param center The center of the rotation
+ * @param value The point to be rotated, absolut to the center
+ * @param rotation The rotation angle in radians
+ * @param rotationDirection The direction, -1 for clockwise, 1 for counterclockwise
+ * @return The rotated point
+ */
+ public static Vector2D rotateAround(Vector2D center, Vector2D value, double rotation, int rotationDirection){
+
+ Vector2D dif = Vector2D.subtract(value, center);
+
+ double rotatedX = Math.cos(rotation * rotationDirection) * dif.x;
+ double rotatedY = Math.sin(rotation * rotationDirection) * dif.x;
+
+ return new Vector2D(rotatedX + center.x, rotatedY + center.y);
+ }
+
+ public Vector2D copy(){
+ return new Vector2D(x, y);
+ }
+
+ @Override
+ public String toString() {
+ return "Vector2D{" +
+ "x=" + x +
+ ", y=" + y +
+ '}';
+ }
+
+ /**
+ * Overrides the equals method. True when the x and y values match
+ *
+ * @param o The other Vector
+ * @return True if both x and values are the same
+ */
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+
+ Vector2D vector2D = (Vector2D) o;
+
+ if (Double.compare(vector2D.x, x) != 0) return false;
+ return Double.compare(vector2D.y, y) == 0;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/objects/DebugPos.java b/src/main/java/objects/DebugPos.java
new file mode 100644
index 0000000..0a8c248
--- /dev/null
+++ b/src/main/java/objects/DebugPos.java
@@ -0,0 +1,26 @@
+package objects;
+
+import core.Master;
+import core.Vector2D;
+
+import java.awt.*;
+
+/**
+ * A GameObject used for debugging
+ */
+public class DebugPos extends GameObject {
+ public DebugPos(Vector2D position, Vector2D size) {
+ super(position.copy(), size);
+ this.velocity = new Vector2D();
+ }
+
+ @Override
+ public void draw(Graphics2D g2d, int w, Master master) {
+ g2d.setPaint(Color.green);
+ g2d.drawOval((int) (position.x + size.x / 2), (int) (position.y + size.y / 2), (int) size.x, (int) size.y);
+ }
+
+ @Override
+ public void update(Master master) {
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/objects/GameObject.java b/src/main/java/objects/GameObject.java
new file mode 100644
index 0000000..fe7bb84
--- /dev/null
+++ b/src/main/java/objects/GameObject.java
@@ -0,0 +1,67 @@
+package objects;
+
+import core.Master;
+import core.Vector2D;
+
+import java.awt.*;
+
+/**
+ * The GameObject class is the superclass of every GameObject that can be displayed on screen. It has the 2
+ * {@link #update(Master)} and {@link #draw(Graphics2D, int, Master)} methods that have to be
+ */
+public abstract class GameObject {
+
+ protected int w;
+ protected int h;
+
+ protected Vector2D position;
+ protected Vector2D size;
+
+ protected Vector2D velocity;
+
+ public GameObject(double x, double y, double xSize, double ySize) {
+ this(new Vector2D(x, y), new Vector2D(xSize, ySize));
+ }
+
+ public GameObject(Vector2D position, Vector2D size) {
+ this.position = position;
+ this.size = size;
+ this.velocity = new Vector2D();
+ }
+
+ public abstract void draw(Graphics2D g2d, int w, Master master);
+ public abstract void update(Master master);
+
+
+ public double getMapCoords(double value, boolean isX){
+ if (isX){
+ return (position.x + value / 100 * size.x);
+ } else {
+ return (position.y + value / 100 * size.y);
+ }
+ }
+
+ public double getMapCoordsSize(double value, boolean useX){
+ if (useX){
+ return (value / 100 * size.x);
+ } else {
+ return (value / 100 * size.y);
+ }
+ }
+
+ public double getWorldCoords(double value, boolean isX){
+ if (isX){
+ return (value / 100 * w);
+ } else {
+ return (value / 100 * h);
+ }
+ }
+
+ public int getWorldCoordsFromLocal(double value, boolean isX){
+ return (int) getWorldCoords(getMapCoords(value, isX), isX);
+ }
+
+ public int getWorldCoordsFromLocalSize(double value, boolean useX){
+ return (int) getWorldCoords(getMapCoordsSize(value, useX), useX);
+ }
+}
diff --git a/src/main/java/objects/ships/BattleShip.java b/src/main/java/objects/ships/BattleShip.java
new file mode 100644
index 0000000..16b0eef
--- /dev/null
+++ b/src/main/java/objects/ships/BattleShip.java
@@ -0,0 +1,54 @@
+package objects.ships;
+
+import core.Master;
+import objects.GameObject;
+
+import java.awt.*;
+import java.util.ArrayList;
+
+/**
+ * A Battleship that can have several turrets
+ */
+public class BattleShip extends GameObject {
+
+ private Color mainColor;
+ private ArrayList turrets;
+
+ public BattleShip(Color mainColor) {
+ super(20, 20, 5, 40);
+ turrets = new ArrayList<>();
+ turrets.add(new Turret(this, 25, 25, 50, 1));
+ //turrets.add(new Turret(this, 25, 10, 50, 2));
+ //turrets.add(new Turret(this, 25, 70, 50, 2));
+ this.mainColor = mainColor;
+ }
+
+ public BattleShip(double x, double y, double xSize, double ySize, Color mainColor) {
+ super(x, y, xSize, ySize);
+ turrets = new ArrayList<>();
+ this.mainColor = mainColor;
+ }
+
+ @Override
+ public void draw(Graphics2D g2d, int w, Master master) {
+ this.w = w;
+ h = w/16*9;
+ g2d.setPaint(mainColor);
+ int xAbs = (int) getWorldCoords(position.x, true);
+ int yAbs = (int) getWorldCoords(position.y, false);
+ int sizeXAbs = (int) getWorldCoords(size.x, true);
+ int sizeYAbs = (int) getWorldCoords(size.y, false);
+ g2d.fillRoundRect(xAbs, yAbs, sizeXAbs, sizeYAbs, w/10, w/10);
+
+ turrets.forEach((turret -> turret.draw(g2d, w, master)));
+ }
+
+ @Override
+ public void update(Master master) {
+ turrets.forEach((turret -> turret.update(master)));
+ }
+
+ public void addTurret(Turret turret){
+ turrets.add(turret);
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/objects/ships/Shell.java b/src/main/java/objects/ships/Shell.java
new file mode 100644
index 0000000..938c54b
--- /dev/null
+++ b/src/main/java/objects/ships/Shell.java
@@ -0,0 +1,27 @@
+package objects.ships;
+
+import core.Master;
+import core.Vector2D;
+import objects.GameObject;
+
+import java.awt.*;
+
+public class Shell extends GameObject {
+
+
+ public Shell(Vector2D position, Vector2D size, Vector2D velocity) {
+ super(position, size);
+ this.velocity = velocity;
+ }
+
+ @Override
+ public void draw(Graphics2D g2d, int w, Master master) {
+ g2d.setPaint(Color.orange);
+ g2d.fillOval((int) position.x, (int) position.y, (int) size.x, (int) size.y);
+ }
+
+ @Override
+ public void update(Master master) {
+ position.add(velocity);
+ }
+}
diff --git a/src/main/java/objects/ships/Turret.java b/src/main/java/objects/ships/Turret.java
new file mode 100644
index 0000000..35b68c4
--- /dev/null
+++ b/src/main/java/objects/ships/Turret.java
@@ -0,0 +1,103 @@
+package objects.ships;
+
+import core.Master;
+import core.Vector2D;
+import objects.GameObject;
+
+import java.awt.*;
+
+/**
+ * A Turret that can shoot projectiles
+ */
+public class Turret extends GameObject {
+
+ BattleShip battleShip;
+
+ private int barrelAmount = 3;
+
+ private Color mainColor;
+
+ private long lastShot = 0;
+ private static int SHOT_EFFECT_TIME = 300;
+ private static int SHELL_SPEED = 10;
+ private double rotation;
+
+ public Turret(BattleShip battleShip, double x, double y, double size, int barrelAmount) {
+ super(x, y, size, size);
+ this.battleShip = battleShip;
+ this.barrelAmount = barrelAmount;
+ mainColor = Color.GRAY;
+ }
+
+ public Turret(BattleShip battleShip) {
+ super(25, 50, 50, 50);
+ this.battleShip = battleShip;
+ mainColor = Color.GRAY;
+ }
+
+ @Override
+ public void draw(Graphics2D g2d, int w, Master master) {
+ //TODO draw should be draw only for better everything
+ h = w / 16 * 9;
+ g2d.setPaint(mainColor);
+ int xAbs = battleShip.getWorldCoordsFromLocal(position.x, true);
+ int yAbs = battleShip.getWorldCoordsFromLocal(position.y, false);
+ int sizeAbs = battleShip.getWorldCoordsFromLocalSize(size.x, true);
+ int xCenterAbs = xAbs + sizeAbs / 2;
+ int yCenterAbs = yAbs + sizeAbs / 2;
+
+ g2d.fillOval(xAbs, yAbs, sizeAbs, sizeAbs);
+
+ g2d.setStroke(new BasicStroke(battleShip.getWorldCoordsFromLocalSize(10, true), BasicStroke.CAP_BUTT,
+ BasicStroke.JOIN_BEVEL));
+
+ //BARRELS---------------------------------------
+
+ g2d.setPaint(Color.BLACK);
+ int barrelSpacing = sizeAbs / (barrelAmount + 1);
+ g2d.rotate(rotation, xCenterAbs, yCenterAbs);
+ for (int i = 0; i < barrelAmount; i++) {
+ int barrelX = xAbs + (i + 1) * barrelSpacing;
+ int frontPosY = yAbs - sizeAbs / 2;
+ g2d.drawLine(barrelX, yCenterAbs, barrelX, frontPosY);
+
+ if (lastShot + SHOT_EFFECT_TIME > System.currentTimeMillis()) {
+ g2d.setPaint(Color.YELLOW);
+ g2d.fillOval(barrelX - 5, frontPosY - 5, 10, 10);
+ g2d.setPaint(Color.BLACK);
+ }
+ }
+ g2d.rotate(-rotation, xCenterAbs, yCenterAbs);
+ }
+
+ @Override
+ public void update(Master master) {
+
+ int xAbs = battleShip.getWorldCoordsFromLocal(position.x, true);
+ int yAbs = battleShip.getWorldCoordsFromLocal(position.y, false);
+ int sizeAbs = battleShip.getWorldCoordsFromLocalSize(size.x, true);
+ int xCenterAbs = xAbs + sizeAbs / 2;
+ int yCenterAbs = yAbs + sizeAbs / 2;
+
+ Point msLoc = master.getMouseLocation();
+ rotation = -Math.atan2(xCenterAbs - msLoc.x, yCenterAbs - msLoc.y);
+
+ int barrelSpacing = sizeAbs / (barrelAmount + 1);
+
+ for (int i = 0; i < barrelAmount; i++) {
+ int barrelX = xAbs + (i + 1) * barrelSpacing;
+ int frontPosY = yAbs - sizeAbs / 2;
+
+ if (master.isMousePressed()) {
+ lastShot = System.currentTimeMillis();
+
+ Vector2D shellVel = new Vector2D(xCenterAbs - msLoc.x, yCenterAbs - msLoc.y).normalized().negative().multiply(SHELL_SPEED);
+ Vector2D pos = Vector2D.rotateAround(new Vector2D(xCenterAbs, yCenterAbs), new Vector2D(barrelX, frontPosY), rotation, Vector2D.CLOCKWISE);
+
+ master.debugPos(pos);
+
+ master.create(new Shell(pos, new Vector2D(10, 10), shellVel));
+ }
+ }
+ }
+}
diff --git a/src/main/java/objects/world/Grid.java b/src/main/java/objects/world/Grid.java
new file mode 100644
index 0000000..083ad96
--- /dev/null
+++ b/src/main/java/objects/world/Grid.java
@@ -0,0 +1,47 @@
+package objects.world;
+
+import core.Master;
+import objects.GameObject;
+
+import java.awt.*;
+
+/**
+ * A basic background grid
+ */
+public class Grid extends GameObject {
+
+ private int gridSpacing = 50;
+
+ public Grid() {
+ super(0, 0, 0, 0);
+ }
+
+ @Override
+ public void draw(Graphics2D g2d, int w, Master master) {
+ g2d.setPaint(Color.LIGHT_GRAY);
+
+ this.w = w;
+ h = w/16*9;
+
+ g2d.drawRect(0, 0, w, h);
+
+ int verticalLines = w / gridSpacing;
+ int horizontalLines = h / gridSpacing;
+
+ for (int i = 0; i < horizontalLines; i++) {
+ int y = i * h / horizontalLines;
+ g2d.drawLine(0, y, w, y);
+ }
+
+ for (int i = 0; i < verticalLines; i++) {
+ int x = i * w / verticalLines;
+ g2d.drawLine(x, 0, x, h);
+ }
+
+ }
+
+ @Override
+ public void update(Master master) {
+
+ }
+}
diff --git a/src/test/java/core/Vector2DTest.java b/src/test/java/core/Vector2DTest.java
new file mode 100644
index 0000000..e8a20a8
--- /dev/null
+++ b/src/test/java/core/Vector2DTest.java
@@ -0,0 +1,60 @@
+package core;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+class Vector2DTest {
+
+
+ @Test
+ void addOK() {
+ Vector2D a = new Vector2D(1, 2);
+ Vector2D b = new Vector2D(1, 2);
+ Vector2D c = new Vector2D(-1 ,-1);
+ Vector2D d = new Vector2D(0, 1);
+
+ assertEquals(new Vector2D(2, 4), Vector2D.add(a, b));
+ assertEquals(new Vector2D(0, 1), Vector2D.add(a, c));
+ assertEquals(new Vector2D(-1, 0), Vector2D.add(c, d));
+ }
+
+ @Test
+ void normalized() {
+ Vector2D a = new Vector2D(1, 1);
+ Vector2D b = new Vector2D(1, 0);
+
+ assertEquals(new Vector2D(1 / Math.sqrt(2), 1 / Math.sqrt(2)), a.normalized());
+ assertEquals(new Vector2D(1,0), b.normalized());
+ }
+
+ @Test
+ void subtractOK() {
+ Vector2D a = new Vector2D(1, 2);
+ Vector2D b = new Vector2D(1, 2);
+ Vector2D c = new Vector2D(-1 ,-1);
+ Vector2D d = new Vector2D(0, 1);
+
+ assertEquals(new Vector2D(0, 0), Vector2D.subtract(a, b));
+ assertEquals(new Vector2D(2, 3), Vector2D.subtract(a, c));
+ assertEquals(new Vector2D(-1, -2), Vector2D.subtract(c, d));
+ }
+
+ @Test
+ void rotateAroundTest(){
+ Vector2D cent = new Vector2D(0, 0);
+ Vector2D a = new Vector2D(1, 0);
+ Vector2D exceptedA = new Vector2D(6.123233995736766E-17 ,-1); //floating point precision probably
+
+ Vector2D centB = new Vector2D(1, 1);
+ Vector2D b = new Vector2D(2, 1);
+ Vector2D exceptedB = new Vector2D(1 ,2);
+
+
+ Vector2D rotated = Vector2D.rotateAround(cent, a, Math.toRadians(90), Vector2D.CLOCKWISE);
+ Vector2D rotatedb = Vector2D.rotateAround(centB, b, Math.toRadians(90), Vector2D.COUNTERCLOCKWISE);
+
+ assertEquals(exceptedA, rotated);
+ assertEquals(exceptedB, rotatedb);
+ }
+}
\ No newline at end of file
diff --git a/target/classes/BasicEx$1.class b/target/classes/BasicEx$1.class
new file mode 100644
index 0000000..fd3f4b9
Binary files /dev/null and b/target/classes/BasicEx$1.class differ
diff --git a/target/classes/BasicEx.class b/target/classes/BasicEx.class
new file mode 100644
index 0000000..296712b
Binary files /dev/null and b/target/classes/BasicEx.class differ
diff --git a/target/classes/core/Master.class b/target/classes/core/Master.class
new file mode 100644
index 0000000..a5ff27c
Binary files /dev/null and b/target/classes/core/Master.class differ
diff --git a/target/classes/core/Vector2D.class b/target/classes/core/Vector2D.class
new file mode 100644
index 0000000..28de856
Binary files /dev/null and b/target/classes/core/Vector2D.class differ
diff --git a/target/classes/objects/DebugPos.class b/target/classes/objects/DebugPos.class
new file mode 100644
index 0000000..3994bf6
Binary files /dev/null and b/target/classes/objects/DebugPos.class differ
diff --git a/target/classes/objects/GameObject.class b/target/classes/objects/GameObject.class
new file mode 100644
index 0000000..533e792
Binary files /dev/null and b/target/classes/objects/GameObject.class differ
diff --git a/target/classes/objects/ships/BattleShip.class b/target/classes/objects/ships/BattleShip.class
new file mode 100644
index 0000000..1867366
Binary files /dev/null and b/target/classes/objects/ships/BattleShip.class differ
diff --git a/target/classes/objects/ships/Shell.class b/target/classes/objects/ships/Shell.class
new file mode 100644
index 0000000..3f2a361
Binary files /dev/null and b/target/classes/objects/ships/Shell.class differ
diff --git a/target/classes/objects/ships/Turret.class b/target/classes/objects/ships/Turret.class
new file mode 100644
index 0000000..2cc59bb
Binary files /dev/null and b/target/classes/objects/ships/Turret.class differ
diff --git a/target/classes/objects/world/Grid.class b/target/classes/objects/world/Grid.class
new file mode 100644
index 0000000..52de6aa
Binary files /dev/null and b/target/classes/objects/world/Grid.class differ
diff --git a/target/test-classes/core/Vector2DTest.class b/target/test-classes/core/Vector2DTest.class
new file mode 100644
index 0000000..d89748d
Binary files /dev/null and b/target/test-classes/core/Vector2DTest.class differ