fix: reapplied changes

This commit is contained in:
Laureηt 2021-04-13 21:08:25 +02:00
parent 1cd41cc5e3
commit 696735af14
5 changed files with 46 additions and 81 deletions

View file

@ -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()
;
}
}

View file

@ -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";
}
}

View file

@ -4,7 +4,6 @@ import sagittarius.view.GameScreen;
public class MouseInfo extends BaseActor {
// ---------- METHODs ----------
@Override

View file

@ -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()
;
}
}

View file

@ -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
}