Legger til en demo av et spillbrett

Bytter fra HelloWorld til GameBoard i Main
Legger til små forbedringer til søppelinnsamling
This commit is contained in:
Kristian Knarvik 2020-01-31 17:39:05 +01:00
parent 646404bc23
commit f083026866
5 changed files with 78 additions and 7 deletions

View File

@ -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
*/

View File

@ -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();
}

View File

@ -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);
}
}

View File

@ -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();
}
}

View File

@ -1,4 +1,4 @@
package inf112.skeleton.app;
package inf112.skeleton.app.demo;
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;