From ccbdd559e11caa068e0134001aa0a72e49835619 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laure=CE=B7t?= Date: Fri, 9 Apr 2021 14:55:36 +0200 Subject: [PATCH] fix: Player debug drawing --- core/src/sagittarius/model/Planet.java | 5 ++-- core/src/sagittarius/model/Player.java | 36 +++++++++++++++++++++----- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/core/src/sagittarius/model/Planet.java b/core/src/sagittarius/model/Planet.java index 9682143..4f379d0 100644 --- a/core/src/sagittarius/model/Planet.java +++ b/core/src/sagittarius/model/Planet.java @@ -30,8 +30,9 @@ public class Planet extends Actor { @Override public void draw(Batch batch, float parentAlpha) { super.draw(batch, parentAlpha); - fontDebug.draw(batch, "mass = " + mass, this.getX(), this.getY() + 15); - fontDebug.draw(batch, "x = " + (int) this.getX() + ", y = " + (int) this.getY(), this.getX(), this.getY()); + fontDebug.draw(batch, "radius=" + (int)radius, getX(), getY() + fontDebug.getCapHeight()*2); + fontDebug.draw(batch, "mass=" + (int)mass, getX(), getY() + fontDebug.getCapHeight()); + fontDebug.draw(batch, "pos=" + (int)getX() + "," + (int)getY(), getX(), getY()); } @Override diff --git a/core/src/sagittarius/model/Player.java b/core/src/sagittarius/model/Player.java index 6eb5a68..0c34227 100644 --- a/core/src/sagittarius/model/Player.java +++ b/core/src/sagittarius/model/Player.java @@ -1,9 +1,12 @@ package sagittarius.model; +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.Input.Keys; import com.badlogic.gdx.graphics.Color; 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.graphics.glutils.ShapeRenderer.ShapeType; import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.scenes.scene2d.Actor; @@ -12,17 +15,17 @@ public class Player extends Actor { // ---------- ATTRIBUTEs ---------- private Planet home; - private Bow bow; + // private Bow bow; private BitmapFont fontDebug = new BitmapFont(); // ---------- CONSTRUCTORs ---------- public Player(Planet home, Color color) { super(); - this.setSize(50, 100); + this.setSize(100, 50); this.setRotation(MathUtils.random(360)); this.setColor(color); - this.setOrigin(25, 50); + this.setOrigin(0, getHeight()/2); this.home = home; //this.bow = new Bow(this, true); } @@ -32,7 +35,7 @@ public class Player extends Actor { @Override public void draw(Batch batch, float parentAlpha) { super.draw(batch, parentAlpha); - fontDebug.draw(batch, "x = " + (int) this.getX() + ", y = " + (int) this.getY(), this.getX(), this.getY()); + fontDebug.draw(batch, "pos=" + (int)getX() + "," + (int)getY() , getX(), getY()); } @Override @@ -40,14 +43,33 @@ public class Player extends Actor { super.drawDebug(shapes); } + @Override + protected void drawDebugBounds(ShapeRenderer shapes) { + if (!getDebug()) return; + shapes.set(ShapeType.Line); + if (getStage() != null) shapes.setColor(getStage().getDebugColor()); + + shapes.rect(getX(), getY() - getOriginY(), + getOriginX(), getOriginY(), + getWidth(), getHeight(), + getScaleX(), getScaleY(), + getRotation()); + shapes.line(home.getX(), home.getY(), getX(), getY()); + } + @Override public void act(float dt) { super.act(dt); - this.setX(home.getX() + this.home.getRadius()*MathUtils.cosDeg(this.getRotation())); - this.setY(home.getY() + this.home.getRadius()*MathUtils.cosDeg(this.getRotation())); + if (Gdx.input.isKeyPressed(Keys.LEFT)) { + rotateBy( 100.0f / home.getRadius()); + } + if (Gdx.input.isKeyPressed(Keys.RIGHT)) { + rotateBy(- 100.0f / home.getRadius()); + } - //this.bow.act(dt); + setX(home.getX() + home.getRadius()*MathUtils.cosDeg(getRotation())); + setY(home.getY() + home.getRadius()*MathUtils.sinDeg(getRotation())); } /**