mirror of
https://github.com/Noratrieb/Java2DGame.git
synced 2026-01-14 14:05:01 +01:00
re cleanup
This commit is contained in:
parent
76ad24f96b
commit
4356d02a66
1 changed files with 51 additions and 33 deletions
|
|
@ -19,20 +19,12 @@ public class RenderEngine extends JPanel {
|
||||||
|
|
||||||
private Camera currentCamera;
|
private Camera currentCamera;
|
||||||
|
|
||||||
/**
|
|
||||||
* The current width and height of the game area
|
|
||||||
*/
|
|
||||||
private int w, h;
|
private int w, h;
|
||||||
|
|
||||||
/**
|
|
||||||
* The {@code LayerManager} for the render layers
|
|
||||||
*/
|
|
||||||
private final LayerManager layerManager;
|
private final LayerManager layerManager;
|
||||||
|
|
||||||
/**
|
|
||||||
* The current {@code Graphics2D} object
|
|
||||||
*/
|
|
||||||
private Graphics2D g2d;
|
private Graphics2D g2d;
|
||||||
|
private ShapeDrawContainer sdc;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new {@code RenderEngine}
|
* Construct a new {@code RenderEngine}
|
||||||
|
|
@ -137,42 +129,68 @@ public class RenderEngine extends JPanel {
|
||||||
//Drawing methods---------------------------------------------------------------------------------------------------------------
|
//Drawing methods---------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
public void fillRect(Vector2D position, Vector2D size, Color color, double rotation){
|
public void fillRect(Vector2D position, Vector2D size, Color color, double rotation){
|
||||||
Vector2D abs = Coordinates.getWorldCoordinates(shiftPoint(position));
|
drawSetup(position, size, color, rotation);
|
||||||
Vector2D sizeAbs = Coordinates.getWorldCoordinates(scaleSize(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(
|
g2d.fillRect(
|
||||||
(int) abs.x, (int) abs.y,
|
(int) sdc.abs.x, (int) sdc.abs.y,
|
||||||
(int) sizeAbs.x, (int) sizeAbs.y);
|
(int) sdc.sizeAbs.x, (int) sdc.sizeAbs.y);
|
||||||
g2d.rotate(-rotation, centerAbs.x, centerAbs.y);
|
drawTearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void fillRoundRect(Vector2D position, Vector2D size, Vector2D arcFactors, Color color, double rotation){
|
public void fillRoundRect(Vector2D position, Vector2D size, Vector2D arcFactors, Color color, double rotation){
|
||||||
Vector2D abs = Coordinates.getWorldCoordinates(shiftPoint(position));
|
drawSetup(position, size, color, rotation);
|
||||||
Vector2D sizeAbs = Coordinates.getWorldCoordinates(scaleSize(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(
|
g2d.fillRoundRect(
|
||||||
(int) abs.x, (int) abs.y,
|
(int) sdc.abs.x, (int) sdc.abs.y,
|
||||||
(int) sizeAbs.x, (int) sizeAbs.y,
|
(int) sdc.sizeAbs.x, (int) sdc.sizeAbs.y,
|
||||||
(int) (master.getW() / arcFactors.x), (int) (master.getH() / arcFactors.y));
|
(int) (master.getW() / arcFactors.x), (int) (master.getH() / arcFactors.y));
|
||||||
g2d.rotate(-rotation, centerAbs.x, centerAbs.y);
|
drawTearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void fillOval(Vector2D position, Vector2D size, Color color, double rotation){
|
public void fillOval(Vector2D position, Vector2D size, Color color, double rotation){
|
||||||
|
drawSetup(position, size, color, rotation);
|
||||||
|
g2d.fillOval(
|
||||||
|
(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){
|
||||||
Vector2D abs = Coordinates.getWorldCoordinates(shiftPoint(position));
|
Vector2D abs = Coordinates.getWorldCoordinates(shiftPoint(position));
|
||||||
Vector2D sizeAbs = Coordinates.getWorldCoordinates(scaleSize(size));
|
Vector2D sizeAbs = Coordinates.getWorldCoordinates(scaleSize(size));
|
||||||
Vector2D centerAbs = new Vector2D((abs.x + sizeAbs.x / 2), (abs.y + sizeAbs.y / 2));
|
Vector2D centerAbs = new Vector2D((abs.x + sizeAbs.x / 2), (abs.y + sizeAbs.y / 2));
|
||||||
|
|
||||||
g2d.setPaint(color);
|
sdc = new ShapeDrawContainer(abs, sizeAbs, centerAbs, color, rotation, args);
|
||||||
g2d.rotate(rotation, centerAbs.x, centerAbs.y);
|
|
||||||
g2d.fillOval(
|
g2d.setPaint(sdc.color);
|
||||||
(int) abs.x, (int) abs.y,
|
g2d.rotate(sdc.rotation, sdc.centerAbs.x, sdc.centerAbs.y);
|
||||||
(int) sizeAbs.x, (int) sizeAbs.y);
|
}
|
||||||
g2d.rotate(-rotation, centerAbs.x, centerAbs.y);
|
|
||||||
|
private void drawTearDown(){
|
||||||
|
g2d.rotate(-sdc.rotation, sdc.centerAbs.x, sdc.centerAbs.y);
|
||||||
|
sdc = null; //to avoid any drawing errors, might be changed at some point
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Holds all information about a shape to be drawn
|
||||||
|
*/
|
||||||
|
private class ShapeDrawContainer {
|
||||||
|
public Vector2D abs;
|
||||||
|
public Vector2D sizeAbs;
|
||||||
|
public Vector2D centerAbs;
|
||||||
|
public Color color;
|
||||||
|
public double rotation;
|
||||||
|
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) {
|
||||||
|
this.abs = abs;
|
||||||
|
this.sizeAbs = sizeAbs;
|
||||||
|
this.centerAbs = centerAbs;
|
||||||
|
this.color = color;
|
||||||
|
this.rotation = rotation;
|
||||||
|
this.args = args;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue