diff --git a/src/main/java/inf112/skeleton/app/Game.java b/src/main/java/inf112/skeleton/app/Game.java index 3bbbe51..0851e52 100644 --- a/src/main/java/inf112/skeleton/app/Game.java +++ b/src/main/java/inf112/skeleton/app/Game.java @@ -11,8 +11,6 @@ public class Game implements IDrawableGame { private final int BOARD_WIDTH = TILE_SIZE * TILE_NUMBER; private final int BOARD_HEIGHT = TILE_SIZE * TILE_NUMBER; - - /** * Instantiates a new Game object */ diff --git a/src/main/java/inf112/skeleton/app/GameLauncher.java b/src/main/java/inf112/skeleton/app/GameLauncher.java index 422cfca..3946f71 100644 --- a/src/main/java/inf112/skeleton/app/GameLauncher.java +++ b/src/main/java/inf112/skeleton/app/GameLauncher.java @@ -59,6 +59,11 @@ public class GameLauncher extends ApplicationAdapter { @Override public void dispose() { + robotTexture.dispose(); + tileTexture.dispose(); + walledTileTexture.dispose(); + doublyWalledTileTexture.dispose(); + slowTransportBandTexture.dispose(); batch.dispose(); } diff --git a/src/main/java/inf112/skeleton/app/Main.java b/src/main/java/inf112/skeleton/app/Main.java index 68266b2..36817ce 100644 --- a/src/main/java/inf112/skeleton/app/Main.java +++ b/src/main/java/inf112/skeleton/app/Main.java @@ -2,15 +2,16 @@ package inf112.skeleton.app; import com.badlogic.gdx.backends.lwjgl.LwjglApplication; import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration; +import inf112.skeleton.app.demo.GameBoard; public class Main { public static void main(String[] args) { LwjglApplicationConfiguration cfg = new LwjglApplicationConfiguration(); - cfg.title = "hello-world"; - cfg.width = 480; - cfg.height = 320; + cfg.title = "Game Board"; + cfg.width = 768; + cfg.height = 769; - new LwjglApplication(new HelloWorld(), cfg); + new LwjglApplication(new GameBoard(), cfg); } } \ No newline at end of file diff --git a/src/main/java/inf112/skeleton/app/demo/GameBoard.java b/src/main/java/inf112/skeleton/app/demo/GameBoard.java new file mode 100644 index 0000000..ed4c7f3 --- /dev/null +++ b/src/main/java/inf112/skeleton/app/demo/GameBoard.java @@ -0,0 +1,67 @@ +package inf112.skeleton.app.demo; + +import com.badlogic.gdx.ApplicationAdapter; +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.Input; +import com.badlogic.gdx.graphics.GL20; +import com.badlogic.gdx.graphics.OrthographicCamera; +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.badlogic.gdx.math.Rectangle; + +public class GameBoard extends ApplicationAdapter { + private OrthographicCamera camera; + private SpriteBatch batch; + + private Texture robotTexture; + private Texture tileTexture; + + private Rectangle robot; + + @Override + public void create() { + //Loads some textures + robotTexture = new Texture(Gdx.files.internal("assets/Robot.png")); + tileTexture = new Texture(Gdx.files.internal("assets/Tile.png")); + + robot = new Rectangle((float)768/2,(float)768/2,64,64); + camera = new OrthographicCamera(); + camera.setToOrtho(false, 768, 768); + 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(); + for (int i = 0; i < 12; i++) { + for (int j = 0; j < 12; j++) { + batch.draw(tileTexture, i * 64, j * 64); + } + } + batch.draw(robotTexture, robot.x, robot.y); + batch.end(); + if (Gdx.input.isKeyJustPressed(Input.Keys.RIGHT) && robot.x < 768-64) { + robot.x += 64; + } + if (Gdx.input.isKeyJustPressed(Input.Keys.LEFT) && robot.x > 0) { + robot.x -= 64; + } + if (Gdx.input.isKeyJustPressed(Input.Keys.UP) && robot.y < 768-64) { + robot.y += 64; + } + if (Gdx.input.isKeyJustPressed(Input.Keys.DOWN) && robot.y > 0) { + robot.y -= 64; + } + } + + @Override + public void dispose() { + batch.dispose(); + } +} \ No newline at end of file diff --git a/src/main/java/inf112/skeleton/app/HelloWorld.java b/src/main/java/inf112/skeleton/app/demo/HelloWorld.java similarity index 96% rename from src/main/java/inf112/skeleton/app/HelloWorld.java rename to src/main/java/inf112/skeleton/app/demo/HelloWorld.java index 266481a..e5c3fdc 100644 --- a/src/main/java/inf112/skeleton/app/HelloWorld.java +++ b/src/main/java/inf112/skeleton/app/demo/HelloWorld.java @@ -1,4 +1,4 @@ -package inf112.skeleton.app; +package inf112.skeleton.app.demo; import com.badlogic.gdx.ApplicationListener; import com.badlogic.gdx.Gdx;