Skip to content
Snippets Groups Projects
Commit b2ed066b authored by Jan Einar Thorvaldsen's avatar Jan Einar Thorvaldsen
Browse files

Resolve "Screen logic"

parent 54b0b598
No related branches found
No related tags found
1 merge request!10Resolve "Screen logic"
/* 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();
}
}
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() {
}
}
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() {
}
}
package com.game.tankwars.view;
public class GameView {
}
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() {
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment