mirror of
https://github.com/inf112-v20/Fiasko.git
synced 2025-01-31 15:19:35 +01:00
Legger til en spillstarter og et ufullstendig spill
Legger til GameLauncher som er i stand til å vise et spill i et vindu Legger til Game som er en skjelettklasse for en representasjon av et spill
This commit is contained in:
parent
3add398a16
commit
b3e6521651
49
src/main/java/inf112/skeleton/app/Game.java
Normal file
49
src/main/java/inf112/skeleton/app/Game.java
Normal file
@ -0,0 +1,49 @@
|
||||
package inf112.skeleton.app;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class represent a game which is drawable using libgdx
|
||||
*/
|
||||
public class Game implements IDrawableGame {
|
||||
private final int TILE_SIZE = 64;
|
||||
private final int TILE_NUMBER = 12;
|
||||
private final int BOARD_WIDTH = TILE_SIZE * TILE_NUMBER;
|
||||
private final int BOARD_HEIGHT = TILE_SIZE * TILE_NUMBER;
|
||||
|
||||
private Texture robotTexture;
|
||||
private Texture tileTexture;
|
||||
private Texture walledTileTexture;
|
||||
private Texture doublyWalledTileTexture;
|
||||
private Texture slowTransportBandTexture;
|
||||
|
||||
/**
|
||||
* Instantiates a new Game object
|
||||
*/
|
||||
public Game () {
|
||||
//Loads some textures
|
||||
robotTexture = new Texture(Gdx.files.internal("assets/Robot.png"));
|
||||
tileTexture = new Texture(Gdx.files.internal("assets/Tile.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"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IDrawableObject> objectsToRender() {
|
||||
return null;
|
||||
}
|
||||
}
|
49
src/main/java/inf112/skeleton/app/GameLauncher.java
Normal file
49
src/main/java/inf112/skeleton/app/GameLauncher.java
Normal file
@ -0,0 +1,49 @@
|
||||
package inf112.skeleton.app;
|
||||
|
||||
import com.badlogic.gdx.ApplicationAdapter;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.GL20;
|
||||
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
|
||||
/**
|
||||
* This class renders a game using libgdx
|
||||
*/
|
||||
public class GameLauncher extends ApplicationAdapter {
|
||||
private OrthographicCamera camera;
|
||||
private SpriteBatch batch;
|
||||
private IDrawableGame game;
|
||||
|
||||
@Override
|
||||
public void create() {
|
||||
game = new Game();
|
||||
camera = new OrthographicCamera();
|
||||
camera.setToOrtho(false, game.getWidth(), game.getHeight());
|
||||
batch = new SpriteBatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders all textures necessary to display a game
|
||||
*/
|
||||
public void render() {
|
||||
Gdx.gl.glClearColor(0,0,0.2f,1);
|
||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||
camera.update();
|
||||
batch.setProjectionMatrix(camera.combined);
|
||||
batch.begin();
|
||||
//Renders all elements the game wants to render
|
||||
for (IDrawableObject object : game.objectsToRender()) {
|
||||
batch.draw(object.getTexture(), object.getXPosition(), object.getYPosition(),
|
||||
(float)object.getWidth()/2, (float)object.getHeight()/2, object.getWidth(),
|
||||
object.getHeight(), 1, 1, object.getRotation(),
|
||||
0, 0, object.getTexture().getWidth(), object.getTexture().getHeight(), object.flipX(),
|
||||
object.flipY());
|
||||
}
|
||||
batch.end();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
batch.dispose();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user