Skip to content
Snippets Groups Projects
Commit 9cae767e authored by Magnus Segtnan Skjølberg's avatar Magnus Segtnan Skjølberg
Browse files

Merge branch 'combine-hud-game' into 'main'

Combine hud with gameplay

See merge request !32
parents f5c00d5c 90eb6ea8
Branches feat/SignUp
No related tags found
1 merge request!32Combine hud with gameplay
Pipeline #214721 passed
Showing
with 495 additions and 43 deletions
File added
No preview for this file type
gameplay-skin.png
size: 256, 256
format: RGBA8888
filter: Linear, Linear
repeat: none
fire-button-light.9
rotate: false
xy: 67, 213
size: 32, 32
split: 1, 1, 1, 1
pad: 13, 13, 2, 2
orig: 32, 32
offset: 0, 0
index: -1
fire-button.9
rotate: false
xy: 1, 1
size: 32, 32
split: 1, 1, 1, 1
pad: 13, 13, 1, 1
orig: 32, 32
offset: 0, 0
index: -1
move-left-light.9
rotate: false
xy: 1, 35
size: 43, 43
split: 0, 0, 0, 0
orig: 43, 43
offset: 0, 0
index: -1
move-left.9
rotate: false
xy: 1, 125
size: 43, 43
split: 0, 0, 0, 0
orig: 43, 43
offset: 0, 0
index: -1
move-right-light.9
rotate: false
xy: 1, 80
size: 43, 43
split: 0, 0, 0, 0
orig: 43, 43
offset: 0, 0
index: -1
move-right.9
rotate: false
xy: 1, 170
size: 43, 43
split: 0, 0, 0, 0
orig: 43, 43
offset: 0, 0
index: -1
progress-background.9
rotate: false
xy: 101, 213
size: 32, 32
split: 3, 3, 3, 3
pad: 1, 1, 1, 1
orig: 32, 32
offset: 0, 0
index: -1
progress-knob
rotate: false
xy: 169, 215
size: 30, 30
orig: 30, 30
offset: 0, 0
index: -1
slider-background.9
rotate: false
xy: 135, 213
size: 32, 32
split: 1, 1, 1, 1
orig: 32, 32
offset: 0, 0
index: -1
slider-knob-before.9
rotate: false
xy: 1, 215
size: 64, 30
split: 1, 1, 1, 1
orig: 64, 30
offset: 0, 0
index: -1
slider-knob.9
rotate: false
xy: 46, 177
size: 10, 36
split: 1, 1, 1, 1
orig: 10, 36
offset: 0, 0
index: -1
{
com.badlogic.gdx.graphics.Color: {
black: {
r: 0
g: 0
b: 0
a: 1
}
yellow: {
r: 0.98039216
g: 1
b: 0
a: 1
}
red: {
r: 1
g: 0
b: 0
a: 1
}
white: {
r: 1
g: 1
b: 1
a: 1
}
}
BitmapFont: {
large: {
file: Roboto-Black.ttf
size: 28
}
largest: {
file: Roboto-Black.ttf
size: 30
}
default: {
file: Roboto-Regular.ttf
size: 16
}
}
com.badlogic.gdx.scenes.scene2d.ui.Button$ButtonStyle: {
move-right: {
up: move-right.9
down: move-right-light.9
}
move-left: {
up: move-left.9
down: move-left-light.9
}
}
com.badlogic.gdx.scenes.scene2d.ui.Label$LabelStyle: {
default: {
font: default
fontColor: black
}
large-black: {
font: large
fontColor: black
}
large-white: {
font: large
fontColor: white
}
}
com.badlogic.gdx.scenes.scene2d.ui.ProgressBar$ProgressBarStyle: {
default-horizontal: {
background: progress-background.9
knobBefore: progress-knob
}
}
com.badlogic.gdx.scenes.scene2d.ui.Slider$SliderStyle: {
default-horizontal: {
background: slider-background.9
knob: slider-knob.9
knobBefore: slider-knob-before.9
}
}
com.badlogic.gdx.scenes.scene2d.ui.TextButton$TextButtonStyle: {
default: {
font: largest
fontColor: yellow
up: fire-button.9
down: fire-button-light.9
}
}
com.badlogic.gdx.scenes.scene2d.ui.TextTooltip$TextTooltipStyle: {
default: {
label: default
}
}
}
\ No newline at end of file
frontend/assets/gameplay-skin.png

9.06 KiB

...@@ -96,5 +96,8 @@ project(":core") { ...@@ -96,5 +96,8 @@ project(":core") {
implementation "com.badlogicgames.gdx:gdx-freetype:$gdxVersion" implementation "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
implementation 'com.github.acanthite:freetype-skin:0.4' implementation 'com.github.acanthite:freetype-skin:0.4'
implementation 'com.github.raeleus.stripe:freetype:1.4.5'
} }
} }
...@@ -2,15 +2,8 @@ package com.game.tankwars; ...@@ -2,15 +2,8 @@ package com.game.tankwars;
import com.badlogic.gdx.assets.AssetDescriptor; import com.badlogic.gdx.assets.AssetDescriptor;
import com.badlogic.gdx.assets.AssetManager; import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.assets.loaders.FileHandleResolver;
import com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.TextureAtlas; import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGeneratorLoader;
import com.badlogic.gdx.graphics.g2d.freetype.FreetypeFontLoader;
import com.badlogic.gdx.scenes.scene2d.ui.Skin; import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.utils.Drawable;
import com.badlogic.gdx.utils.GdxRuntimeException; import com.badlogic.gdx.utils.GdxRuntimeException;
import com.github.acanthite.gdx.graphics.g2d.FreeTypeSkinLoader; import com.github.acanthite.gdx.graphics.g2d.FreeTypeSkinLoader;
...@@ -29,6 +22,8 @@ public class ResourceManager { ...@@ -29,6 +22,8 @@ public class ResourceManager {
new AssetDescriptor<>("menu-textures.atlas", TextureAtlas.class); new AssetDescriptor<>("menu-textures.atlas", TextureAtlas.class);
private final AssetDescriptor<Skin> MENU_SKIN = private final AssetDescriptor<Skin> MENU_SKIN =
new AssetDescriptor<>("menu-textures.json", Skin.class); new AssetDescriptor<>("menu-textures.json", Skin.class);
private final AssetDescriptor<Skin> GAMEPLAY_SKIN =
new AssetDescriptor<>("gameplay-skin.json", Skin.class);
public ResourceManager() { public ResourceManager() {
manager = new AssetManager(); manager = new AssetManager();
...@@ -66,6 +61,21 @@ public class ResourceManager { ...@@ -66,6 +61,21 @@ public class ResourceManager {
return null; return null;
} }
/**
* Loads the Skin for the gameplay,
* @return loaded Skin object with JSON file, null on loading error
*/
public Skin loadAndGetGameplayHudAssets() {
if (!manager.isLoaded(GAMEPLAY_SKIN)) manager.load(GAMEPLAY_SKIN);
try {
manager.finishLoading();
return manager.get(GAMEPLAY_SKIN);
} catch(GdxRuntimeException error) {
System.out.println(error.getMessage());
}
return null;
}
/** /**
* Block until all currently loaded assets are finished loading * Block until all currently loaded assets are finished loading
*/ */
......
...@@ -4,14 +4,25 @@ ...@@ -4,14 +4,25 @@
package com.game.tankwars; package com.game.tankwars;
import com.badlogic.gdx.Game; import com.badlogic.gdx.Game;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.game.tankwars.view.FindGameScreen; import com.game.tankwars.view.FindGameScreen;
import com.game.tankwars.view.LoginScreen; import com.game.tankwars.view.LoginScreen;
public class TankWarsGame extends Game { public class TankWarsGame extends Game {
public static final float SCALE = 10;
public static int VIEWPORT_WIDTH = 320; public static int VIEWPORT_WIDTH = 320;
public static int VIEWPORT_HEIGHT = 240; public static int VIEWPORT_HEIGHT = 240;
public static final int GAMEPORT_WIDTH = 720;
public static final int GAMEPORT_HEIGHT = 480;
private SpriteBatch batch;
private BitmapFont font;
@Override @Override
public void create() { public void create() {
this.setScreen(new LoginScreen(this)); this.setScreen(new LoginScreen(this));
......
...@@ -2,29 +2,35 @@ package com.game.tankwars.controller; ...@@ -2,29 +2,35 @@ package com.game.tankwars.controller;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input; import com.badlogic.gdx.Input;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.game.tankwars.TankWarsGame; import com.game.tankwars.TankWarsGame;
import com.game.tankwars.model.Bullet; import com.game.tankwars.model.Bullet;
import com.game.tankwars.model.Tank; import com.game.tankwars.model.Tank;
import com.game.tankwars.view.GameHud;
import java.util.Arrays;
public class GameController { public class GameController {
TankWarsGame tankWarsGame;
Tank tank; private TankWarsGame tankWarsGame;
Bullet bullet;
public GameController(Tank tank, TankWarsGame tankWarsGame){ private GameHud hud;
private Tank tank;
private Bullet bullet;
private boolean moveRightTouched;
private boolean moveLeftTouched;
public GameController(Tank tank, TankWarsGame tankWarsGame, GameHud hud) {
this.hud = hud;
this.tank = tank; this.tank = tank;
this.tankWarsGame = tankWarsGame; this.tankWarsGame = tankWarsGame;
} }
public void checkKeyInput(Tank tank){ public void checkKeyInput(Tank tank){
if(Gdx.input.isKeyPressed(Input.Keys.D)) {
tank.moveRight();
}
else if(Gdx.input.isKeyPressed(Input.Keys.A)) {
tank.moveLeft();
}
if(Gdx.input.isKeyPressed(Input.Keys.Q)) { if(Gdx.input.isKeyPressed(Input.Keys.Q)) {
tank.rotateCannonLeft(); tank.rotateCannonLeft();
} }
...@@ -32,9 +38,68 @@ public class GameController { ...@@ -32,9 +38,68 @@ public class GameController {
tank.rotateCannonRight(); tank.rotateCannonRight();
} }
if(Gdx.input.justTouched()) { if(moveRightTouched) {
bullet = new Bullet(tank); tank.moveRight();
bullet.shoot(); }
else if(moveLeftTouched) {
tank.moveLeft();
} }
} }
public void handleHudEvents() {
hud.getFireButton().addListener(new ChangeListener() {
public void changed (ChangeEvent event, Actor actor) {
bullet = new Bullet(tank);
bullet.shoot();
//actor.setTouchable(Touchable.disabled);
// TODO: send turn to server + enable touchable when it is players turn
endPlayerTurn();
}
});
hud.getPowerSlider().addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
System.out.println(hud.getPowerSlider().getValue());
tank.setPower(Math.round(hud.getPowerSlider().getValue()));
}
});
hud.getMoveLeft().addListener(new InputListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
moveLeftTouched = true;
return true;
}
@Override
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
moveLeftTouched = false;
}
});
hud.getMoveRight().addListener(new InputListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
moveRightTouched = true;
return true;
}
@Override
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
moveRightTouched = false;
}
});
}
public boolean endPlayerTurn() {
System.out.println(tank.getPower());
System.out.println(tank.getPosition());
// end turn for player and send data to server
return true;
}
} }
package com.game.tankwars.model; package com.game.tankwars.model;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.math.Rectangle;
...@@ -37,6 +38,7 @@ public class Tank { ...@@ -37,6 +38,7 @@ public class Tank {
private Vector2[] vertices; private Vector2[] vertices;
int posInVertArr; int posInVertArr;
float cannonAngle = 90; float cannonAngle = 90;
private int power;
boolean directionLeft; boolean directionLeft;
public Tank(int posInVertArr, Texture chassisTexture, Texture cannonTexture, Terrain terrain, TankWarsGame tankWarsGame, boolean directionLeft) { public Tank(int posInVertArr, Texture chassisTexture, Texture cannonTexture, Terrain terrain, TankWarsGame tankWarsGame, boolean directionLeft) {
...@@ -49,6 +51,8 @@ public class Tank { ...@@ -49,6 +51,8 @@ public class Tank {
this.posInVertArr = posInVertArr; this.posInVertArr = posInVertArr;
position = vertices[posInVertArr]; position = vertices[posInVertArr];
this.power = 25;
this.bounds = new Rectangle(position.x, position.y, TANK_WIDTH, TANK_HEIGHT); this.bounds = new Rectangle(position.x, position.y, TANK_WIDTH, TANK_HEIGHT);
this.chassisTexture = chassisTexture; this.chassisTexture = chassisTexture;
...@@ -99,7 +103,7 @@ public class Tank { ...@@ -99,7 +103,7 @@ public class Tank {
chassisSprite.flip(true, false); chassisSprite.flip(true, false);
directionLeft = false; directionLeft = false;
} }
if (chassis.getPosition().x <= VIEWPORT_WIDTH - TANK_WIDTH){ if (chassis.getPosition().x <= TankWarsGame.GAMEPORT_WIDTH - TANK_WIDTH){
setPosition(newPos); setPosition(newPos);
chassis.setTransform(newPos.x, newPos.y + 0.11f, angle); chassis.setTransform(newPos.x, newPos.y + 0.11f, angle);
chassisSprite.setRotation(angle); chassisSprite.setRotation(angle);
...@@ -176,6 +180,10 @@ public class Tank { ...@@ -176,6 +180,10 @@ public class Tank {
public Sprite getChassisSprite() {return chassisSprite;} public Sprite getChassisSprite() {return chassisSprite;}
public Sprite getCannonSprite() {return cannonSprite;} public Sprite getCannonSprite() {return cannonSprite;}
public int getPower() {
return power;
}
public void setPosition(Vector2 position) { public void setPosition(Vector2 position) {
this.position = position; this.position = position;
} }
...@@ -184,6 +192,10 @@ public class Tank { ...@@ -184,6 +192,10 @@ public class Tank {
this.bounds = bounds; this.bounds = bounds;
} }
public void setPower(int power) {
this.power = power;
}
public void setChassisTexture(Texture texture) { public void setChassisTexture(Texture texture) {
this.chassisTexture = texture; this.chassisTexture = texture;
} }
......
package com.game.tankwars.model; package com.game.tankwars.model;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Mesh;
import com.badlogic.gdx.graphics.VertexAttribute;
import com.badlogic.gdx.graphics.VertexAttributes;
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body; import com.badlogic.gdx.physics.box2d.Body;
...@@ -26,8 +21,8 @@ public class Terrain { ...@@ -26,8 +21,8 @@ public class Terrain {
float xStart = -5; float xStart = -5;
float xEnd = 100; float xEnd = 100;
float yMin = 1f; float yMin = 5f;
float yMax = 10; float yMax = 15;
int points = 10; int points = 10;
int vertNumber = 1000; int vertNumber = 1000;
......
package com.game.tankwars.view;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Button;
import com.badlogic.gdx.scenes.scene2d.ui.Container;
import com.badlogic.gdx.scenes.scene2d.ui.HorizontalGroup;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.ProgressBar;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Slider;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.utils.viewport.Viewport;
import com.game.tankwars.ResourceManager;
import com.ray3k.stripe.FreeTypeSkin;
public class GameHud {
private Stage stage;
private Viewport viewport;
private Table table;
private Skin skin;
private ProgressBar healthProgressBarPlayer;
private ProgressBar healthProgressBarOpponent;
private TextButton fireButton;
private HorizontalGroup powerContainer;
private Label powerLabel;
private Slider powerSlider;
private Button moveLeft;
private Button moveRight;
private HorizontalGroup moveContainer;
public GameHud(Viewport viewport, SpriteBatch batch) {
this.viewport = viewport;
stage = new Stage(viewport, batch);
table = new Table();
table.setFillParent(true);
table.setDebug(false);
stage.addActor(table);
skin = ResourceManager.getInstance().loadAndGetGameplayHudAssets();
healthProgressBarPlayer = new ProgressBar(0, 100, 1, false, skin);
healthProgressBarPlayer.setValue(100);
healthProgressBarOpponent = new ProgressBar(0, 100, 1, false, skin);
healthProgressBarOpponent.setValue(100);
Container HpOpponentWrapper = new Container(healthProgressBarOpponent);
HpOpponentWrapper.setTransform(true);
HpOpponentWrapper.setOrigin(HpOpponentWrapper.getPrefWidth() / 2, HpOpponentWrapper.getPrefHeight() / 2);
HpOpponentWrapper.setRotation(180);
table.add(healthProgressBarPlayer).expand().top().left().padTop(10).padLeft(10);
table.add(HpOpponentWrapper).colspan(2).top().right().padTop(10).padRight(10);
table.row();
fireButton = new TextButton("Fire!", skin);
table.add(fireButton).expand().bottom().left().padLeft(10).padBottom(10);
powerLabel = new Label("Power", skin.get("large-white", Label.LabelStyle.class));
powerSlider = new Slider(0, 100, 1, false, skin);
powerContainer = new HorizontalGroup().space(10);
powerContainer.addActor(powerLabel);
powerContainer.addActor(powerSlider);
table.add(powerContainer).expand().bottom().padBottom(10);
moveLeft = new Button(skin.get("move-left", Button.ButtonStyle.class));
moveRight = new Button(skin.get("move-right", Button.ButtonStyle.class));
moveContainer = new HorizontalGroup().space(10);
moveContainer.addActor(moveLeft);
moveContainer.addActor(moveRight);
table.add(moveContainer).expand().bottom().right().padBottom(10).padRight(10);
}
public Stage getStage() {
return stage;
}
public Viewport getViewport() {
return viewport;
}
public Skin getSkin() {
return skin;
}
public TextButton getFireButton() {
return fireButton;
}
public Slider getPowerSlider() {
return powerSlider;
}
public Button getMoveLeft() {
return moveLeft;
}
public Button getMoveRight() {
return moveRight;
}
/**
* Set visible health of player
* @param health new health of player
*/
public void setPlayerHealth(int health) {
healthProgressBarPlayer.setValue(health);
}
/**
* Set visible health of opponent
* @param health new health of opponent
*/
public void setOpponentHealth(int health) {
healthProgressBarOpponent.setValue(health);
}
}
...@@ -18,7 +18,7 @@ import com.badlogic.gdx.physics.box2d.Body; ...@@ -18,7 +18,7 @@ import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.Box2DDebugRenderer; import com.badlogic.gdx.physics.box2d.Box2DDebugRenderer;
import com.badlogic.gdx.physics.box2d.World; import com.badlogic.gdx.physics.box2d.World;
import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.ScreenUtils; import com.badlogic.gdx.utils.viewport.FitViewport;
import com.game.tankwars.TankWarsGame; import com.game.tankwars.TankWarsGame;
import com.game.tankwars.controller.GameController; import com.game.tankwars.controller.GameController;
import com.game.tankwars.model.Box2dWorld; import com.game.tankwars.model.Box2dWorld;
...@@ -36,10 +36,12 @@ public class GameScreen implements Screen { ...@@ -36,10 +36,12 @@ public class GameScreen implements Screen {
ShapeRenderer shapeRender; ShapeRenderer shapeRender;
Tank myTank; Tank myTank;
Tank opponentTank; Tank opponentTank;
GameHud hud;
Box2dWorld model; Box2dWorld model;
World world; World world;
Terrain terrain; Terrain terrain;
OrthographicCamera cam; OrthographicCamera worldCam;
OrthographicCamera hudCam;
Box2DDebugRenderer debugRenderer; Box2DDebugRenderer debugRenderer;
Bullet bullet; Bullet bullet;
GameController controller; GameController controller;
...@@ -56,9 +58,16 @@ public class GameScreen implements Screen { ...@@ -56,9 +58,16 @@ public class GameScreen implements Screen {
model = new Box2dWorld(); model = new Box2dWorld();
world = Box2dWorld.getWorld(); world = Box2dWorld.getWorld();
cam = new OrthographicCamera(VIEWPORT_WIDTH, VIEWPORT_HEIGHT);
cam.position.set(VIEWPORT_WIDTH/2, VIEWPORT_HEIGHT/2, 0); worldCam = new OrthographicCamera(scale(TankWarsGame.GAMEPORT_WIDTH), scale(TankWarsGame.GAMEPORT_HEIGHT));
cam.update(); worldCam.position.set(scale(TankWarsGame.GAMEPORT_WIDTH)/2, scale(TankWarsGame.GAMEPORT_HEIGHT)/2, 0);
hudCam = new OrthographicCamera(TankWarsGame.GAMEPORT_WIDTH, TankWarsGame.GAMEPORT_HEIGHT);
hudCam.position.set(TankWarsGame.GAMEPORT_WIDTH/2, TankWarsGame.GAMEPORT_HEIGHT/2, 0);
worldCam.update();
hudCam.update();
debugRenderer = new Box2DDebugRenderer(true, true, true, true, true, true); debugRenderer = new Box2DDebugRenderer(true, true, true, true, true, true);
terrain = new Terrain(); terrain = new Terrain();
...@@ -77,18 +86,23 @@ public class GameScreen implements Screen { ...@@ -77,18 +86,23 @@ public class GameScreen implements Screen {
terrain, terrain,
tankWarsGame, false); tankWarsGame, false);
horizontalScaling = Gdx.graphics.getWidth() / VIEWPORT_WIDTH; horizontalScaling = Gdx.graphics.getWidth() / TankWarsGame.GAMEPORT_WIDTH;
verticalScaling = Gdx.graphics.getHeight() / VIEWPORT_HEIGHT; verticalScaling = Gdx.graphics.getHeight() / TankWarsGame.GAMEPORT_HEIGHT;
hud = new GameHud(new FitViewport(TankWarsGame.GAMEPORT_WIDTH, TankWarsGame.GAMEPORT_HEIGHT, hudCam), batch);
controller = new GameController(myTank, tankWarsGame); controller = new GameController(myTank, tankWarsGame, hud);
Gdx.input.setInputProcessor(hud.getStage());
controller.handleHudEvents();
} }
@Override @Override
public void render(float delta) { public void render(float delta) {
model.logicStep(Gdx.graphics.getDeltaTime()); model.logicStep(Gdx.graphics.getDeltaTime());
Gdx.gl.glClearColor(0, 0, 100, 100); Gdx.gl.glClearColor(0, 0, 100, 100);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
debugRenderer.render(world, cam.combined); debugRenderer.render(world, worldCam.combined);
shapeRender.setProjectionMatrix(cam.combined); shapeRender.setProjectionMatrix(worldCam.combined);
controller.checkKeyInput(myTank); controller.checkKeyInput(myTank);
...@@ -100,7 +114,7 @@ public class GameScreen implements Screen { ...@@ -100,7 +114,7 @@ public class GameScreen implements Screen {
Sprite s = (Sprite) b.getUserData(); Sprite s = (Sprite) b.getUserData();
if (s != null) { if (s != null) {
s.setPosition(b.getPosition().x * (float) horizontalScaling - s.getWidth() / 2, (b.getPosition().y + 0.25f) * (float) verticalScaling); s.setPosition(b.getPosition().x * (float) TankWarsGame.SCALE - s.getWidth() / 2, (b.getPosition().y + 0.25f) * (float) TankWarsGame.SCALE);
if (s.equals(myTank.getChassisSprite())) { if (s.equals(myTank.getChassisSprite())) {
s.setRotation(myTank.getAngle()); s.setRotation(myTank.getAngle());
} }
...@@ -128,6 +142,9 @@ public class GameScreen implements Screen { ...@@ -128,6 +142,9 @@ public class GameScreen implements Screen {
opponentTank.getChassisSprite().draw(batch); opponentTank.getChassisSprite().draw(batch);
opponentTank.getCannonSprite().draw(batch); opponentTank.getCannonSprite().draw(batch);
batch.end(); batch.end();
batch.setProjectionMatrix(hud.getStage().getCamera().combined);
hud.getStage().draw();
} }
@Override @Override
...@@ -158,7 +175,12 @@ public class GameScreen implements Screen { ...@@ -158,7 +175,12 @@ public class GameScreen implements Screen {
public void dispose() { public void dispose() {
myTank.getChassisTexture().dispose(); myTank.getChassisTexture().dispose();
myTank.getCannonTexture().dispose(); myTank.getCannonTexture().dispose();
hud.getStage().dispose();
batch.dispose(); batch.dispose();
shapeRender.dispose(); shapeRender.dispose();
} }
private float scale(float value) {
return value / TankWarsGame.SCALE;
}
} }
...@@ -2,15 +2,25 @@ package com.game.tankwars.view; ...@@ -2,15 +2,25 @@ package com.game.tankwars.view;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen; import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Event;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.badlogic.gdx.scenes.scene2d.Stage; import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Button;
import com.badlogic.gdx.scenes.scene2d.ui.Label; import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Skin; import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table; import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton; import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.Image; import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.TextField; import com.badlogic.gdx.scenes.scene2d.ui.TextField;
import com.badlogic.gdx.scenes.scene2d.ui.Value;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import com.badlogic.gdx.scenes.scene2d.utils.Drawable; import com.badlogic.gdx.scenes.scene2d.utils.Drawable;
import com.badlogic.gdx.scenes.scene2d.utils.FocusListener;
import com.badlogic.gdx.utils.Align; import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.ScreenUtils; import com.badlogic.gdx.utils.ScreenUtils;
import com.badlogic.gdx.utils.viewport.ExtendViewport; import com.badlogic.gdx.utils.viewport.ExtendViewport;
...@@ -114,7 +124,7 @@ public class LoginScreen implements Screen { ...@@ -114,7 +124,7 @@ public class LoginScreen implements Screen {
@Override @Override
public void hide() { public void hide() {
Gdx.input.setInputProcessor(null); //Gdx.input.setInputProcessor(null);
dispose(); 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