mirror of
https://github.com/Noratrieb/Java2DGame.git
synced 2026-01-14 14:05:01 +01:00
draw method signature change
This commit is contained in:
parent
4356d02a66
commit
adab1a4b7c
16 changed files with 34 additions and 43 deletions
|
|
@ -139,7 +139,7 @@ public class Master {
|
||||||
collidablesBuffer.remove(gameObject);
|
collidablesBuffer.remove(gameObject);
|
||||||
|
|
||||||
if (Init.DEBUG_MODE) {
|
if (Init.DEBUG_MODE) {
|
||||||
renderEngine.removeRenderer(((CollGameObject) gameObject).getHitbox());
|
//add hitbox renderer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,8 @@ public class DebugPos extends GameObject {
|
||||||
|
|
||||||
this.setRenderer(new CustomRenderer(Color.GREEN, this) {
|
this.setRenderer(new CustomRenderer(Color.GREEN, this) {
|
||||||
@Override
|
@Override
|
||||||
public void draw(Graphics2D g2d) {
|
public void draw() {
|
||||||
|
Graphics2D g2d = master.getRenderEngine().getG2d();
|
||||||
Vector2D positionAbs = Coordinates.getWorldCoordinates(getMapPosition());
|
Vector2D positionAbs = Coordinates.getWorldCoordinates(getMapPosition());
|
||||||
g2d.setColor(color);
|
g2d.setColor(color);
|
||||||
g2d.setStroke(new BasicStroke((int) Coordinates.getWorldCoordinates(new Vector2D(0.5, 0)).x, BasicStroke.CAP_BUTT,
|
g2d.setStroke(new BasicStroke((int) Coordinates.getWorldCoordinates(new Vector2D(0.5, 0)).x, BasicStroke.CAP_BUTT,
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ package core.physics.hitboxes;
|
||||||
import core.rendering.Drawable;
|
import core.rendering.Drawable;
|
||||||
import core.math.Vector2D;
|
import core.math.Vector2D;
|
||||||
|
|
||||||
public abstract class Hitbox implements Drawable {
|
public abstract class Hitbox{
|
||||||
|
|
||||||
|
|
||||||
public static final int HITBOX_RENDER_LAYER = 1;
|
public static final int HITBOX_RENDER_LAYER = 1;
|
||||||
|
|
@ -24,9 +24,4 @@ public abstract class Hitbox implements Drawable {
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return super.toString();
|
return super.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getLayer() {
|
|
||||||
return HITBOX_RENDER_LAYER;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package core.physics.hitboxes;
|
package core.physics.hitboxes;
|
||||||
|
|
||||||
|
import core.general.Master;
|
||||||
import core.math.Coordinates;
|
import core.math.Coordinates;
|
||||||
import core.math.Vector2D;
|
import core.math.Vector2D;
|
||||||
import custom.Init;
|
import custom.Init;
|
||||||
|
|
@ -171,14 +172,4 @@ public class RectHitBox extends Hitbox {
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "RectHitBox{" + x1 + " " + x2 + "\n" + y1 + " " + y2 + "}";
|
return "RectHitBox{" + x1 + " " + x2 + "\n" + y1 + " " + y2 + "}";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void draw(Graphics2D g2d) {
|
|
||||||
|
|
||||||
Vector2D abs = Coordinates.getWorldCoordinates(x1);
|
|
||||||
Vector2D sizeAbs = Coordinates.getWorldCoordinates(Vector2D.subtract(y2, x1));
|
|
||||||
|
|
||||||
g2d.setPaint(Color.MAGENTA);
|
|
||||||
g2d.drawRect((int) abs.x, (int) abs.y, (int) sizeAbs.x, (int) sizeAbs.y);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
package core.rendering;
|
package core.rendering;
|
||||||
|
|
||||||
import java.awt.Graphics2D;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This interface has to be implemented by every
|
* This interface has to be implemented by every
|
||||||
*/
|
*/
|
||||||
|
|
@ -14,9 +12,8 @@ public interface Drawable {
|
||||||
* fine even without this method being called.</p>
|
* fine even without this method being called.</p>
|
||||||
* <p>This function is <i>NOT</i> intended to be called manually.</p>
|
* <p>This function is <i>NOT</i> intended to be called manually.</p>
|
||||||
*
|
*
|
||||||
* @param g2d The {@code Graphics2D} object given by the master
|
|
||||||
*/
|
*/
|
||||||
void draw(Graphics2D g2d);
|
void draw();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the layer of the Drawable
|
* Returns the layer of the Drawable
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ public class LayerManager {
|
||||||
* @param g2d
|
* @param g2d
|
||||||
*/
|
*/
|
||||||
public void drawAll(Graphics2D g2d){
|
public void drawAll(Graphics2D g2d){
|
||||||
layers.forEach(e -> e.forEach(f -> f.draw(g2d)));
|
layers.forEach(e -> e.forEach(f -> f.draw()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -113,6 +113,10 @@ public class RenderEngine extends JPanel {
|
||||||
this.currentCamera = currentCamera;
|
this.currentCamera = currentCamera;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Graphics2D getG2d(){
|
||||||
|
return g2d;
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------
|
//--------------------------------------
|
||||||
|
|
||||||
public Vector2D shiftPoint(Vector2D point){
|
public Vector2D shiftPoint(Vector2D point){
|
||||||
|
|
@ -153,6 +157,15 @@ public class RenderEngine extends JPanel {
|
||||||
drawTearDown();
|
drawTearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void drawRect(Vector2D position, Vector2D size, Color color, int rotation) {
|
||||||
|
drawSetup(position, size, color, rotation);
|
||||||
|
g2d.drawRect(
|
||||||
|
(int) sdc.abs.x, (int) sdc.abs.y,
|
||||||
|
(int) sdc.sizeAbs.x, (int) sdc.sizeAbs.y
|
||||||
|
);
|
||||||
|
drawTearDown();
|
||||||
|
}
|
||||||
|
|
||||||
private void drawSetup(Vector2D position, Vector2D size, Color color, double rotation, Object ... args){
|
private void drawSetup(Vector2D position, Vector2D size, Color color, double rotation, Object ... args){
|
||||||
Vector2D abs = Coordinates.getWorldCoordinates(shiftPoint(position));
|
Vector2D abs = Coordinates.getWorldCoordinates(shiftPoint(position));
|
||||||
Vector2D sizeAbs = Coordinates.getWorldCoordinates(scaleSize(size));
|
Vector2D sizeAbs = Coordinates.getWorldCoordinates(scaleSize(size));
|
||||||
|
|
@ -169,6 +182,7 @@ public class RenderEngine extends JPanel {
|
||||||
sdc = null; //to avoid any drawing errors, might be changed at some point
|
sdc = null; //to avoid any drawing errors, might be changed at some point
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds all information about a shape to be drawn
|
* Holds all information about a shape to be drawn
|
||||||
*/
|
*/
|
||||||
|
|
@ -180,10 +194,6 @@ public class RenderEngine extends JPanel {
|
||||||
public double rotation;
|
public double rotation;
|
||||||
public Object[] args;
|
public Object[] args;
|
||||||
|
|
||||||
public ShapeDrawContainer(Vector2D abs, Vector2D sizeAbs, Vector2D centerAbs, Color color, double rotation) {
|
|
||||||
this(abs, sizeAbs, centerAbs, color, rotation, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ShapeDrawContainer(Vector2D abs, Vector2D sizeAbs, Vector2D centerAbs, Color color, double rotation, Object ... args) {
|
public ShapeDrawContainer(Vector2D abs, Vector2D sizeAbs, Vector2D centerAbs, Color color, double rotation, Object ... args) {
|
||||||
this.abs = abs;
|
this.abs = abs;
|
||||||
this.sizeAbs = sizeAbs;
|
this.sizeAbs = sizeAbs;
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ public class CircleRenderer extends Renderer {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(Graphics2D g2d) {
|
public void draw() {
|
||||||
re.fillOval(object.getMapPosition(), new Vector2D(2 * radius, 2 * radius), color, object.getRotation());
|
re.fillOval(object.getMapPosition(), new Vector2D(2 * radius, 2 * radius), color, object.getRotation());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ package core.rendering.renderer;
|
||||||
|
|
||||||
import core.objects.core.GameObject;
|
import core.objects.core.GameObject;
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
|
@ -12,7 +11,7 @@ import java.util.Arrays;
|
||||||
*/
|
*/
|
||||||
public class ComplexRenderer extends Renderer{
|
public class ComplexRenderer extends Renderer{
|
||||||
|
|
||||||
private ArrayList<Renderer> renderers;
|
private final ArrayList<Renderer> renderers;
|
||||||
|
|
||||||
public ComplexRenderer (GameObject object, Renderer ... renderers){
|
public ComplexRenderer (GameObject object, Renderer ... renderers){
|
||||||
super(null, object);
|
super(null, object);
|
||||||
|
|
@ -20,7 +19,7 @@ public class ComplexRenderer extends Renderer{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(Graphics2D g2d) {
|
public void draw() {
|
||||||
renderers.forEach(e -> e.draw(g2d));
|
renderers.forEach(e -> e.draw());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,6 @@ package core.rendering.renderer;
|
||||||
|
|
||||||
import core.objects.core.GameObject;
|
import core.objects.core.GameObject;
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A filler {@code Renderer} that does nothing
|
* A filler {@code Renderer} that does nothing
|
||||||
*/
|
*/
|
||||||
|
|
@ -19,6 +17,6 @@ public class EmptyRenderer extends Renderer{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(Graphics2D g2d) {
|
public void draw() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ public class RectRenderer extends Renderer{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(Graphics2D g2d) {
|
public void draw() {
|
||||||
re.fillRect(object.getMapPosition(), size, color, object.getRotation());
|
re.fillRect(object.getMapPosition(), size, color, object.getRotation());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,9 +30,8 @@ public abstract class Renderer implements Drawable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is called on every renderer for every {@code GameObject}
|
* This method is called on every renderer for every {@code GameObject}
|
||||||
* @param g2d the {@code Graphics2D} object
|
|
||||||
*/
|
*/
|
||||||
public abstract void draw(Graphics2D g2d);
|
public abstract void draw();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getLayer() {
|
public int getLayer() {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package core.rendering.renderer;
|
package core.rendering.renderer;
|
||||||
|
|
||||||
import core.general.Master;
|
import core.general.Master;
|
||||||
import core.math.Coordinates;
|
|
||||||
import core.math.Vector2D;
|
import core.math.Vector2D;
|
||||||
import core.objects.core.GameObject;
|
import core.objects.core.GameObject;
|
||||||
|
|
||||||
|
|
@ -22,7 +21,7 @@ public class RoundRectRenderer extends Renderer {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(Graphics2D g2d) {
|
public void draw() {
|
||||||
re.fillRoundRect(object.getMapPosition(), size, new Vector2D(cornerFactorX, cornerFactorY), color, object.getRotation());
|
re.fillRoundRect(object.getMapPosition(), size, new Vector2D(cornerFactorX, cornerFactorY), color, object.getRotation());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ import java.awt.*;
|
||||||
*/
|
*/
|
||||||
public class Init {
|
public class Init {
|
||||||
|
|
||||||
public static final boolean DEBUG_MODE = false;
|
public static final boolean DEBUG_MODE = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new GameObject
|
* Create a new GameObject
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,8 @@ public class Turret extends GameObject {
|
||||||
|
|
||||||
setRenderer(new CustomRenderer(mainColor, this) {
|
setRenderer(new CustomRenderer(mainColor, this) {
|
||||||
@Override
|
@Override
|
||||||
public void draw(Graphics2D g2d) {
|
public void draw() {
|
||||||
|
Graphics2D g2d = re.getG2d();
|
||||||
g2d.setPaint(mainColor);
|
g2d.setPaint(mainColor);
|
||||||
Vector2D abs = getWorldCoordsFromLocal(position);
|
Vector2D abs = getWorldCoordsFromLocal(position);
|
||||||
int sizeAbs = (int) Coordinates.getWorldCoordinates(object.getSize()).x;
|
int sizeAbs = (int) Coordinates.getWorldCoordinates(object.getSize()).x;
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,8 @@ public class Grid extends GameObject {
|
||||||
super(Vector2D.zero(), Vector2D.zero());
|
super(Vector2D.zero(), Vector2D.zero());
|
||||||
setRenderer(new CustomRenderer(mainColor, this) {
|
setRenderer(new CustomRenderer(mainColor, this) {
|
||||||
@Override
|
@Override
|
||||||
public void draw(Graphics2D g2d) {
|
public void draw() {
|
||||||
|
Graphics2D g2d = re.getG2d();
|
||||||
g2d.setPaint(Color.LIGHT_GRAY);
|
g2d.setPaint(Color.LIGHT_GRAY);
|
||||||
|
|
||||||
int w = master.getW();
|
int w = master.getW();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue