diff --git a/frontend/assets/Roboto-Black.ttf b/frontend/assets/Roboto-Black.ttf new file mode 100644 index 0000000000000000000000000000000000000000..0112e7da626ca2f959eca850c806779ba55dbfbd Binary files /dev/null and b/frontend/assets/Roboto-Black.ttf differ diff --git a/frontend/assets/Roboto-Regular.ttf b/frontend/assets/Roboto-Regular.ttf index 67bd9e22486e31cdf67caa1cbdc4c02746af6e33..ddf4bfacb396e97546364ccfeeb9c31dfaea4c25 100644 Binary files a/frontend/assets/Roboto-Regular.ttf and b/frontend/assets/Roboto-Regular.ttf differ diff --git a/frontend/assets/gameplay-skin.atlas b/frontend/assets/gameplay-skin.atlas new file mode 100644 index 0000000000000000000000000000000000000000..a1a43ca1f31b527a946d1964fac1482749114254 --- /dev/null +++ b/frontend/assets/gameplay-skin.atlas @@ -0,0 +1,96 @@ + +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 diff --git a/frontend/assets/gameplay-skin.json b/frontend/assets/gameplay-skin.json new file mode 100644 index 0000000000000000000000000000000000000000..f51104b4ed1ecca0f178fb3ab6c6b3d208b33b49 --- /dev/null +++ b/frontend/assets/gameplay-skin.json @@ -0,0 +1,92 @@ +{ +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 diff --git a/frontend/assets/gameplay-skin.png b/frontend/assets/gameplay-skin.png new file mode 100644 index 0000000000000000000000000000000000000000..899800011a86f538027ce2e3a68512d34483e46d Binary files /dev/null and b/frontend/assets/gameplay-skin.png differ diff --git a/frontend/build.gradle b/frontend/build.gradle index b45378c5400ad14ddd3d227d3d8094d071d7f773..2feeafc7fe23302006df3d3887ae56c36fe10185 100644 --- a/frontend/build.gradle +++ b/frontend/build.gradle @@ -96,5 +96,8 @@ project(":core") { implementation "com.badlogicgames.gdx:gdx-freetype:$gdxVersion" implementation 'com.github.acanthite:freetype-skin:0.4' + + implementation 'com.github.raeleus.stripe:freetype:1.4.5' + } } diff --git a/frontend/core/src/com/game/tankwars/ResourceManager.java b/frontend/core/src/com/game/tankwars/ResourceManager.java index 021ebc389503f1de6624a29e835685f46776675e..7c9e4c8505f67512a4c460a7b36599adca359530 100644 --- a/frontend/core/src/com/game/tankwars/ResourceManager.java +++ b/frontend/core/src/com/game/tankwars/ResourceManager.java @@ -2,15 +2,8 @@ package com.game.tankwars; import com.badlogic.gdx.assets.AssetDescriptor; 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.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.utils.Drawable; import com.badlogic.gdx.utils.GdxRuntimeException; import com.github.acanthite.gdx.graphics.g2d.FreeTypeSkinLoader; @@ -29,6 +22,8 @@ public class ResourceManager { new AssetDescriptor<>("menu-textures.atlas", TextureAtlas.class); private final AssetDescriptor<Skin> MENU_SKIN = new AssetDescriptor<>("menu-textures.json", Skin.class); + private final AssetDescriptor<Skin> GAMEPLAY_SKIN = + new AssetDescriptor<>("gameplay-skin.json", Skin.class); public ResourceManager() { manager = new AssetManager(); @@ -66,6 +61,21 @@ public class ResourceManager { 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 */ diff --git a/frontend/core/src/com/game/tankwars/TankWarsGame.java b/frontend/core/src/com/game/tankwars/TankWarsGame.java index 3c93ec84373938149727812059eb8324ddda054a..befe4b7ff9112dcd97b1f26fead44b5052b6482e 100644 --- a/frontend/core/src/com/game/tankwars/TankWarsGame.java +++ b/frontend/core/src/com/game/tankwars/TankWarsGame.java @@ -4,14 +4,25 @@ package com.game.tankwars; 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.LoginScreen; public class TankWarsGame extends Game { + public static final float SCALE = 10; public static int VIEWPORT_WIDTH = 320; 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 public void create() { this.setScreen(new LoginScreen(this)); diff --git a/frontend/core/src/com/game/tankwars/controller/GameController.java b/frontend/core/src/com/game/tankwars/controller/GameController.java index c005df1dc7f70e8f6da3034ec2b7672d02b99378..78b7051e1c2ca304cc7b27635e5571f066b24672 100644 --- a/frontend/core/src/com/game/tankwars/controller/GameController.java +++ b/frontend/core/src/com/game/tankwars/controller/GameController.java @@ -2,29 +2,35 @@ package com.game.tankwars.controller; import com.badlogic.gdx.Gdx; 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.model.Bullet; import com.game.tankwars.model.Tank; - -import java.util.Arrays; +import com.game.tankwars.view.GameHud; public class GameController { - TankWarsGame tankWarsGame; - Tank tank; - Bullet bullet; - public GameController(Tank tank, TankWarsGame tankWarsGame){ + + private 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.tankWarsGame = tankWarsGame; } 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)) { tank.rotateCannonLeft(); } @@ -32,9 +38,68 @@ public class GameController { tank.rotateCannonRight(); } - if(Gdx.input.justTouched()) { - bullet = new Bullet(tank); - bullet.shoot(); + if(moveRightTouched) { + tank.moveRight(); + } + 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; + } } diff --git a/frontend/core/src/com/game/tankwars/model/Tank.java b/frontend/core/src/com/game/tankwars/model/Tank.java index 43d4746745b3d401fd74261c9f03698e50a53c10..b042a698ea7fd5a67a2e16780e25083e2fb94495 100644 --- a/frontend/core/src/com/game/tankwars/model/Tank.java +++ b/frontend/core/src/com/game/tankwars/model/Tank.java @@ -1,5 +1,6 @@ package com.game.tankwars.model; +import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.math.Rectangle; @@ -37,6 +38,7 @@ public class Tank { private Vector2[] vertices; int posInVertArr; float cannonAngle = 90; + private int power; boolean directionLeft; public Tank(int posInVertArr, Texture chassisTexture, Texture cannonTexture, Terrain terrain, TankWarsGame tankWarsGame, boolean directionLeft) { @@ -49,6 +51,8 @@ public class Tank { this.posInVertArr = posInVertArr; position = vertices[posInVertArr]; + this.power = 25; + this.bounds = new Rectangle(position.x, position.y, TANK_WIDTH, TANK_HEIGHT); this.chassisTexture = chassisTexture; @@ -99,7 +103,7 @@ public class Tank { chassisSprite.flip(true, false); directionLeft = false; } - if (chassis.getPosition().x <= VIEWPORT_WIDTH - TANK_WIDTH){ + if (chassis.getPosition().x <= TankWarsGame.GAMEPORT_WIDTH - TANK_WIDTH){ setPosition(newPos); chassis.setTransform(newPos.x, newPos.y + 0.11f, angle); chassisSprite.setRotation(angle); @@ -176,6 +180,10 @@ public class Tank { public Sprite getChassisSprite() {return chassisSprite;} public Sprite getCannonSprite() {return cannonSprite;} + public int getPower() { + return power; + } + public void setPosition(Vector2 position) { this.position = position; } @@ -184,6 +192,10 @@ public class Tank { this.bounds = bounds; } + public void setPower(int power) { + this.power = power; + } + public void setChassisTexture(Texture texture) { this.chassisTexture = texture; } diff --git a/frontend/core/src/com/game/tankwars/model/Terrain.java b/frontend/core/src/com/game/tankwars/model/Terrain.java index dcd5ff9d255f81e3183fbf1e9f7c023dec080c39..90f1d7736a22422d65d9f39d2cccced337163bf9 100644 --- a/frontend/core/src/com/game/tankwars/model/Terrain.java +++ b/frontend/core/src/com/game/tankwars/model/Terrain.java @@ -1,11 +1,6 @@ package com.game.tankwars.model; -import com.badlogic.gdx.Gdx; 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.math.Vector2; import com.badlogic.gdx.physics.box2d.Body; @@ -26,8 +21,8 @@ public class Terrain { float xStart = -5; float xEnd = 100; - float yMin = 1f; - float yMax = 10; + float yMin = 5f; + float yMax = 15; int points = 10; int vertNumber = 1000; diff --git a/frontend/core/src/com/game/tankwars/view/GameHud.java b/frontend/core/src/com/game/tankwars/view/GameHud.java new file mode 100644 index 0000000000000000000000000000000000000000..634dab2dc3094b246758616f5fb906251a9610d8 --- /dev/null +++ b/frontend/core/src/com/game/tankwars/view/GameHud.java @@ -0,0 +1,136 @@ +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); + } +} diff --git a/frontend/core/src/com/game/tankwars/view/GameScreen.java b/frontend/core/src/com/game/tankwars/view/GameScreen.java index e90df6957940e9cdfe636e752c57cd66e0feefaa..8db938accdaf4e9dd39000ce52d4ffbd809da3c0 100644 --- a/frontend/core/src/com/game/tankwars/view/GameScreen.java +++ b/frontend/core/src/com/game/tankwars/view/GameScreen.java @@ -18,7 +18,7 @@ import com.badlogic.gdx.physics.box2d.Body; import com.badlogic.gdx.physics.box2d.Box2DDebugRenderer; import com.badlogic.gdx.physics.box2d.World; 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.controller.GameController; import com.game.tankwars.model.Box2dWorld; @@ -36,10 +36,12 @@ public class GameScreen implements Screen { ShapeRenderer shapeRender; Tank myTank; Tank opponentTank; + GameHud hud; Box2dWorld model; World world; Terrain terrain; - OrthographicCamera cam; + OrthographicCamera worldCam; + OrthographicCamera hudCam; Box2DDebugRenderer debugRenderer; Bullet bullet; GameController controller; @@ -56,9 +58,16 @@ public class GameScreen implements Screen { model = new Box2dWorld(); world = Box2dWorld.getWorld(); - cam = new OrthographicCamera(VIEWPORT_WIDTH, VIEWPORT_HEIGHT); - cam.position.set(VIEWPORT_WIDTH/2, VIEWPORT_HEIGHT/2, 0); - cam.update(); + + worldCam = new OrthographicCamera(scale(TankWarsGame.GAMEPORT_WIDTH), scale(TankWarsGame.GAMEPORT_HEIGHT)); + 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); terrain = new Terrain(); @@ -77,18 +86,23 @@ public class GameScreen implements Screen { terrain, tankWarsGame, false); - horizontalScaling = Gdx.graphics.getWidth() / VIEWPORT_WIDTH; - verticalScaling = Gdx.graphics.getHeight() / VIEWPORT_HEIGHT; + horizontalScaling = Gdx.graphics.getWidth() / TankWarsGame.GAMEPORT_WIDTH; + 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 public void render(float delta) { model.logicStep(Gdx.graphics.getDeltaTime()); Gdx.gl.glClearColor(0, 0, 100, 100); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); - debugRenderer.render(world, cam.combined); - shapeRender.setProjectionMatrix(cam.combined); + debugRenderer.render(world, worldCam.combined); + shapeRender.setProjectionMatrix(worldCam.combined); controller.checkKeyInput(myTank); @@ -100,7 +114,7 @@ public class GameScreen implements Screen { Sprite s = (Sprite) b.getUserData(); 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())) { s.setRotation(myTank.getAngle()); } @@ -128,6 +142,9 @@ public class GameScreen implements Screen { opponentTank.getChassisSprite().draw(batch); opponentTank.getCannonSprite().draw(batch); batch.end(); + + batch.setProjectionMatrix(hud.getStage().getCamera().combined); + hud.getStage().draw(); } @Override @@ -158,7 +175,12 @@ public class GameScreen implements Screen { public void dispose() { myTank.getChassisTexture().dispose(); myTank.getCannonTexture().dispose(); + hud.getStage().dispose(); batch.dispose(); shapeRender.dispose(); } + + private float scale(float value) { + return value / TankWarsGame.SCALE; + } } diff --git a/frontend/core/src/com/game/tankwars/view/LoginScreen.java b/frontend/core/src/com/game/tankwars/view/LoginScreen.java index 9e7be8adb155f2235d5b018904ff00a2cfd76a07..a0cdefac7214d02493a9443e9cdf784ebf3be1bf 100644 --- a/frontend/core/src/com/game/tankwars/view/LoginScreen.java +++ b/frontend/core/src/com/game/tankwars/view/LoginScreen.java @@ -2,15 +2,25 @@ package com.game.tankwars.view; import com.badlogic.gdx.Gdx; 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.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.ui.Button; import com.badlogic.gdx.scenes.scene2d.ui.Label; import com.badlogic.gdx.scenes.scene2d.ui.Skin; import com.badlogic.gdx.scenes.scene2d.ui.Table; import com.badlogic.gdx.scenes.scene2d.ui.TextButton; import com.badlogic.gdx.scenes.scene2d.ui.Image; 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.FocusListener; import com.badlogic.gdx.utils.Align; import com.badlogic.gdx.utils.ScreenUtils; import com.badlogic.gdx.utils.viewport.ExtendViewport; @@ -114,7 +124,7 @@ public class LoginScreen implements Screen { @Override public void hide() { - Gdx.input.setInputProcessor(null); + //Gdx.input.setInputProcessor(null); dispose(); }