mirror of
https://github.com/Noratrieb/Java2DGame.git
synced 2026-01-14 14:05:01 +01:00
RenderEngine now uses Renderer directly
This commit is contained in:
parent
39558c94c7
commit
01f76d5c51
27 changed files with 271 additions and 227 deletions
|
|
@ -25,6 +25,7 @@ class Main extends JFrame {
|
|||
private void initUI() {
|
||||
|
||||
master = new Master();
|
||||
master.init();
|
||||
add(master.getRenderEngine());
|
||||
|
||||
Init.init();
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
package core.general;
|
||||
|
||||
import core.rendering.RenderEngine;
|
||||
import core.math.Vector2D;
|
||||
import core.objects.core.CollGameObject;
|
||||
import core.physics.Collidable;
|
||||
import core.physics.Collision;
|
||||
import core.objects.base.DebugPos;
|
||||
import core.objects.core.GameObject;
|
||||
import core.renderer.Drawable;
|
||||
import core.rendering.Drawable;
|
||||
import objects.Init;
|
||||
|
||||
import javax.swing.*;
|
||||
|
|
@ -58,7 +59,7 @@ public class Master {
|
|||
/**
|
||||
* The {@code RenderEngine} that handles everything about rendering
|
||||
*/
|
||||
private final RenderEngine renderEngine = new RenderEngine();
|
||||
private RenderEngine renderEngine;
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -73,6 +74,13 @@ public class Master {
|
|||
collidablesBuffer = new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Called once after the constructor
|
||||
*/
|
||||
public void init() {
|
||||
renderEngine = new RenderEngine();
|
||||
}
|
||||
|
||||
public static Master getMaster() {
|
||||
return master;
|
||||
}
|
||||
|
|
@ -147,7 +155,11 @@ public class Master {
|
|||
if (obj instanceof CollGameObject) {
|
||||
collidablesBuffer.add((Collidable) obj);
|
||||
}
|
||||
renderEngine.addRenderer(obj);
|
||||
if(obj.getRenderer() == null){
|
||||
System.out.println(obj);
|
||||
throw new NullPointerException("oh god oh fuck its null wtf pls no");
|
||||
}
|
||||
renderEngine.addRenderer(obj.getRenderer());
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
|
@ -204,7 +216,7 @@ public class Master {
|
|||
objectBuffer.remove(gameObject);
|
||||
gameObject.getParent().removeChild(gameObject);
|
||||
|
||||
renderEngine.removeRenderer(gameObject);
|
||||
renderEngine.removeRenderer(gameObject.getRenderer());
|
||||
|
||||
if (gameObject instanceof Collidable) {
|
||||
collidablesBuffer.remove(gameObject);
|
||||
|
|
@ -218,4 +230,5 @@ public class Master {
|
|||
public RenderEngine getRenderEngine() {
|
||||
return renderEngine;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,103 +0,0 @@
|
|||
package core.general;
|
||||
|
||||
import core.renderer.Drawable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* The {@code RenderEngine} handles the rendering of all {@code Renderers}
|
||||
* c<p>The {@code RenderEngine} extends JPanel and can be integrated into a JFrame. It gets the drawcall from resizing/moving the JPanel
|
||||
* or from the {@code Master}</p>
|
||||
*/
|
||||
public class RenderEngine extends JPanel {
|
||||
|
||||
/**
|
||||
* The current width and height of the game area
|
||||
*/
|
||||
private int w, h;
|
||||
|
||||
/**
|
||||
* The {@code LayerManager} for the render layers
|
||||
*/
|
||||
private final LayerManager layerManager;
|
||||
|
||||
/**
|
||||
* Construct a new {@code RenderEngine}
|
||||
*/
|
||||
public RenderEngine() {
|
||||
layerManager = new LayerManager();
|
||||
}
|
||||
|
||||
/**
|
||||
* The mein drawing method, handles everything about drawing
|
||||
*
|
||||
* @param g The {@code Graphics} object
|
||||
*/
|
||||
private void doDrawing(Graphics g) {
|
||||
|
||||
if (getWidth() * 9 > getHeight() * 16) {
|
||||
h = getHeight();
|
||||
w = h / 9 * 16;
|
||||
} else {
|
||||
w = getWidth();
|
||||
h = w / 16 * 9;
|
||||
}
|
||||
|
||||
Graphics2D g2d = (Graphics2D) g.create();
|
||||
|
||||
layerManager.drawAll(g2d);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The paintComponent method is called from Swing.
|
||||
* @param g
|
||||
*/
|
||||
@Override
|
||||
public void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
doDrawing(g);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a {@code Renderer} to the scene. Gets added to the buffer
|
||||
* @param d The {@code Renderer}
|
||||
*/
|
||||
public void addRenderer(Drawable d){
|
||||
layerManager.addToRendererBuffer(d);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a {@code Renderer} from the engine because it won't be needed anymore.
|
||||
* <p>If the object should only temporarily be invisible, change its {@code isVisible} field</p>
|
||||
* @param d
|
||||
* @return
|
||||
*/
|
||||
public boolean removeRenderer(Drawable d){
|
||||
return layerManager.removeRenderer(d);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the true width of the current screen
|
||||
* @return The width in Java2D coordinates
|
||||
*/
|
||||
public int getW() {
|
||||
return w;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the true height of the current screen
|
||||
* @return The height in Java2D coordinates
|
||||
*/
|
||||
public int getH() {
|
||||
return h;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush the buffer
|
||||
*/
|
||||
public void flush() {
|
||||
layerManager.flush();
|
||||
}
|
||||
}
|
||||
|
|
@ -3,7 +3,7 @@ package core.objects.base;
|
|||
import core.math.Coordinates;
|
||||
import core.math.Vector2D;
|
||||
import core.objects.core.GameObject;
|
||||
import core.renderer.CustomRenderer;
|
||||
import core.rendering.renderer.CustomRenderer;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
|
|
@ -33,6 +33,11 @@ public class DebugPos extends GameObject {
|
|||
g2d.drawLine((int)positionAbs.x - 20, (int)positionAbs.y, (int)positionAbs.x + 20, (int)positionAbs.y);
|
||||
g2d.drawLine((int)positionAbs.x, (int)positionAbs.y-20, (int)positionAbs.x, (int)positionAbs.y+20);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLayer() {
|
||||
return layer;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,9 @@
|
|||
package core.objects.core;
|
||||
|
||||
import core.math.Vector2D;
|
||||
import core.objects.core.GameObject;
|
||||
import core.physics.Collidable;
|
||||
import core.physics.Collision;
|
||||
import core.physics.hitboxes.Hitbox;
|
||||
import core.renderer.Renderer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,19 +1,20 @@
|
|||
package core.objects.core;
|
||||
|
||||
import core.math.Coordinates;
|
||||
import core.renderer.Drawable;
|
||||
import core.rendering.Drawable;
|
||||
import core.general.Master;
|
||||
import core.math.Vector2D;
|
||||
import core.renderer.Renderer;
|
||||
import core.rendering.RenderEngine;
|
||||
import core.rendering.renderer.Renderer;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* The GameObject class is the superclass of every {@code GameObject} that can be displayed on screen. It has the 2
|
||||
* {@link #update()} and {@link #draw(Graphics2D)} methods that have to be overridden
|
||||
* The GameObject class is the superclass of every {@code GameObject} that can be displayed on screen. It has the
|
||||
* {@link #update()} and method that have to be overridden
|
||||
*/
|
||||
public abstract class GameObject implements Drawable {
|
||||
public abstract class GameObject {
|
||||
|
||||
protected boolean doesDespawn = true;
|
||||
|
||||
|
|
@ -51,17 +52,13 @@ public abstract class GameObject implements Drawable {
|
|||
}
|
||||
|
||||
/**
|
||||
* <p>The update method is called every frame before the {@link #draw(Graphics2D)} method by the master object on each object. Everything
|
||||
* <p>The update method is called every before drawing. Everything
|
||||
* that is needed for the game to work should be here in this method.</p>
|
||||
* <p>No drawing should be made in this method. The {@code debug} method can be called on the master.</p>
|
||||
* <p>This function is <i>NOT</i> intended to be called manually.</p>
|
||||
*/
|
||||
protected abstract void update();
|
||||
|
||||
@Override
|
||||
public void draw(Graphics2D g2d) {
|
||||
renderer.draw(g2d);
|
||||
}
|
||||
|
||||
/**
|
||||
* A simple method to move the object to a Vector2D. This method should be called instead of doing it manually.
|
||||
|
|
@ -197,4 +194,8 @@ public abstract class GameObject implements Drawable {
|
|||
public GameObject getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public Renderer getRenderer(){
|
||||
return renderer;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package core.physics.hitboxes;
|
||||
|
||||
import core.renderer.Drawable;
|
||||
import core.rendering.Drawable;
|
||||
import core.math.Vector2D;
|
||||
|
||||
public abstract class Hitbox implements Drawable {
|
||||
|
|
|
|||
|
|
@ -1,35 +0,0 @@
|
|||
package core.renderer;
|
||||
|
||||
import core.general.Master;
|
||||
import core.math.Coordinates;
|
||||
import core.math.Vector2D;
|
||||
import core.objects.core.GameObject;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class RectRenderer extends Renderer{
|
||||
|
||||
private Vector2D size;
|
||||
|
||||
public RectRenderer(Color color, GameObject object, Vector2D size) {
|
||||
super(color, object);
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Graphics2D g2d) {
|
||||
Vector2D abs = Coordinates.getWorldCoordinates(object.getMapPosition());
|
||||
Vector2D sizeAbs = Coordinates.getWorldCoordinates(size);
|
||||
|
||||
int xCenterAbs = (int) (abs.x + sizeAbs.x / 2);
|
||||
int yCenterAbs = (int) (abs.y + sizeAbs.y / 2);
|
||||
|
||||
g2d.setPaint(color);
|
||||
|
||||
g2d.rotate(object.getRotation(), xCenterAbs, yCenterAbs);
|
||||
|
||||
g2d.fillRect((int) abs.x, (int) abs.y, (int) sizeAbs.x, (int) sizeAbs.y);
|
||||
|
||||
g2d.rotate(-object.getRotation(), xCenterAbs, yCenterAbs);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package core.renderer;
|
||||
package core.rendering;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
|
||||
|
|
@ -1,6 +1,4 @@
|
|||
package core.general;
|
||||
|
||||
import core.renderer.Drawable;
|
||||
package core.rendering;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
154
src/main/java/core/rendering/RenderEngine.java
Normal file
154
src/main/java/core/rendering/RenderEngine.java
Normal file
|
|
@ -0,0 +1,154 @@
|
|||
package core.rendering;
|
||||
|
||||
import core.general.Master;
|
||||
import core.math.Coordinates;
|
||||
import core.math.Vector2D;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* The {@code RenderEngine} handles the rendering of all {@code Renderers}
|
||||
* c<p>The {@code RenderEngine} extends JPanel and can be integrated into a JFrame. It gets the drawcall from resizing/moving the JPanel
|
||||
* or from the {@code Master}</p>
|
||||
*/
|
||||
public class RenderEngine extends JPanel {
|
||||
|
||||
private final Master master = Master.getMaster();
|
||||
|
||||
/**
|
||||
* The current width and height of the game area
|
||||
*/
|
||||
private int w, h;
|
||||
|
||||
/**
|
||||
* The {@code LayerManager} for the render layers
|
||||
*/
|
||||
private final LayerManager layerManager;
|
||||
|
||||
/**
|
||||
* The current {@code Graphics2D} object
|
||||
*/
|
||||
private Graphics2D g2d;
|
||||
|
||||
/**
|
||||
* Construct a new {@code RenderEngine}
|
||||
*/
|
||||
public RenderEngine() {
|
||||
layerManager = new LayerManager();
|
||||
}
|
||||
|
||||
/**
|
||||
* The mein drawing method, handles everything about drawing
|
||||
*
|
||||
* @param g The {@code Graphics} object
|
||||
*/
|
||||
private void doDrawing(Graphics g) {
|
||||
|
||||
if (getWidth() * 9 > getHeight() * 16) {
|
||||
h = getHeight();
|
||||
w = h / 9 * 16;
|
||||
} else {
|
||||
w = getWidth();
|
||||
h = w / 16 * 9;
|
||||
}
|
||||
|
||||
g2d = (Graphics2D) g.create();
|
||||
layerManager.drawAll(g2d);
|
||||
g2d = null; //making sure that nothing can be drawn between frames
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The paintComponent method is called from Swing.
|
||||
* @param g
|
||||
*/
|
||||
@Override
|
||||
public void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
doDrawing(g);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a {@code Renderer} to the scene. Gets added to the buffer
|
||||
* @param d The {@code Renderer}
|
||||
*/
|
||||
public void addRenderer(Drawable d){
|
||||
layerManager.addToRendererBuffer(d);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a {@code Renderer} from the engine because it won't be needed anymore.
|
||||
* <p>If the object should only temporarily be invisible, change its {@code isVisible} field</p>
|
||||
* @param d
|
||||
* @return
|
||||
*/
|
||||
public boolean removeRenderer(Drawable d){
|
||||
return layerManager.removeRenderer(d);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the true width of the current screen
|
||||
* @return The width in Java2D coordinates
|
||||
*/
|
||||
public int getW() {
|
||||
return w;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the true height of the current screen
|
||||
* @return The height in Java2D coordinates
|
||||
*/
|
||||
public int getH() {
|
||||
return h;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush the buffer
|
||||
*/
|
||||
public void flush() {
|
||||
layerManager.flush();
|
||||
}
|
||||
|
||||
//Drawing methods---------------------------------------------------------------------------------------------------------------
|
||||
|
||||
public void fillRect(Vector2D position, Vector2D size, Color color, double rotation){
|
||||
Vector2D abs = Coordinates.getWorldCoordinates(position);
|
||||
Vector2D sizeAbs = Coordinates.getWorldCoordinates(size);
|
||||
Vector2D centerAbs = new Vector2D((abs.x + sizeAbs.x / 2), (abs.y + sizeAbs.y / 2));
|
||||
|
||||
g2d.setPaint(color);
|
||||
g2d.rotate(rotation, centerAbs.x, centerAbs.y);
|
||||
g2d.fillRect(
|
||||
(int) abs.x, (int) abs.y,
|
||||
(int) sizeAbs.x, (int) sizeAbs.y);
|
||||
g2d.rotate(-rotation, centerAbs.x, centerAbs.y);
|
||||
}
|
||||
|
||||
public void fillRoundRect(Vector2D position, Vector2D size, Vector2D arcFactors, Color color, double rotation){
|
||||
Vector2D abs = Coordinates.getWorldCoordinates(position);
|
||||
Vector2D sizeAbs = Coordinates.getWorldCoordinates(size);
|
||||
Vector2D centerAbs = new Vector2D((abs.x + sizeAbs.x / 2), (abs.y + sizeAbs.y / 2));
|
||||
|
||||
g2d.setPaint(color);
|
||||
g2d.rotate(rotation, centerAbs.x, centerAbs.y);
|
||||
g2d.fillRoundRect(
|
||||
(int) abs.x, (int) abs.y,
|
||||
(int) sizeAbs.x, (int) sizeAbs.y,
|
||||
(int) (master.getW() / arcFactors.x), (int) (master.getH() / arcFactors.y));
|
||||
g2d.rotate(-rotation, centerAbs.x, centerAbs.y);
|
||||
}
|
||||
|
||||
public void fillOval(Vector2D position, Vector2D size, Color color, double rotation){
|
||||
Vector2D abs = Coordinates.getWorldCoordinates(position);
|
||||
Vector2D sizeAbs = Coordinates.getWorldCoordinates(size);
|
||||
Vector2D centerAbs = new Vector2D((abs.x + sizeAbs.x / 2), (abs.y + sizeAbs.y / 2));
|
||||
|
||||
g2d.setPaint(color);
|
||||
g2d.rotate(rotation, centerAbs.x, centerAbs.y);
|
||||
g2d.fillOval(
|
||||
(int) abs.x, (int) abs.y,
|
||||
(int) sizeAbs.x, (int) sizeAbs.y);
|
||||
g2d.rotate(-rotation, centerAbs.x, centerAbs.y);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
package core.renderer;
|
||||
package core.rendering.renderer;
|
||||
|
||||
import core.math.Coordinates;
|
||||
import core.math.Vector2D;
|
||||
import core.objects.core.GameObject;
|
||||
|
||||
|
|
@ -29,18 +28,6 @@ public class CircleRenderer extends Renderer {
|
|||
|
||||
@Override
|
||||
public void draw(Graphics2D g2d) {
|
||||
Vector2D abs = Coordinates.getWorldCoordinates(object.getMapPosition());
|
||||
Vector2D sizeAbs = Coordinates.getWorldCoordinates(new Vector2D(radius * 2, radius * 2));
|
||||
|
||||
g2d.setPaint(color);
|
||||
g2d.fillOval((int) abs.x, (int) abs.y, (int) sizeAbs.x, (int) sizeAbs.y);
|
||||
}
|
||||
|
||||
public double getRadius() {
|
||||
return radius;
|
||||
}
|
||||
|
||||
public void setRadius(double radius) {
|
||||
this.radius = radius;
|
||||
re.fillOval(object.getMapPosition(), new Vector2D(2 * radius, 2 * radius), color, object.getRotation());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package core.renderer;
|
||||
package core.rendering.renderer;
|
||||
|
||||
import core.objects.core.GameObject;
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package core.renderer;
|
||||
package core.rendering.renderer;
|
||||
|
||||
import core.objects.core.GameObject;
|
||||
|
||||
21
src/main/java/core/rendering/renderer/RectRenderer.java
Normal file
21
src/main/java/core/rendering/renderer/RectRenderer.java
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
package core.rendering.renderer;
|
||||
|
||||
import core.math.Vector2D;
|
||||
import core.objects.core.GameObject;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class RectRenderer extends Renderer{
|
||||
|
||||
private Vector2D size;
|
||||
|
||||
public RectRenderer(Color color, GameObject object, Vector2D size) {
|
||||
super(color, object);
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Graphics2D g2d) {
|
||||
re.fillRect(object.getMapPosition(), size, color, object.getRotation());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,13 +1,18 @@
|
|||
package core.renderer;
|
||||
package core.rendering.renderer;
|
||||
|
||||
import core.general.Master;
|
||||
import core.objects.core.GameObject;
|
||||
import core.rendering.Drawable;
|
||||
import core.rendering.RenderEngine;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* The base renderer class for all renderers
|
||||
*/
|
||||
public abstract class Renderer {
|
||||
public abstract class Renderer implements Drawable {
|
||||
|
||||
protected RenderEngine re;
|
||||
|
||||
protected Color color;
|
||||
protected GameObject object;
|
||||
|
|
@ -18,6 +23,7 @@ public abstract class Renderer {
|
|||
* @param object The {@code GameObject} the {@code Renderer} os assigned to
|
||||
*/
|
||||
public Renderer(Color color, GameObject object) {
|
||||
this.re = Master.getMaster().getRenderEngine();
|
||||
this.color = color;
|
||||
this.object = object;
|
||||
}
|
||||
|
|
@ -27,4 +33,9 @@ public abstract class Renderer {
|
|||
* @param g2d the {@code Graphics2D} object
|
||||
*/
|
||||
public abstract void draw(Graphics2D g2d);
|
||||
|
||||
@Override
|
||||
public int getLayer() {
|
||||
return object.getLayer();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package core.renderer;
|
||||
package core.rendering.renderer;
|
||||
|
||||
import core.general.Master;
|
||||
import core.math.Coordinates;
|
||||
|
|
@ -23,17 +23,6 @@ public class RoundRectRenderer extends Renderer {
|
|||
|
||||
@Override
|
||||
public void draw(Graphics2D g2d) {
|
||||
Vector2D abs = Coordinates.getWorldCoordinates(object.getMapPosition());
|
||||
Vector2D sizeAbs = Coordinates.getWorldCoordinates(size);
|
||||
|
||||
int xCenterAbs = (int) (abs.x + sizeAbs.x / 2);
|
||||
int yCenterAbs = (int) (abs.y + sizeAbs.y / 2);
|
||||
|
||||
g2d.setPaint(color);
|
||||
|
||||
g2d.rotate(object.getRotation(), xCenterAbs, yCenterAbs);
|
||||
g2d.fillRoundRect((int) abs.x, (int) abs.y, (int) sizeAbs.x, (int) sizeAbs.y, (int) (master.getW() / cornerFactorX), (int) (master.getH() / cornerFactorY));
|
||||
|
||||
g2d.rotate(-object.getRotation(), xCenterAbs, yCenterAbs);
|
||||
re.fillRoundRect(object.getMapPosition(), size, new Vector2D(cornerFactorX, cornerFactorY), color, object.getRotation());
|
||||
}
|
||||
}
|
||||
|
|
@ -32,6 +32,7 @@ public class Init {
|
|||
public static void init(){
|
||||
|
||||
//INIT GOES HERE
|
||||
|
||||
create(new Grid());
|
||||
|
||||
BattleShip battleShip = create(new BattleShip());
|
||||
|
|
|
|||
|
|
@ -2,14 +2,11 @@ package objects.ships;
|
|||
|
||||
import core.general.Input;
|
||||
import core.math.Vector2D;
|
||||
import core.objects.core.CollGameObject;
|
||||
import core.objects.core.GameObject;
|
||||
import core.physics.hitboxes.RectHitBox;
|
||||
import core.renderer.RectRenderer;
|
||||
import core.renderer.RoundRectRenderer;
|
||||
import core.rendering.renderer.RectRenderer;
|
||||
import core.rendering.renderer.RoundRectRenderer;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
|
|
@ -34,8 +31,8 @@ public class BattleShip extends GameObject {
|
|||
turrets = new ArrayList<>();
|
||||
this.mainColor = mainColor;
|
||||
this.doesDespawn = false;
|
||||
//setRenderer(new RoundRectRenderer(mainColor, this, size, 10, 10));
|
||||
setRenderer(new RectRenderer(mainColor, this, size));
|
||||
setRenderer(new RoundRectRenderer(mainColor, this, size, 10, 10));
|
||||
//setRenderer(new RectRenderer(mainColor, this, size));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package objects.ships;
|
|||
import core.math.Vector2D;
|
||||
import core.objects.core.CollGameObject;
|
||||
import core.physics.hitboxes.RectHitBox;
|
||||
import core.rendering.renderer.CircleRenderer;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
|
|
@ -18,11 +19,8 @@ public class Shell extends CollGameObject {
|
|||
this.mainColor = Color.ORANGE;
|
||||
this.ignores.add(Shell.class);
|
||||
this.isTrigger = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Graphics2D g2d) {
|
||||
fillOval(g2d);
|
||||
this.setRenderer(new CircleRenderer(this, mainColor, size.x/2));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -4,9 +4,7 @@ import core.math.Coordinates;
|
|||
import core.math.Vector2D;
|
||||
import core.physics.hitboxes.RectHitBox;
|
||||
import core.objects.core.CollGameObject;
|
||||
import core.renderer.CircleRenderer;
|
||||
import core.renderer.CustomRenderer;
|
||||
import core.renderer.RectRenderer;
|
||||
import core.rendering.renderer.CircleRenderer;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,11 @@
|
|||
package objects.ships;
|
||||
|
||||
import core.general.Input;
|
||||
import core.general.Master;
|
||||
import core.math.Coordinates;
|
||||
import core.math.ExMath;
|
||||
import core.math.Vector2D;
|
||||
import core.objects.core.GameObject;
|
||||
import core.renderer.CustomRenderer;
|
||||
import core.rendering.renderer.CustomRenderer;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
|
|
@ -68,6 +67,11 @@ public class Turret extends GameObject {
|
|||
|
||||
g2d.setStroke(new BasicStroke());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLayer() {
|
||||
return object.getLayer();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package objects.world;
|
|||
|
||||
import core.math.Vector2D;
|
||||
import core.objects.core.GameObject;
|
||||
import core.rendering.renderer.CustomRenderer;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
|
|
@ -14,30 +15,35 @@ public class Grid extends GameObject {
|
|||
|
||||
public Grid() {
|
||||
super(Vector2D.zero(), Vector2D.zero());
|
||||
}
|
||||
setRenderer(new CustomRenderer(mainColor, this) {
|
||||
@Override
|
||||
public void draw(Graphics2D g2d) {
|
||||
g2d.setPaint(Color.LIGHT_GRAY);
|
||||
|
||||
@Override
|
||||
public void draw(Graphics2D g2d) {
|
||||
g2d.setPaint(Color.LIGHT_GRAY);
|
||||
int w = master.getW();
|
||||
int h = w/16*9;
|
||||
|
||||
int w = master.getW();
|
||||
int h = w/16*9;
|
||||
g2d.drawRect(0, 0, w, h);
|
||||
|
||||
g2d.drawRect(0, 0, w, h);
|
||||
int verticalLines = w / GRID_SPACING;
|
||||
int horizontalLines = h / GRID_SPACING;
|
||||
|
||||
int verticalLines = w / GRID_SPACING;
|
||||
int horizontalLines = h / GRID_SPACING;
|
||||
for (int i = 0; i < horizontalLines; i++) {
|
||||
int y = i * h / horizontalLines;
|
||||
g2d.drawLine(0, y, w, y);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
for (int i = 0; i < verticalLines; i++) {
|
||||
int x = i * w / verticalLines;
|
||||
g2d.drawLine(x, 0, x, h);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLayer() {
|
||||
return object.getLayer();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import core.math.Vector2D;
|
|||
import core.physics.hitboxes.Hitbox;
|
||||
import core.physics.hitboxes.RectHitBox;
|
||||
import core.objects.core.CollGameObject;
|
||||
import core.renderer.RectRenderer;
|
||||
import core.rendering.renderer.RectRenderer;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue