diff --git a/frontend/core/src/com/game/tankwars/TankWarsGame.java b/frontend/core/src/com/game/tankwars/TankWarsGame.java index 9811df045e8287ad2b373ed418b24f2c9429dab1..eb93a26e0a1c3adbb2b0c03410d05e6420368962 100644 --- a/frontend/core/src/com/game/tankwars/TankWarsGame.java +++ b/frontend/core/src/com/game/tankwars/TankWarsGame.java @@ -1,6 +1,10 @@ +/* NOTE: This class now extends the GDX Game-class. +* Previous input handling code is moved to the GameScreen-Class (for now). +*/ package com.game.tankwars; import com.badlogic.gdx.ApplicationAdapter; +import com.badlogic.gdx.Game; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Input; import com.badlogic.gdx.graphics.Texture; @@ -8,37 +12,24 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.utils.ScreenUtils; import com.game.tankwars.model.Tank; +import com.game.tankwars.view.MainMenuScreen; -public class TankWarsGame extends ApplicationAdapter { - SpriteBatch batch; +public class TankWarsGame extends Game { - Tank tank; - @Override - public void create () { - batch = new SpriteBatch(); - tank = new Tank(new Vector2(50, 50), new Texture("tank-khaki.png")); + public void create() { + + MainMenuScreen mainMenuScreen = new MainMenuScreen(this); + this.setScreen(mainMenuScreen); } @Override public void render () { - - if(Gdx.input.isKeyPressed(Input.Keys.D) && !tank.detectCollisionRight()) { - tank.moveRight(); - } - if(Gdx.input.isKeyPressed(Input.Keys.A) && !tank.detectCollisionLeft()) { - tank.moveLeft(); - } - - ScreenUtils.clear(0, 0, 0, 1); - batch.begin(); - batch.draw(tank.getTexture(), tank.getPosition().x, tank.getPosition().y, Tank.TANK_WIDTH, Tank.TANK_HEIGHT); - batch.end(); + super.render(); } @Override public void dispose () { - batch.dispose(); - tank.getTexture().dispose(); + } } diff --git a/frontend/core/src/com/game/tankwars/view/GameOverScreen.java b/frontend/core/src/com/game/tankwars/view/GameOverScreen.java new file mode 100644 index 0000000000000000000000000000000000000000..077d2853b0d56e9f461d2c59b3cb95b8af36dea7 --- /dev/null +++ b/frontend/core/src/com/game/tankwars/view/GameOverScreen.java @@ -0,0 +1,51 @@ +package com.game.tankwars.view; + +import com.badlogic.gdx.Screen; +import com.badlogic.gdx.graphics.OrthographicCamera; +import com.game.tankwars.TankWarsGame; + +public class GameOverScreen implements Screen { + + final TankWarsGame tankWarsGame; + OrthographicCamera camera; + + public GameOverScreen(final TankWarsGame tankWarsGame){ + this.tankWarsGame = tankWarsGame; + camera = new OrthographicCamera(); + } + + @Override + public void show() { + + } + + @Override + public void render(float delta) { + + } + + @Override + public void resize(int width, int height) { + + } + + @Override + public void pause() { + + } + + @Override + public void resume() { + + } + + @Override + public void hide() { + + } + + @Override + public void dispose() { + + } +} diff --git a/frontend/core/src/com/game/tankwars/view/GameScreen.java b/frontend/core/src/com/game/tankwars/view/GameScreen.java new file mode 100644 index 0000000000000000000000000000000000000000..d92f2fba1f6c6dbc2bd3f64281d257f84e8e5aeb --- /dev/null +++ b/frontend/core/src/com/game/tankwars/view/GameScreen.java @@ -0,0 +1,70 @@ +package com.game.tankwars.view; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.Input; +import com.badlogic.gdx.Screen; +import com.badlogic.gdx.graphics.OrthographicCamera; +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.badlogic.gdx.math.Vector2; +import com.badlogic.gdx.utils.ScreenUtils; +import com.game.tankwars.TankWarsGame; +import com.game.tankwars.model.Tank; + +public class GameScreen implements Screen { + final TankWarsGame tankWarsGame; + OrthographicCamera camera; + SpriteBatch batch; + Tank tank; + + public GameScreen(final TankWarsGame tankWarsGame){ + this.tankWarsGame = tankWarsGame; + camera = new OrthographicCamera(); + + batch = new SpriteBatch(); + tank = new Tank(new Vector2(50, 50), new Texture("tank-khaki.png")); + } + @Override + public void render(float delta) { + if(Gdx.input.isKeyPressed(Input.Keys.D)) { + tank.moveRight(); + } + if(Gdx.input.isKeyPressed(Input.Keys.A)) { + tank.moveLeft(); + } + + ScreenUtils.clear(0, 0, 0, 1); + batch.begin(); + batch.draw(tank.getTexture(), tank.getPosition().x, tank.getPosition().y, Tank.TANK_WIDTH, Tank.TANK_HEIGHT); + batch.end(); + } + + @Override + public void show() { + + } + @Override + public void resize(int width, int height) { + + } + + @Override + public void pause() { + + } + + @Override + public void resume() { + + } + + @Override + public void hide() { + + } + + @Override + public void dispose() { + + } +} diff --git a/frontend/core/src/com/game/tankwars/view/GameView.java b/frontend/core/src/com/game/tankwars/view/GameView.java deleted file mode 100644 index 3745607ce3f5f3ed2787a79856a5f503b24c8afc..0000000000000000000000000000000000000000 --- a/frontend/core/src/com/game/tankwars/view/GameView.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.game.tankwars.view; - -public class GameView { -} diff --git a/frontend/core/src/com/game/tankwars/view/MainMenuScreen.java b/frontend/core/src/com/game/tankwars/view/MainMenuScreen.java new file mode 100644 index 0000000000000000000000000000000000000000..82fccd79f0a855e664bda6293b3dde9044ea4ae3 --- /dev/null +++ b/frontend/core/src/com/game/tankwars/view/MainMenuScreen.java @@ -0,0 +1,54 @@ +package com.game.tankwars.view; + +import com.badlogic.gdx.Screen; +import com.badlogic.gdx.graphics.OrthographicCamera; +import com.game.tankwars.TankWarsGame; + +public class MainMenuScreen implements Screen { + final TankWarsGame tankWarsGame; + OrthographicCamera camera; + + public MainMenuScreen(final TankWarsGame tankWarsGame){ + this.tankWarsGame = tankWarsGame; + camera = new OrthographicCamera(); + + //NB! Temporarily directing to GameScreen, this is subject to change + GameScreen gameScreen = new GameScreen(this.tankWarsGame); + tankWarsGame.setScreen(gameScreen); + } + + @Override + public void render(float delta) { + + } + + @Override + public void show() { + + } + + @Override + public void resize(int width, int height) { + + } + + @Override + public void pause() { + + } + + @Override + public void resume() { + + } + + @Override + public void hide() { + + } + + @Override + public void dispose() { + + } +}