Omstrukturerer litt mens det fortsatt er enkelt

Forbedrer tester
Bytter navn på noen metoder og variabler
Bytter noen tall til relevante konstanter
Stokker om på rekkefølgen i konstruksjonsmetodene til DrawableObject
This commit is contained in:
2020-02-05 05:14:35 +01:00
parent e4784246bf
commit 4eb5b42755
5 changed files with 54 additions and 43 deletions

View File

@ -27,17 +27,16 @@ public class Game implements IDrawableGame {
}
@Override
public List<IDrawableObject> objectsToRender() {
public List<IDrawableObject> getObjectsToDraw() {
List<IDrawableObject> list = new ArrayList<>();
for (int i = 0; i < 12; i++) {
for (int j = 0; j < 12; j++) {
DrawableObject tileObj = new DrawableObject(i * 64, j * 64, GameTexture.TILE);
list.add(tileObj);
for (int i = 0; i < TILE_NUMBER; i++) {
for (int j = 0; j < TILE_NUMBER; j++) {
DrawableObject tile = new DrawableObject(GameTexture.TILE, i * TILE_SIZE, j * TILE_SIZE);
list.add(tile);
}
}
DrawableObject roboObj = new DrawableObject(128,128, GameTexture.ROBOT);
list.add(roboObj);
DrawableObject robot = new DrawableObject(GameTexture.ROBOT, TILE_SIZE, TILE_SIZE);
list.add(robot);
return list;
}
}

View File

@ -22,9 +22,9 @@ public interface IDrawableGame {
int getHeight();
/**
* Gets a list of objects which are to be rendered
* Gets a list of objects which are to be drawn
* @return A list of drawable objects in the order they are to be drawn
*/
List<IDrawableObject> objectsToRender();
List<IDrawableObject> getObjectsToDraw();
}

View File

@ -6,27 +6,28 @@ import inf112.fiasko.roborally.abstractions.GameTexture;
* This class represents an object that can be drawn using libgdx
*/
public class DrawableObject implements IDrawableObject {
private GameTexture texture;
private int xPos;
private int yPos;
private int width = 64;
private int height = 64;
private int rotation = 0;
private GameTexture texture;
private boolean flipX = false;
private boolean flipY = false;
/**
* Initializes a drawable object
* @param texture The texture to use for drawing the element
* @param xPos The pixel to start drawing on for the x axis
* @param yPos The pixel to start drawing on for the y axis
* @param texture The texture to use for drawing the element
* @param rotation The amount of degrees to rotate the element counterclockwise
* @param width The width of the element
* @param height The height of the element
* @param rotation The amount of degrees to rotate the element counterclockwise
* @param flipX Whether to flip/mirror the element over the x axis
* @param flipY Whether to flip/mirror the element over the y axis
*/
public DrawableObject(int xPos, int yPos, GameTexture texture, int rotation, int width, int height, boolean flipX, boolean flipY) {
public DrawableObject(GameTexture texture, int xPos, int yPos, int width, int height, int rotation, boolean flipX,
boolean flipY) {
this.xPos = xPos;
this.yPos = yPos;
this.rotation = rotation;
@ -39,11 +40,11 @@ public class DrawableObject implements IDrawableObject {
/**
* Initializes a new drawable object
* @param texture The texture to use for drawing the element
* @param xPos The pixel to start drawing on for the x axis
* @param yPos The pixel to start drawing on for the y axis
* @param texture The texture to use for drawing the element
*/
public DrawableObject(int xPos, int yPos, GameTexture texture) {
public DrawableObject(GameTexture texture, int xPos, int yPos) {
this.xPos = xPos;
this.yPos = yPos;
this.texture = texture;