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 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;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.scenes.scene2d.Actor;
import sagittarius.SagittariusGame; import sagittarius.SagittariusGame;
import sagittarius.view.GameScreen; import sagittarius.view.GameScreen;
public class Arrow extends Actor { public class Arrow extends BaseActor {
private static final float initTTL = 20; private static final float initTTL = 20;
@ -26,8 +22,6 @@ public class Arrow extends Actor {
private float TTL = initTTL; private float TTL = initTTL;
private boolean landed; private boolean landed;
private BitmapFont fontDebug = new BitmapFont();
// ---------- CONSTRUCTORs ---------- // ---------- 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 @Override
public void drawDebug(ShapeRenderer shapes) { public void drawDebug(ShapeRenderer shapes) {
super.drawDebug(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, * Computes the {@link Arrow#force} exerted on the Arrow,
* according to the other weighted entities. * according to the other weighted entities.
@ -202,4 +172,16 @@ public class Arrow extends Actor {
return new Vector2( getX(), getY() ); 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; package sagittarius.model;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.scenes.scene2d.Actor;
import sagittarius.SagittariusGame; public class FPS extends BaseActor {
public class FPS extends Actor {
// ---------- ATTRIBUTEs ---------- // ---------- ATTRIBUTEs ----------
private BitmapFont font = new BitmapFont();
private int frameRate; private int frameRate;
// ---------- METHODs ---------- // ---------- METHODs ----------
public FPS(Stage stage) {
super();
setPosition(3, stage.getViewport().getWorldHeight() - 3);
}
@Override @Override
public void act(float delta) { public void act(float delta) {
super.act(delta); super.act(delta);
@ -23,9 +23,8 @@ public class FPS extends Actor {
} }
@Override @Override
public void draw(Batch batch, float parentAlpha) { protected String getInfo() {
super.draw(batch, parentAlpha); return frameRate + " fps";
font.draw(batch, frameRate + " fps", 3, SagittariusGame.getActiveScreen().getUIStage().getViewport().getWorldHeight() - 3);
} }
} }

View file

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

View file

@ -3,60 +3,40 @@ package sagittarius.model;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Keys; import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.graphics.Color; 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;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.scenes.scene2d.Actor;
public class Player extends Actor { public class Player extends BaseActor {
// ---------- ATTRIBUTEs ---------- // ---------- ATTRIBUTEs ----------
private Planet home; private Planet home;
private Bow bow; private Bow bow;
private boolean playing; private boolean playing;
private BitmapFont fontDebug = new BitmapFont();
// ---------- CONSTRUCTORs ---------- // ---------- CONSTRUCTORs ----------
public Player(Planet home, Color color) { public Player(Planet home, Color color) {
super(); 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.setColor(color);
this.setOrigin(0, getHeight()/2);
this.angle = MathUtils.random(360);
this.setRotation(angle-90);
this.home = home; this.home = home;
this.bow = new Bow(this, true); this.bow = new Bow(this, true);
} }
// ---------- METHODs ---------- // ---------- METHODs ----------
@Override
public void draw(Batch batch, float parentAlpha) {
super.draw(batch, parentAlpha);
fontDebug.draw(batch, "pos=" + (int)getX() + "," + (int)getY() , getX(), getY());
}
@Override @Override
public void drawDebug(ShapeRenderer shapes) { public void drawDebug(ShapeRenderer shapes) {
super.drawDebug(shapes); super.drawDebug(shapes);
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()); shapes.line(home.getX(), home.getY(), getX(), getY());
bow.drawDebug(shapes);
} }
@Override @Override
@ -65,15 +45,17 @@ public class Player extends Actor {
if (playing) { if (playing) {
if (Gdx.input.isKeyPressed(Keys.LEFT)) { if (Gdx.input.isKeyPressed(Keys.LEFT)) {
rotateBy( 100.0f / home.getRadius()); this.angle += 100.0f / home.getRadius();
} }
if (Gdx.input.isKeyPressed(Keys.RIGHT)) { 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())); setX(home.getX() + (home.getRadius() + getHeight()/2)*MathUtils.cosDeg(angle));
setY(home.getY() + home.getRadius()*MathUtils.sinDeg(getRotation())); setY(home.getY() + (home.getRadius() + getHeight()/2)*MathUtils.sinDeg(angle));
this.setRotation(angle-90);
bow.act(dt); bow.act(dt);
} }
@ -85,7 +67,6 @@ public class Player extends Actor {
return this.home; return this.home;
} }
/** /**
* @return the player's bow. * @return the player's bow.
*/ */
@ -93,7 +74,6 @@ public class Player extends Actor {
return bow; return bow;
} }
/** /**
* Indiquer que c'est son tour de jouer. * Indiquer que c'est son tour de jouer.
*/ */
@ -102,7 +82,6 @@ public class Player extends Actor {
playing = true; playing = true;
} }
/** /**
* Indique la fin de son tour de jeu. * Indique la fin de son tour de jeu.
*/ */
@ -111,7 +90,6 @@ public class Player extends Actor {
playing = false; playing = false;
} }
/** /**
* Savoir si il est entrain de jouer. * Savoir si il est entrain de jouer.
*/ */
@ -119,4 +97,11 @@ public class Player extends Actor {
return playing; 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.graphics.Color;
import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3; import com.badlogic.gdx.math.Vector3;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Group; import com.badlogic.gdx.scenes.scene2d.Group;
import sagittarius.model.*; import sagittarius.model.*;
@ -62,13 +61,14 @@ public class GameScreen extends BaseScreen {
mainStage.addActor(arrows); mainStage.addActor(arrows);
// others // others
FPS fpsCounter = new FPS(); FPS fpsCounter = new FPS(uiStage);
uiStage.addActor(fpsCounter); uiStage.addActor(fpsCounter);
MouseInfo mouseInfo = new MouseInfo(); MouseInfo mouseInfo = new MouseInfo();
uiStage.addActor(mouseInfo); uiStage.addActor(mouseInfo);
mainStage.setDebugAll(true); // TODO: disable later mainStage.setDebugAll(true); // TODO: disable later
uiStage.setDebugAll(true); // TODO: disable later
} }