fix: separated angle and rotation in Player
This commit is contained in:
parent
b279519b55
commit
ec764c56fb
|
@ -2,6 +2,8 @@ package sagittarius.model;
|
|||
|
||||
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.scenes.scene2d.Actor;
|
||||
|
||||
public abstract class BaseActor extends Actor {
|
||||
|
@ -10,7 +12,7 @@ public abstract class BaseActor extends Actor {
|
|||
|
||||
protected abstract String getInfo();
|
||||
|
||||
protected float angle;
|
||||
protected float angle; // encapsulate ?
|
||||
|
||||
@Override
|
||||
public void draw(Batch batch, float parentAlpha) {
|
||||
|
@ -18,4 +20,16 @@ public abstract class BaseActor extends Actor {
|
|||
fontDebug.draw(batch, getInfo(), getX(), getY());
|
||||
}
|
||||
|
||||
@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());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import com.badlogic.gdx.Gdx;
|
|||
import com.badlogic.gdx.Input.Keys;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
|
||||
import com.badlogic.gdx.math.MathUtils;
|
||||
|
||||
public class Player extends BaseActor {
|
||||
|
@ -18,10 +17,14 @@ public class Player extends BaseActor {
|
|||
|
||||
public Player(Planet home, Color color) {
|
||||
super();
|
||||
this.setSize(100, 50); // TODO: fix this ? (width & height inverted) => use BaseActor.angle
|
||||
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);
|
||||
}
|
||||
|
@ -31,21 +34,8 @@ public class Player extends BaseActor {
|
|||
@Override
|
||||
public void drawDebug(ShapeRenderer 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());
|
||||
bow.drawDebug(shapes);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -53,14 +43,16 @@ public class Player extends BaseActor {
|
|||
super.act(dt);
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue