diff --git a/frontend/assets/camo-tank-1.png b/frontend/assets/camo-tank-1.png new file mode 100644 index 0000000000000000000000000000000000000000..1952d6fb49a44b6599d5d6802407114f5353f42f Binary files /dev/null and b/frontend/assets/camo-tank-1.png differ diff --git a/frontend/assets/camo-tank-barrel.png b/frontend/assets/camo-tank-barrel.png new file mode 100644 index 0000000000000000000000000000000000000000..30c592bb706069f4a133f11b6d5f218e33432514 Binary files /dev/null and b/frontend/assets/camo-tank-barrel.png differ diff --git a/frontend/core/src/com/game/tankwars/TankWarsGame.java b/frontend/core/src/com/game/tankwars/TankWarsGame.java index befe4b7ff9112dcd97b1f26fead44b5052b6482e..375ab3c98dfac8483f79f1e9bf4069cf02be3140 100644 --- a/frontend/core/src/com/game/tankwars/TankWarsGame.java +++ b/frontend/core/src/com/game/tankwars/TankWarsGame.java @@ -9,6 +9,7 @@ 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.GameScreen; import com.game.tankwars.view.LoginScreen; public class TankWarsGame extends Game { @@ -25,7 +26,7 @@ public class TankWarsGame extends Game { @Override public void create() { - this.setScreen(new LoginScreen(this)); + this.setScreen(new GameScreen(this)); } public int getViewportWidth(){ diff --git a/frontend/core/src/com/game/tankwars/model/Tank.java b/frontend/core/src/com/game/tankwars/model/Tank.java index b042a698ea7fd5a67a2e16780e25083e2fb94495..41236a44780eddebace7003c89c0f97de416d9af 100644 --- a/frontend/core/src/com/game/tankwars/model/Tank.java +++ b/frontend/core/src/com/game/tankwars/model/Tank.java @@ -37,11 +37,13 @@ public class Tank { Terrain terrain; private Vector2[] vertices; int posInVertArr; - float cannonAngle = 90; + float cannonAngle; private int power; boolean directionLeft; + int fuel = 150; + int health = 100; - 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, float cannonAngle) { VIEWPORT_HEIGHT = tankWarsGame.getViewportHeight(); VIEWPORT_WIDTH = tankWarsGame.getViewportWidth(); @@ -52,16 +54,15 @@ public class Tank { position = vertices[posInVertArr]; this.power = 25; + this.cannonAngle = cannonAngle; this.bounds = new Rectangle(position.x, position.y, TANK_WIDTH, TANK_HEIGHT); this.chassisTexture = chassisTexture; chassisSprite = new Sprite(chassisTexture); - chassisSprite.scale(0.4f); this.cannonTexture = cannonTexture; cannonSprite = new Sprite(cannonTexture); - cannonSprite.scale(-0.1f); world = Box2dWorld.getWorld(); bodyDef.type = BodyDef.BodyType.KinematicBody; @@ -75,11 +76,12 @@ public class Tank { chassis = world.createBody(bodyDef); chassis.setUserData(chassisSprite); chassis.createFixture(fixtureDef); + chassisSprite.scale(0.2f); //Cannon shape.setAsBox(CANNON_WIDTH, CANNON_HEIGHT); - cannonSprite.setOrigin(0, cannonSprite.getHeight()/2); + cannonSprite.setOrigin(1, cannonSprite.getHeight()/2); cannon = world.createBody(bodyDef); cannon.setUserData(cannonSprite); @@ -103,12 +105,13 @@ public class Tank { chassisSprite.flip(true, false); directionLeft = false; } - if (chassis.getPosition().x <= TankWarsGame.GAMEPORT_WIDTH - TANK_WIDTH){ + if (chassis.getPosition().x <= TankWarsGame.GAMEPORT_WIDTH/TankWarsGame.SCALE - TANK_WIDTH && fuel > 0){ setPosition(newPos); chassis.setTransform(newPos.x, newPos.y + 0.11f, angle); chassisSprite.setRotation(angle); updateCannonPos(); posInVertArr++; + fuel--; } else { chassis.setTransform(curPos.x, curPos.y + 0.11f, angle); @@ -125,12 +128,13 @@ public class Tank { directionLeft = true; } - if (chassis.getPosition().x >= TANK_WIDTH){ + if (chassis.getPosition().x >= TANK_WIDTH && fuel > 0){ setPosition(newPos); chassis.setTransform(newPos.x, newPos.y + 0.11f, angle); chassisSprite.setRotation(angle); updateCannonPos(); posInVertArr--; + fuel--; } else { chassis.setTransform(curPos.x, curPos.y + 0.11f, angle); @@ -145,18 +149,18 @@ public class Tank { public void updateCannonPos(){ Vector2 chassisPos = chassis.getPosition(); - chassisPos.add(0, 1); + chassisPos.add(0, 0.35f); cannon.setTransform(chassisPos, cannon.getAngle()); } public void rotateCannonRight(){ - if(cannonAngle > -90) { + if(cannonAngle > 90) { cannonAngle--; } } public void rotateCannonLeft(){ - if(cannonAngle < 90) { + if(cannonAngle < 270) { cannonAngle++; } } @@ -179,23 +183,20 @@ public class Tank { } public Sprite getChassisSprite() {return chassisSprite;} public Sprite getCannonSprite() {return cannonSprite;} - public int getPower() { return power; } + public int getFuel(){return fuel;} public void setPosition(Vector2 position) { this.position = position; } - public void setBounds(Rectangle bounds) { 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/GameScreen.java b/frontend/core/src/com/game/tankwars/view/GameScreen.java index 8db938accdaf4e9dd39000ce52d4ffbd809da3c0..5f52edb7565c25c0226c12e830463de393343db7 100644 --- a/frontend/core/src/com/game/tankwars/view/GameScreen.java +++ b/frontend/core/src/com/game/tankwars/view/GameScreen.java @@ -26,6 +26,8 @@ import com.game.tankwars.model.Bullet; import com.game.tankwars.model.Tank; import com.game.tankwars.model.Terrain; +import java.util.Arrays; + public class GameScreen implements Screen { final TankWarsGame tankWarsGame; int VIEWPORT_WIDTH; @@ -43,9 +45,7 @@ public class GameScreen implements Screen { OrthographicCamera worldCam; OrthographicCamera hudCam; Box2DDebugRenderer debugRenderer; - Bullet bullet; GameController controller; - Mesh groundMesh; public GameScreen(final TankWarsGame tankWarsGame){ this.tankWarsGame = tankWarsGame; @@ -73,18 +73,21 @@ public class GameScreen implements Screen { terrain = new Terrain(); int myPos = 50; - int opponentPos = terrain.getVertices().length - 150; + int opponentPos = terrain.getVertices().length - 220; myTank = new Tank(myPos, - new Texture("tank-khaki.png"), - new Texture("cannon.png"), + new Texture("camo-tank-1.png"), + new Texture("camo-tank-barrel.png"), terrain, - tankWarsGame, true); + tankWarsGame, true, + 120); opponentTank = new Tank(opponentPos, - new Texture("tank-khaki.png"), - new Texture("cannon.png"), + new Texture("camo-tank-1.png"), + new Texture("camo-tank-barrel.png"), terrain, - tankWarsGame, false); + tankWarsGame, + false, + 225); horizontalScaling = Gdx.graphics.getWidth() / TankWarsGame.GAMEPORT_WIDTH; verticalScaling = Gdx.graphics.getHeight() / TankWarsGame.GAMEPORT_HEIGHT; @@ -114,19 +117,22 @@ public class GameScreen implements Screen { Sprite s = (Sprite) b.getUserData(); if (s != null) { - s.setPosition(b.getPosition().x * (float) TankWarsGame.SCALE - s.getWidth() / 2, (b.getPosition().y + 0.25f) * (float) TankWarsGame.SCALE); + s.setPosition(b.getPosition().x * (float) TankWarsGame.SCALE - s.getWidth() / 2, + (b.getPosition().y * (float) TankWarsGame.SCALE) - s.getHeight()/2); if (s.equals(myTank.getChassisSprite())) { + s.setOrigin(s.getWidth() / 2, s.getHeight()); s.setRotation(myTank.getAngle()); } if (s.equals(opponentTank.getChassisSprite())) { + s.setOrigin(s.getWidth() / 2, s.getHeight()); s.setRotation(opponentTank.getAngle()); } if (s.equals(myTank.getCannonSprite())) { - s.setOrigin(s.getWidth() / 2, 0); + s.setOrigin(s.getWidth() / 2, s.getHeight()); s.setRotation(myTank.getCannonAngle()); } if (s.equals(opponentTank.getCannonSprite())) { - s.setOrigin(s.getWidth() / s.getWidth(), 0); + s.setOrigin(s.getWidth() / 2 , s.getHeight()); s.setRotation(opponentTank.getCannonAngle()); } }