From 696735af148035769f99191f79b99dcf6dd3397d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laure=CE=B7t?= Date: Tue, 13 Apr 2021 21:08:25 +0200 Subject: [PATCH] fix: reapplied changes --- core/src/sagittarius/model/Arrow.java | 44 +++++------------ core/src/sagittarius/model/FPS.java | 19 ++++---- core/src/sagittarius/model/MouseInfo.java | 1 - core/src/sagittarius/model/Player.java | 59 +++++++++-------------- core/src/sagittarius/view/GameScreen.java | 4 +- 5 files changed, 46 insertions(+), 81 deletions(-) diff --git a/core/src/sagittarius/model/Arrow.java b/core/src/sagittarius/model/Arrow.java index 2d70a37..20b17d5 100644 --- a/core/src/sagittarius/model/Arrow.java +++ b/core/src/sagittarius/model/Arrow.java @@ -2,18 +2,14 @@ package sagittarius.model; import java.util.ArrayList; -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.math.Vector2; import com.badlogic.gdx.scenes.scene2d.Actor; import sagittarius.SagittariusGame; import sagittarius.view.GameScreen; -public class Arrow extends Actor { +public class Arrow extends BaseActor { private static final float initTTL = 20; @@ -26,8 +22,6 @@ public class Arrow extends Actor { private float TTL = initTTL; private boolean landed; - private BitmapFont fontDebug = new BitmapFont(); - // ---------- CONSTRUCTORs ---------- /** @@ -65,17 +59,6 @@ public class Arrow extends Actor { } - @Override - public void draw(Batch batch, float parentAlpha) { - super.draw(batch, parentAlpha); - fontDebug.draw(batch, "TTL=" + (int)TTL, getX(), getY() + fontDebug.getCapHeight()*5); - fontDebug.draw(batch, "pos=" + (int)getX() + "," + (int)getY(), getX(), getY() + fontDebug.getCapHeight()*4); - fontDebug.draw(batch, "speed=" + (int)velocity.x + "," + (int)velocity.y, getX(), getY() + fontDebug.getCapHeight()*3); - fontDebug.draw(batch, "accel=" + (int)acceleration.x + "," + (int)acceleration.y, getX(), getY() + fontDebug.getCapHeight()*2); - fontDebug.draw(batch, "force=" + (int)force.x + "," + (int)force.y, getX(), getY() + fontDebug.getCapHeight()*1); - fontDebug.draw(batch, "angle=" + (int)getRotation(), getX(), getY()); - } - @Override public void drawDebug(ShapeRenderer shapes) { super.drawDebug(shapes); @@ -84,19 +67,6 @@ public class Arrow extends Actor { } } - @Override - protected void drawDebugBounds(ShapeRenderer shapes) { - if (!getDebug()) return; - shapes.set(ShapeType.Line); - if (getStage() != null) shapes.setColor(getStage().getDebugColor()); - - shapes.rect(getX() - getOriginX(), getY() - getOriginY(), - getOriginX(), getOriginY(), - getWidth(), getHeight(), - getScaleX(), getScaleY(), - getRotation()); - } - /** * Computes the {@link Arrow#force} exerted on the Arrow, * according to the other weighted entities. @@ -202,4 +172,16 @@ public class Arrow extends Actor { return new Vector2( getX(), getY() ); } + @Override + protected String getInfo() { + return + "TTL=" + (int)TTL + "\n" + + "pos=" + (int)getX() + "," + (int)getY() + "\n" + + "speed=" + (int)velocity.x + "," + (int)velocity.y + "\n" + + "accel=" + (int)acceleration.x + "," + (int)acceleration.y +"\n" + + "force=" + (int)force.x + "," + (int)force.y + "\n" + + "angle=" + (int)getRotation() + ; + } + } diff --git a/core/src/sagittarius/model/FPS.java b/core/src/sagittarius/model/FPS.java index f25b924..f98ec9c 100644 --- a/core/src/sagittarius/model/FPS.java +++ b/core/src/sagittarius/model/FPS.java @@ -1,21 +1,21 @@ package sagittarius.model; import com.badlogic.gdx.Gdx; -import com.badlogic.gdx.graphics.g2d.Batch; -import com.badlogic.gdx.graphics.g2d.BitmapFont; -import com.badlogic.gdx.scenes.scene2d.Actor; +import com.badlogic.gdx.scenes.scene2d.Stage; -import sagittarius.SagittariusGame; - -public class FPS extends Actor { +public class FPS extends BaseActor { // ---------- ATTRIBUTEs ---------- - private BitmapFont font = new BitmapFont(); private int frameRate; // ---------- METHODs ---------- + public FPS(Stage stage) { + super(); + setPosition(3, stage.getViewport().getWorldHeight() - 3); + } + @Override public void act(float delta) { super.act(delta); @@ -23,9 +23,8 @@ public class FPS extends Actor { } @Override - public void draw(Batch batch, float parentAlpha) { - super.draw(batch, parentAlpha); - font.draw(batch, frameRate + " fps", 3, SagittariusGame.getActiveScreen().getUIStage().getViewport().getWorldHeight() - 3); + protected String getInfo() { + return frameRate + " fps"; } } diff --git a/core/src/sagittarius/model/MouseInfo.java b/core/src/sagittarius/model/MouseInfo.java index a5f77b9..92659b4 100644 --- a/core/src/sagittarius/model/MouseInfo.java +++ b/core/src/sagittarius/model/MouseInfo.java @@ -4,7 +4,6 @@ import sagittarius.view.GameScreen; public class MouseInfo extends BaseActor { - // ---------- METHODs ---------- @Override diff --git a/core/src/sagittarius/model/Player.java b/core/src/sagittarius/model/Player.java index c369167..4a57740 100644 --- a/core/src/sagittarius/model/Player.java +++ b/core/src/sagittarius/model/Player.java @@ -3,77 +3,59 @@ 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; -public class Player extends Actor { +public class Player extends BaseActor { // ---------- ATTRIBUTEs ---------- private Planet home; private Bow bow; private boolean playing; - private BitmapFont fontDebug = new BitmapFont(); // ---------- CONSTRUCTORs ---------- public Player(Planet home, Color color) { super(); - this.setSize(100, 50); // TODO: fix this ? (width & height inverted) - this.setRotation(MathUtils.random(360)); + + this.setSize(50, 100); + this.setOrigin(getWidth()/2, getHeight()/2); this.setColor(color); - this.setOrigin(0, getHeight()/2); + + this.angle = MathUtils.random(360); + this.setRotation(angle-90); + this.home = home; this.bow = new Bow(this, true); } // ---------- METHODs ---------- - @Override - public void draw(Batch batch, float parentAlpha) { - super.draw(batch, parentAlpha); - fontDebug.draw(batch, "pos=" + (int)getX() + "," + (int)getY() , getX(), getY()); - } - @Override public void drawDebug(ShapeRenderer shapes) { super.drawDebug(shapes); + shapes.line(home.getX(), home.getY(), getX(), getY()); bow.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); if (playing) { if (Gdx.input.isKeyPressed(Keys.LEFT)) { - rotateBy( 100.0f / home.getRadius()); + this.angle += 100.0f / home.getRadius(); } if (Gdx.input.isKeyPressed(Keys.RIGHT)) { - rotateBy(- 100.0f / home.getRadius()); + this.angle -= 100.0f / home.getRadius(); } } - setX(home.getX() + home.getRadius()*MathUtils.cosDeg(getRotation())); - setY(home.getY() + home.getRadius()*MathUtils.sinDeg(getRotation())); + setX(home.getX() + (home.getRadius() + getHeight()/2)*MathUtils.cosDeg(angle)); + setY(home.getY() + (home.getRadius() + getHeight()/2)*MathUtils.sinDeg(angle)); + + this.setRotation(angle-90); bow.act(dt); } @@ -85,7 +67,6 @@ public class Player extends Actor { return this.home; } - /** * @return the player's bow. */ @@ -93,7 +74,6 @@ public class Player extends Actor { return bow; } - /** * Indiquer que c'est son tour de jouer. */ @@ -102,7 +82,6 @@ public class Player extends Actor { playing = true; } - /** * Indique la fin de son tour de jeu. */ @@ -111,7 +90,6 @@ public class Player extends Actor { playing = false; } - /** * Savoir si il est entrain de jouer. */ @@ -119,4 +97,11 @@ public class Player extends Actor { return playing; } + @Override + protected String getInfo() { + return + "pos=" + (int)getX() + "," + (int)getY() + ; + } + } diff --git a/core/src/sagittarius/view/GameScreen.java b/core/src/sagittarius/view/GameScreen.java index b36d7ca..9d776e6 100644 --- a/core/src/sagittarius/view/GameScreen.java +++ b/core/src/sagittarius/view/GameScreen.java @@ -4,7 +4,6 @@ import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector3; -import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.scenes.scene2d.Group; import sagittarius.model.*; @@ -62,13 +61,14 @@ public class GameScreen extends BaseScreen { mainStage.addActor(arrows); // others - FPS fpsCounter = new FPS(); + FPS fpsCounter = new FPS(uiStage); uiStage.addActor(fpsCounter); MouseInfo mouseInfo = new MouseInfo(); uiStage.addActor(mouseInfo); mainStage.setDebugAll(true); // TODO: disable later + uiStage.setDebugAll(true); // TODO: disable later }