no useless parameters

This commit is contained in:
nora 2020-12-13 12:23:02 +01:00
parent e841bb4188
commit 70610c7c53
18 changed files with 27 additions and 45 deletions

View file

@ -1,7 +1,10 @@
package core;
import java.awt.*;
import java.awt.Graphics2D;
/**
* This interface has to be implemented by every
*/
public interface Drawable {
/**
@ -12,8 +15,6 @@ public interface Drawable {
* <p>This function is <i>NOT</i> intended to be called manually.</p>
*
* @param g2d The {@code Graphics2D} object given by the master
* @param w The width of the screen
* @param master The master object itself
*/
void draw(Graphics2D g2d, int w, Master master);
void draw(Graphics2D g2d);
}

View file

@ -111,7 +111,7 @@ public class Master extends JPanel {
Graphics2D g2d = (Graphics2D) g.create();
drawables.forEach(o -> o.draw(g2d, w, this));
drawables.forEach(o -> o.draw(g2d));
}

View file

@ -149,7 +149,7 @@ public class RectHitBox extends Hitbox {
}
@Override
public void draw(Graphics2D g2d, int w, Master master) {
public void draw(Graphics2D g2d) {
this.w = w;
int h = (int) (w / Master.SCREEN_RATIO);

View file

@ -1,6 +1,5 @@
package objects;
import core.Master;
import core.math.Vector2D;
import java.awt.*;
@ -15,7 +14,7 @@ public class DebugPos extends GameObject {
}
@Override
public void draw(Graphics2D g2d, int w, Master master) {
public void draw(Graphics2D g2d) {
g2d.setPaint(Color.green);
g2d.drawOval((int) (position.x - size.x / 2), (int) (position.y - size.y / 2), (int) size.x, (int) size.y);
}

View file

@ -10,13 +10,10 @@ 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, int, Master)} methods that have to be
* {@link #update()} and {@link #draw(Graphics2D)} methods that have to be
*/
public abstract class GameObject implements Drawable {
protected int w;
protected int h;
protected Vector2D position;
protected Vector2D size;
@ -67,11 +64,8 @@ public abstract class GameObject implements Drawable {
* This method draws a rectangle at the current position and size
*
* @param g2d The Graphics2D object provided by the master
* @param w The width of the screen
*/
public void drawRect(Graphics2D g2d, int w) {
this.w = w;
h = (int) (this.w / Master.SCREEN_RATIO);
public void drawRect(Graphics2D g2d) {
Vector2D abs = Coords.getWorldCoords(position);
Vector2D sizeAbs = Coords.getWorldCoordsSize(size);
@ -83,11 +77,8 @@ public abstract class GameObject implements Drawable {
* This method draws a rectangle at the current position and size
*
* @param g2d The Graphics2D object provided by the master
* @param w The width of the screen
*/
public void drawOval(Graphics2D g2d, int w) {
this.w = w;
h = (int) (this.w / Master.SCREEN_RATIO);
public void drawOval(Graphics2D g2d) {
Vector2D abs = Coords.getWorldCoords(position);
Vector2D sizeAbs = Coords.getWorldCoordsSize(size);
@ -99,13 +90,10 @@ public abstract class GameObject implements Drawable {
* This method draws a rounded rectangle at the current position and size
*
* @param g2d The Graphics2D object provided by the master
* @param w The width of the screen
* @param arcW The arc width of the rectangle
* @param arcH The arc height of the rectangle
*/
public void drawRoundRect(Graphics2D g2d, int w, int arcW, int arcH) {
this.w = w;
h = (int) (w / Master.SCREEN_RATIO);
public void drawRoundRect(Graphics2D g2d, int arcW, int arcH) {
Vector2D abs = Coords.getWorldCoords(position);
Vector2D sizeAbs = Coords.getWorldCoordsSize(size);

View file

@ -1,6 +1,5 @@
package objects.ships;
import core.Master;
import objects.GameObject;
import java.awt.*;
@ -27,10 +26,10 @@ public class BattleShip extends GameObject {
}
@Override
public void draw(Graphics2D g2d, int w, Master master) {
public void draw(Graphics2D g2d) {
drawRoundRect(g2d, w, w/10, w/10);
turrets.forEach((turret -> turret.draw(g2d, w, master)));
drawRoundRect(g2d, master.getW()/10, master.getW()/10);
turrets.forEach((turret -> turret.draw(g2d)));
}
@Override

View file

@ -1,6 +1,5 @@
package objects.ships;
import core.Master;
import core.math.Vector2D;
import objects.GameObject;
@ -15,7 +14,7 @@ public class Shell extends GameObject {
}
@Override
public void draw(Graphics2D g2d, int w, Master master) {
public void draw(Graphics2D g2d) {
g2d.setPaint(Color.orange);
g2d.fillOval((int) position.x, (int) position.y, (int) size.x, (int) size.y);
}

View file

@ -1,7 +1,6 @@
package objects.ships;
import core.Coords;
import core.Master;
import core.math.Vector2D;
import core.physics.Collidable;
import core.physics.Hitbox;
@ -21,9 +20,9 @@ public class Submarine extends GameObject implements Collidable {
}
@Override
public void draw(Graphics2D g2d, int w, Master master) {
public void draw(Graphics2D g2d) {
g2d.setPaint(Color.BLUE);
drawOval(g2d, w);
drawOval(g2d);
}
@Override

View file

@ -1,7 +1,6 @@
package objects.ships;
import core.math.ExMath;
import core.Master;
import core.math.Vector2D;
import objects.GameObject;
@ -42,8 +41,7 @@ public class Turret extends GameObject {
}
@Override
public void draw(Graphics2D g2d, int w, Master master) {
h = w / 16 * 9;
public void draw(Graphics2D g2d) {
g2d.setPaint(mainColor);
Vector2D abs = battleShip.getWorldCoordsFromLocal(position);
int sizeAbs = (int) battleShip.getWorldCoordsFromLocalSize(size).x;

View file

@ -10,23 +10,23 @@ import java.awt.*;
*/
public class Grid extends GameObject {
private final int gridSpacing = 50;
private static final int GRID_SPACING = 50;
public Grid() {
super(0, 0, 0, 0);
}
@Override
public void draw(Graphics2D g2d, int w, Master master) {
public void draw(Graphics2D g2d) {
g2d.setPaint(Color.LIGHT_GRAY);
this.w = w;
h = w/16*9;
int w = master.getW();
int h = w/16*9;
g2d.drawRect(0, 0, w, h);
int verticalLines = w / gridSpacing;
int horizontalLines = h / gridSpacing;
int verticalLines = w / GRID_SPACING;
int horizontalLines = h / GRID_SPACING;
for (int i = 0; i < horizontalLines; i++) {
int y = i * h / horizontalLines;

View file

@ -1,6 +1,5 @@
package objects.world;
import core.Master;
import core.math.Vector2D;
import core.physics.Collidable;
import core.physics.Hitbox;
@ -19,8 +18,8 @@ public class Wall extends GameObject implements Collidable {
}
@Override
public void draw(Graphics2D g2d, int w, Master master) {
drawRect(g2d, w);
public void draw(Graphics2D g2d) {
drawRect(g2d);
}
@Override