2020-02-04 17:52:17 +01:00
|
|
|
package inf112.fiasko.roborally.objects;
|
|
|
|
|
2020-02-24 18:07:26 +01:00
|
|
|
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
2020-02-03 14:06:36 +01:00
|
|
|
|
2020-02-03 18:32:22 +01:00
|
|
|
/**
|
|
|
|
* This class represents an object that can be drawn using libgdx
|
|
|
|
*/
|
2020-04-20 13:13:04 +02:00
|
|
|
public class DrawableObject {
|
2020-02-24 18:07:26 +01:00
|
|
|
private final TextureRegion texture;
|
2020-02-20 14:10:56 +01:00
|
|
|
private final int xPos;
|
|
|
|
private final int yPos;
|
2020-02-03 14:06:36 +01:00
|
|
|
private int width = 64;
|
|
|
|
private int height = 64;
|
|
|
|
private int rotation = 0;
|
|
|
|
private boolean flipX = false;
|
|
|
|
private boolean flipY = false;
|
|
|
|
|
2020-02-03 18:32:22 +01:00
|
|
|
/**
|
|
|
|
* Initializes a drawable object
|
2020-04-20 13:13:04 +02:00
|
|
|
*
|
|
|
|
* @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 width The width of the element
|
|
|
|
* @param height The height of the element
|
2020-02-05 05:14:35 +01:00
|
|
|
* @param rotation The amount of degrees to rotate the element counterclockwise
|
2020-04-20 13:13:04 +02:00
|
|
|
* @param flipX Whether to flip/mirror the element over the x axis
|
|
|
|
* @param flipY Whether to flip/mirror the element over the y axis
|
2020-02-03 18:32:22 +01:00
|
|
|
*/
|
2020-02-24 18:07:26 +01:00
|
|
|
public DrawableObject(TextureRegion texture, int xPos, int yPos, int width, int height, int rotation, boolean flipX,
|
2020-02-05 05:14:35 +01:00
|
|
|
boolean flipY) {
|
2020-02-03 14:06:36 +01:00
|
|
|
this.xPos = xPos;
|
|
|
|
this.yPos = yPos;
|
|
|
|
this.rotation = rotation;
|
|
|
|
this.texture = texture;
|
|
|
|
this.width = width;
|
|
|
|
this.height = height;
|
|
|
|
this.flipX = flipX;
|
|
|
|
this.flipY = flipY;
|
|
|
|
}
|
|
|
|
|
2020-02-24 18:07:26 +01:00
|
|
|
/**
|
|
|
|
* Initializes a drawable object
|
2020-04-20 13:13:04 +02:00
|
|
|
*
|
|
|
|
* @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 width The width of the element
|
|
|
|
* @param height The height of the element
|
2020-02-24 18:07:26 +01:00
|
|
|
* @param rotation The amount of degrees to rotate the element counterclockwise
|
|
|
|
*/
|
|
|
|
public DrawableObject(TextureRegion texture, int xPos, int yPos, int width, int height, int rotation) {
|
|
|
|
this.xPos = xPos;
|
|
|
|
this.yPos = yPos;
|
|
|
|
this.rotation = rotation;
|
|
|
|
this.texture = texture;
|
|
|
|
this.width = width;
|
|
|
|
this.height = height;
|
|
|
|
}
|
|
|
|
|
2020-02-03 18:32:22 +01:00
|
|
|
/**
|
|
|
|
* Initializes a new drawable object
|
2020-04-20 13:13:04 +02:00
|
|
|
*
|
2020-02-05 05:14:35 +01:00
|
|
|
* @param texture The texture to use for drawing the element
|
2020-04-20 13:13:04 +02:00
|
|
|
* @param xPos The pixel to start drawing on for the x axis
|
|
|
|
* @param yPos The pixel to start drawing on for the y axis
|
2020-02-03 18:32:22 +01:00
|
|
|
*/
|
2020-02-24 18:07:26 +01:00
|
|
|
public DrawableObject(TextureRegion texture, int xPos, int yPos) {
|
2020-02-03 14:06:36 +01:00
|
|
|
this.xPos = xPos;
|
|
|
|
this.yPos = yPos;
|
|
|
|
this.texture = texture;
|
|
|
|
}
|
|
|
|
|
2020-04-20 13:13:04 +02:00
|
|
|
/**
|
|
|
|
* Gets the texture to use for drawing the object
|
|
|
|
*
|
|
|
|
* @return The texture of the object
|
|
|
|
*/
|
2020-02-24 18:07:26 +01:00
|
|
|
public TextureRegion getTexture() {
|
2020-02-03 14:06:36 +01:00
|
|
|
return texture;
|
|
|
|
}
|
|
|
|
|
2020-04-20 13:13:04 +02:00
|
|
|
/**
|
|
|
|
* Gets the x position the object should be drawn on
|
|
|
|
*
|
|
|
|
* <p>The x position should be in terms of the actual pixel position on the rendered game, not the position according
|
|
|
|
* to the game tile. E.g. (128,64) not (2,1).</p>
|
|
|
|
*
|
|
|
|
* @return An x position libgdx
|
|
|
|
*/
|
2020-02-03 14:06:36 +01:00
|
|
|
public int getXPosition() {
|
|
|
|
return xPos;
|
|
|
|
}
|
|
|
|
|
2020-04-20 13:13:04 +02:00
|
|
|
/**
|
|
|
|
* Gets the y position the object should be drawn on
|
|
|
|
*
|
|
|
|
* <p>The y position should be in terms of the actual pixel position on the rendered game, not the position according
|
|
|
|
* to the game tile. E.g. (128,64) not (2,1).</p>
|
|
|
|
*
|
|
|
|
* @return An x position libgdx
|
|
|
|
*/
|
2020-02-03 14:06:36 +01:00
|
|
|
public int getYPosition() {
|
|
|
|
return yPos;
|
|
|
|
}
|
|
|
|
|
2020-04-20 13:13:04 +02:00
|
|
|
/**
|
|
|
|
* Gets the width of the object
|
|
|
|
*
|
|
|
|
* @return A positive integer
|
|
|
|
*/
|
2020-02-03 14:06:36 +01:00
|
|
|
public int getWidth() {
|
|
|
|
return width;
|
|
|
|
}
|
|
|
|
|
2020-04-20 13:13:04 +02:00
|
|
|
/**
|
|
|
|
* Gets the height of the object
|
|
|
|
*
|
|
|
|
* @return A positive integer
|
|
|
|
*/
|
2020-02-03 14:06:36 +01:00
|
|
|
public int getHeight() {
|
|
|
|
return height;
|
|
|
|
}
|
|
|
|
|
2020-04-20 13:13:04 +02:00
|
|
|
/**
|
|
|
|
* Gets the number of degrees to rotate the texture counterclockwise when rendering
|
|
|
|
*
|
|
|
|
* @return An integer
|
|
|
|
*/
|
2020-02-03 14:06:36 +01:00
|
|
|
public int getRotation() {
|
|
|
|
return rotation;
|
|
|
|
}
|
|
|
|
|
2020-04-20 13:13:04 +02:00
|
|
|
/**
|
|
|
|
* Whether to flip the texture on the x-axis when rendering
|
|
|
|
*
|
|
|
|
* @return True if the texture is to be flipped. False otherwise
|
|
|
|
*/
|
2020-02-03 14:06:36 +01:00
|
|
|
public boolean flipX() {
|
|
|
|
return flipX;
|
|
|
|
}
|
|
|
|
|
2020-04-20 13:13:04 +02:00
|
|
|
/**
|
|
|
|
* Whether to flip the texture on the y-axis when rendering
|
|
|
|
*
|
|
|
|
* @return True if the texture is to be flipped. False otherwise
|
|
|
|
*/
|
2020-02-03 14:06:36 +01:00
|
|
|
public boolean flipY() {
|
|
|
|
return flipY;
|
|
|
|
}
|
|
|
|
}
|