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..a6cc29f77093e98c0903cc88b0b0edf17b96ea5a --- /dev/null +++ b/frontend/assets/gameplay-skin.atlas @@ -0,0 +1,89 @@ + +gameplay-skin.png +size: 256, 256 +format: RGBA8888 +filter: Linear, Linear +repeat: none +fire-button-light.9 + rotate: false + xy: 1, 1 + 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: 46, 181 + 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 +power-slider.9 + rotate: false + xy: 1, 215 + size: 64, 32 + split: 2, 2, 2, 2 + pad: 31, 30, 15, 14 + orig: 64, 32 + offset: 0, 0 + index: -1 +progress-background.9 + rotate: false + xy: 67, 215 + 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: 101, 217 + size: 30, 30 + orig: 30, 30 + offset: 0, 0 + index: -1 +slider-knob.9 + rotate: false + xy: 46, 147 + size: 10, 32 + split: 0, 0, 0, 0 + orig: 10, 32 + 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..917cb37bc379f13a2334303b3df7896d6784ca2f Binary files /dev/null and b/frontend/assets/gameplay-skin.json differ diff --git a/frontend/assets/gameplay-skin.png b/frontend/assets/gameplay-skin.png new file mode 100644 index 0000000000000000000000000000000000000000..39a98730e9ebf2ee20bb4b3d89cdd78e3d55ad02 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/controller/GameController.java b/frontend/core/src/com/game/tankwars/controller/GameController.java index b085ce214dbddec8e1db2c7edc2a90786008bebd..a5ec5482fc4c6f9bd78ca9328e08fcd25371bbed 100644 --- a/frontend/core/src/com/game/tankwars/controller/GameController.java +++ b/frontend/core/src/com/game/tankwars/controller/GameController.java @@ -2,29 +2,36 @@ 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.Touchable; +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 game; + + private GameHud hud; + + private Tank tank; + + private Bullet bullet; + + private boolean moveRightTouched; + private boolean moveLeftTouched; + + public GameController(TankWarsGame game, GameHud hud, Tank tank) { + this.game = game; + this.hud = hud; this.tank = tank; - this.tankWarsGame = tankWarsGame; } public void checkKeyInput(){ - 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(); } @@ -37,4 +44,73 @@ public class GameController { bullet.shoot(); } } + + public void handleHudEvents() { + hud.getFireButton().addListener(new ChangeListener() { + public void changed (ChangeEvent event, Actor actor) { + System.out.println("Changed!"); + 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; + } + + }); + + if(moveRightTouched) { + tank.moveRight(); + } + if(moveLeftTouched) { + tank.moveLeft(); + } + } + + public boolean isMoveRightTouched() { + return moveRightTouched; + } + + public boolean isMoveLeftTouched() { + return moveLeftTouched; + } + + 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 fb2a7ed180d0b767c5b869ad7263f66c2c5a07a7..ff84658a6925f2f7217fb04e290972f459a90d61 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; @@ -38,6 +39,7 @@ public class Tank { private Vector2[] vertices; int posInVertArr; float cannonAngle = 90; + private int power; public Tank(int posInVertArr, Texture chassisTexture, Texture cannonTexture, Terrain terrain, TankWarsGame tankWarsGame) { VIEWPORT_HEIGHT = tankWarsGame.getViewportHeight(); @@ -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; @@ -159,6 +163,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; } @@ -167,6 +175,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/view/GameHud.java b/frontend/core/src/com/game/tankwars/view/GameHud.java new file mode 100644 index 0000000000000000000000000000000000000000..deffa818a2f1eff718c9fafa86572f0caf1f2768 --- /dev/null +++ b/frontend/core/src/com/game/tankwars/view/GameHud.java @@ -0,0 +1,106 @@ +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.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.ray3k.stripe.FreeTypeSkin; + +public class GameHud { + + private Stage stage; + + 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) { + stage = new Stage(viewport, batch); + + table = new Table(); + table.setFillParent(true); + table.setDebug(true); + + stage.addActor(table); + + skin = new FreeTypeSkin(Gdx.files.internal("gameplay-skin.json")); + + healthProgressBarPlayer = new ProgressBar(0, 100, 1, false, skin); + healthProgressBarPlayer.setValue(40); + healthProgressBarOpponent = new ProgressBar(0, 100, 1, false, skin); + healthProgressBarOpponent.setValue(40); + + table.add(healthProgressBarPlayer).expand().top().left().padTop(10).padLeft(10); + table.add(healthProgressBarOpponent).expand().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("roboto-black-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 Skin getSkin() { + return skin; + } + + public TextButton getFireButton() { + return fireButton; + } + + public Slider getPowerSlider() { + return powerSlider; + } + + public Button getMoveLeft() { + return moveLeft; + } + + public Button getMoveRight() { + return moveRight; + } +} diff --git a/frontend/core/src/com/game/tankwars/view/GameScreen.java b/frontend/core/src/com/game/tankwars/view/GameScreen.java index 83bcae53c1bd141411ec8757f1fc4d85bb9a0853..136be89cde6b7af4c5d5ae7f069b25938c35223f 100644 --- a/frontend/core/src/com/game/tankwars/view/GameScreen.java +++ b/frontend/core/src/com/game/tankwars/view/GameScreen.java @@ -1,7 +1,6 @@ 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.GL20; import com.badlogic.gdx.graphics.Mesh; @@ -9,6 +8,7 @@ import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.Sprite; +import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.math.Vector2; @@ -17,6 +17,9 @@ 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.badlogic.gdx.utils.viewport.Viewport; +import com.badlogic.gdx.utils.viewport.FitViewport; import com.game.tankwars.TankWarsGame; import com.game.tankwars.controller.GameController; import com.game.tankwars.model.Box2dWorld; @@ -33,6 +36,7 @@ public class GameScreen implements Screen { SpriteBatch batch; ShapeRenderer shapeRender; Tank tank; + GameHud hud; Box2dWorld model; World world; Terrain terrain; @@ -64,7 +68,12 @@ public class GameScreen implements Screen { horizontalScaling = Gdx.graphics.getWidth() / VIEWPORT_WIDTH; verticalScaling = Gdx.graphics.getHeight() / VIEWPORT_HEIGHT; - controller = new GameController(tank, tankWarsGame); + hud = new GameHud(new FitViewport(VIEWPORT_WIDTH, VIEWPORT_HEIGHT, cam), batch); + + controller = new GameController(tankWarsGame, hud, tank); + + Gdx.input.setInputProcessor(hud.getStage()); + controller.handleHudEvents(); } @Override public void render(float delta) { @@ -93,7 +102,8 @@ public class GameScreen implements Screen { s.setRotation(tank.getCannonAngle()); } } - } + + hud.getStage().draw(); shapeRender.begin(ShapeRenderer.ShapeType.Filled); terrain.draw(shapeRender); @@ -131,6 +141,7 @@ public class GameScreen implements Screen { @Override public void dispose() { + hud.getStage().dispose(); tank.getChassisTexture().dispose(); tank.getCannonTexture().dispose(); batch.dispose();