mirror of
https://github.com/inf112-v20/Fiasko.git
synced 2025-01-31 23:29:36 +01:00
Legger til et teksturbrett og henter tile teksturen fra den
Gjør om på konverting fra enum til Texture slik at den nå returnerer en TextureRegion i stedet Fjerner ubrukte teksturer Tar hensyn til tekstur-region når brettet tegnes
This commit is contained in:
parent
eb5e6160fb
commit
e4784246bf
BIN
assets/tiles.png
Normal file
BIN
assets/tiles.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 18 MiB |
@ -6,6 +6,7 @@ import com.badlogic.gdx.graphics.GL20;
|
|||||||
import com.badlogic.gdx.graphics.OrthographicCamera;
|
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||||
import com.badlogic.gdx.graphics.Texture;
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||||
|
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||||
import inf112.fiasko.roborally.abstractions.GameTexture;
|
import inf112.fiasko.roborally.abstractions.GameTexture;
|
||||||
import inf112.fiasko.roborally.game.Game;
|
import inf112.fiasko.roborally.game.Game;
|
||||||
import inf112.fiasko.roborally.game.IDrawableGame;
|
import inf112.fiasko.roborally.game.IDrawableGame;
|
||||||
@ -20,19 +21,13 @@ public class GameLauncher extends ApplicationAdapter {
|
|||||||
private IDrawableGame game;
|
private IDrawableGame game;
|
||||||
|
|
||||||
private Texture robotTexture;
|
private Texture robotTexture;
|
||||||
private Texture tileTexture;
|
private Texture textureSheet;
|
||||||
private Texture walledTileTexture;
|
|
||||||
private Texture doublyWalledTileTexture;
|
|
||||||
private Texture slowTransportBandTexture;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void create() {
|
public void create() {
|
||||||
//Loads some textures
|
//Loads some textures
|
||||||
robotTexture = new Texture(Gdx.files.internal("assets/Robot.png"));
|
robotTexture = new Texture(Gdx.files.internal("assets/Robot.png"));
|
||||||
tileTexture = new Texture(Gdx.files.internal("assets/Tile.png"));
|
textureSheet = new Texture(Gdx.files.internal("assets/tiles.png"));
|
||||||
walledTileTexture = new Texture(Gdx.files.internal("assets/WalledTile.png"));
|
|
||||||
doublyWalledTileTexture = new Texture(Gdx.files.internal("assets/DoublyWalledTile.png"));
|
|
||||||
slowTransportBandTexture = new Texture(Gdx.files.internal("assets/TransportBandSlow.png"));
|
|
||||||
|
|
||||||
game = new Game();
|
game = new Game();
|
||||||
camera = new OrthographicCamera();
|
camera = new OrthographicCamera();
|
||||||
@ -49,14 +44,15 @@ public class GameLauncher extends ApplicationAdapter {
|
|||||||
camera.update();
|
camera.update();
|
||||||
batch.setProjectionMatrix(camera.combined);
|
batch.setProjectionMatrix(camera.combined);
|
||||||
batch.begin();
|
batch.begin();
|
||||||
//Renders all elements the game wants to render
|
//Draws all elements the game wants to draw
|
||||||
for (IDrawableObject object : game.objectsToRender()) {
|
for (IDrawableObject object : game.getObjectsToDraw()) {
|
||||||
Texture objectTexture = gameTextureToTexture(object.getTexture());
|
TextureRegion objectTextureRegion = gameTextureToTextureRegion(object.getTexture());
|
||||||
batch.draw(objectTexture, object.getXPosition(), object.getYPosition(),
|
batch.draw(objectTextureRegion.getTexture(), object.getXPosition(), object.getYPosition(),
|
||||||
(float)object.getWidth()/2, (float)object.getHeight()/2, object.getWidth(),
|
(float)object.getWidth()/2, (float)object.getHeight()/2,
|
||||||
object.getHeight(), 1, 1, object.getRotation(),
|
object.getWidth(), object.getHeight(), 1, 1, object.getRotation(),
|
||||||
0, 0, objectTexture.getWidth(), objectTexture.getHeight(), object.flipX(),
|
objectTextureRegion.getRegionX(), objectTextureRegion.getRegionY(),
|
||||||
object.flipY());
|
objectTextureRegion.getRegionWidth(), objectTextureRegion.getRegionHeight(),
|
||||||
|
object.flipX(), object.flipY());
|
||||||
}
|
}
|
||||||
batch.end();
|
batch.end();
|
||||||
}
|
}
|
||||||
@ -64,33 +60,24 @@ public class GameLauncher extends ApplicationAdapter {
|
|||||||
@Override
|
@Override
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
robotTexture.dispose();
|
robotTexture.dispose();
|
||||||
tileTexture.dispose();
|
textureSheet.dispose();
|
||||||
walledTileTexture.dispose();
|
|
||||||
doublyWalledTileTexture.dispose();
|
|
||||||
slowTransportBandTexture.dispose();
|
|
||||||
batch.dispose();
|
batch.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Turns a GameTexture element into a Texture element
|
* Turns a GameTexture element into a TextureRegion element
|
||||||
*
|
*
|
||||||
* This is necessary to keep all libgdx logic in this class only. Otherwise, testing would be painful.
|
* This is necessary to keep all libgdx logic in this class only. Otherwise, testing would be painful.
|
||||||
*
|
*
|
||||||
* @param gameTexture A GameTexture enum
|
* @param gameTexture A GameTexture enum
|
||||||
* @return A Gdx Texture
|
* @return A Gdx TextureRegion
|
||||||
*/
|
*/
|
||||||
private Texture gameTextureToTexture(GameTexture gameTexture) {
|
private TextureRegion gameTextureToTextureRegion(GameTexture gameTexture) {
|
||||||
switch (gameTexture) {
|
switch (gameTexture) {
|
||||||
case ROBOT:
|
case ROBOT:
|
||||||
return robotTexture;
|
return new TextureRegion(robotTexture, 0, 0, 64, 64);
|
||||||
case TILE:
|
case TILE:
|
||||||
return tileTexture;
|
return new TextureRegion(textureSheet, 4*300, 0, 300, 300);
|
||||||
case WALLED_TILE:
|
|
||||||
return walledTileTexture;
|
|
||||||
case DOUBLY_WALLED_TILE:
|
|
||||||
return doublyWalledTileTexture;
|
|
||||||
case SLOW_TRANSPORT_BAND:
|
|
||||||
return slowTransportBandTexture;
|
|
||||||
default:
|
default:
|
||||||
throw new IllegalArgumentException("Non existing texture encountered.");
|
throw new IllegalArgumentException("Non existing texture encountered.");
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,5 @@ package inf112.fiasko.roborally.abstractions;
|
|||||||
*/
|
*/
|
||||||
public enum GameTexture {
|
public enum GameTexture {
|
||||||
ROBOT,
|
ROBOT,
|
||||||
TILE,
|
TILE
|
||||||
WALLED_TILE,
|
|
||||||
DOUBLY_WALLED_TILE,
|
|
||||||
SLOW_TRANSPORT_BAND
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user