From 9f58fa4a33ba91b21b7b291917c74f5ba6ccc2ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laure=CE=B7t?= Date: Mon, 5 Apr 2021 23:31:06 +0200 Subject: [PATCH] feat: Player can move around his Planet --- core/src/bzh/fainsin/sagittarius/Arrow.java | 16 ++++++++++------ core/src/bzh/fainsin/sagittarius/Player.java | 15 +++++++++++++-- .../bzh/fainsin/sagittarius/SagittariusGame.java | 1 - 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/core/src/bzh/fainsin/sagittarius/Arrow.java b/core/src/bzh/fainsin/sagittarius/Arrow.java index 1f1f067..9761aa4 100644 --- a/core/src/bzh/fainsin/sagittarius/Arrow.java +++ b/core/src/bzh/fainsin/sagittarius/Arrow.java @@ -78,12 +78,16 @@ class Arrow extends Entity { } void renderDebug(Batch batch, BitmapFont font) { - font.draw(batch, "TTL = " + this.TTL, this.position.x, this.position.y + font.getCapHeight()*5); - font.draw(batch, "pos = " + this.position, this.position.x, this.position.y + font.getCapHeight()*4); - font.draw(batch, "speed = " + this.velocity, this.position.x, this.position.y + font.getCapHeight()*3); - font.draw(batch, "accel = " + this.acceleration, this.position.x, this.position.y + font.getCapHeight()*2); - font.draw(batch, "force = " + this.force, this.position.x, this.position.y + font.getCapHeight()*1); - font.draw(batch, "angle = " + this.angle, this.position.x, this.position.y); + + // TODO : dirty, do it in an other way + if (!hasLanded()) { + font.draw(batch, "TTL = " + this.TTL, this.position.x, this.position.y + font.getCapHeight()*5); + font.draw(batch, "pos = " + this.position, this.position.x, this.position.y + font.getCapHeight()*4); + font.draw(batch, "speed = " + this.velocity, this.position.x, this.position.y + font.getCapHeight()*3); + font.draw(batch, "accel = " + this.acceleration, this.position.x, this.position.y + font.getCapHeight()*2); + font.draw(batch, "force = " + this.force, this.position.x, this.position.y + font.getCapHeight()*1); + font.draw(batch, "angle = " + this.angle, this.position.x, this.position.y); + } } } diff --git a/core/src/bzh/fainsin/sagittarius/Player.java b/core/src/bzh/fainsin/sagittarius/Player.java index 0406923..34e25b0 100644 --- a/core/src/bzh/fainsin/sagittarius/Player.java +++ b/core/src/bzh/fainsin/sagittarius/Player.java @@ -1,10 +1,14 @@ package bzh.fainsin.sagittarius; +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.Input.Buttons; +import com.badlogic.gdx.Input.Keys; import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.math.Vector2; +import com.badlogic.gdx.scenes.scene2d.ui.Button; class Player extends Entity { @@ -40,12 +44,19 @@ class Player extends Entity { void update(float deltaTime) { + // TODO : do eventListening instead of polling + // TODO : if player moving, add his speed to the arrow + + if (Gdx.input.isKeyPressed(Keys.LEFT)) { + this.angle += 100.0f / home.getRadius(); + } else if (Gdx.input.isKeyPressed(Keys.RIGHT)) { + this.angle -= 100.0f / home.getRadius(); + } + computePosition(); bow.update(deltaTime); - // this.angle += 100.0f / home.getRadius(); // TODO : debug, remove later - } void computePosition() { diff --git a/core/src/bzh/fainsin/sagittarius/SagittariusGame.java b/core/src/bzh/fainsin/sagittarius/SagittariusGame.java index 79ecffc..45bc68e 100644 --- a/core/src/bzh/fainsin/sagittarius/SagittariusGame.java +++ b/core/src/bzh/fainsin/sagittarius/SagittariusGame.java @@ -39,7 +39,6 @@ public class SagittariusGame extends Game { playerList.add( new Player(planetList.get(0)) ); arrowList = new ArrayList(); - } static void update(float deltaTime) {