diff --git a/frontend/assets/tank-khaki.png b/frontend/assets/tank-khaki.png new file mode 100644 index 0000000000000000000000000000000000000000..bd8a624b9cf87af6539e6018ae7bbd674c927307 Binary files /dev/null and b/frontend/assets/tank-khaki.png differ diff --git a/frontend/core/src/com/game/tankwars/TankWarsGame.java b/frontend/core/src/com/game/tankwars/TankWarsGame.java index fa0de6efc7206bc2ae810c4cbf44dc3ab053ae25..6a985e5a9a5addfb7eb47ea8105d22b8c3ad4e31 100644 --- a/frontend/core/src/com/game/tankwars/TankWarsGame.java +++ b/frontend/core/src/com/game/tankwars/TankWarsGame.java @@ -1,31 +1,44 @@ package com.game.tankwars; import com.badlogic.gdx.ApplicationAdapter; +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.Input; 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.model.Tank; public class TankWarsGame extends ApplicationAdapter { SpriteBatch batch; - Texture img; + + Tank tank; @Override public void create () { batch = new SpriteBatch(); - img = new Texture("badlogic.jpg"); + tank = new Tank(new Vector2(50, 50), new Texture("tank-khaki.png")); } @Override public void render () { - ScreenUtils.clear(1, 0, 0, 1); + + 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(img, 0, 0); + batch.draw(tank.getTexture(), tank.getPosition().x, tank.getPosition().y, Tank.TANK_WIDTH, Tank.TANK_HEIGHT); batch.end(); } @Override public void dispose () { batch.dispose(); - img.dispose(); + tank.getTexture().dispose(); } } diff --git a/frontend/core/src/com/game/tankwars/model/Tank.java b/frontend/core/src/com/game/tankwars/model/Tank.java index 13db49fca143e540fa12970d653b5474d4df7f58..bcac50f899b83eba5182cd6f8cd04aad1c71c83f 100644 --- a/frontend/core/src/com/game/tankwars/model/Tank.java +++ b/frontend/core/src/com/game/tankwars/model/Tank.java @@ -1,4 +1,59 @@ package com.game.tankwars.model; +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.math.Rectangle; +import com.badlogic.gdx.math.Vector2; + public class Tank { + + public static final int TANK_MOVESPEED = 2; + public static final int TANK_WIDTH = 50; + public static final int TANK_HEIGHT = 50; + + private Vector2 position; + + private Rectangle bounds; + + private Texture texture; + + public Tank(Vector2 position, Texture texture) { + this.position = position; + this.bounds = new Rectangle(position.x, position.y, TANK_WIDTH, TANK_HEIGHT); + this.texture = texture; + } + + public Vector2 getPosition() { + return position; + } + + public Rectangle getBounds() { + return bounds; + } + + public Texture getTexture() { + return texture; + } + + public void setPosition(Vector2 position) { + this.position = position; + } + + public void setBounds(Rectangle bounds) { + this.bounds = bounds; + } + + public void setTexture(Texture texture) { + this.texture = texture; + } + + + public void moveRight() { + position.x += TANK_MOVESPEED; + } + + public void moveLeft() { + position.x -= TANK_MOVESPEED; + } + + }