fix: files re-structuring

This commit is contained in:
Laureηt 2021-04-09 17:00:16 +02:00
parent 59a3cfe85b
commit bbf9a24092
2 changed files with 43 additions and 45 deletions

View file

@ -46,6 +46,30 @@ public class Arrow extends Actor {
// ---------- METHODs ----------
@Override
public void act(float dt) {
integrationVerlet(dt);
this.TTL -= dt;
this.setRotation(this.velocity.angleDeg());
if (TTL <= 0) {
GameScreen.arrows.removeActor(this);
}
}
@Override
public void draw(Batch batch, float parentAlpha) {
super.draw(batch, parentAlpha);
fontDebug.draw(batch, "TTL=" + this.TTL, getX(), getY() + fontDebug.getCapHeight()*5);
fontDebug.draw(batch, "pos=" + getX() + "," + getY(), getX(), getY() + fontDebug.getCapHeight()*4);
fontDebug.draw(batch, "speed=" + this.velocity, getX(), getY() + fontDebug.getCapHeight()*3);
fontDebug.draw(batch, "accel=" + this.acceleration, getX(), getY() + fontDebug.getCapHeight()*2);
fontDebug.draw(batch, "force=" + this.force, getX(), getY() + fontDebug.getCapHeight()*1);
fontDebug.draw(batch, "angle=" + getRotation(), getX(), getY());
}
/**
* Computes the {@link Arrow#force} exerted on the Arrow,
* according to the other weighted entities.
@ -70,19 +94,6 @@ public class Arrow extends Actor {
return force;
}
@Override
public void act(float dt) {
integrationVerlet(dt);
this.TTL -= dt;
this.setRotation(this.velocity.angleDeg());
if (TTL <= 0) {
GameScreen.arrows.removeActor(this);
}
}
/**
* Computes the next position of the Arrow
* according to its physical attributes
@ -104,19 +115,6 @@ public class Arrow extends Actor {
this.velocity.y += dt * ( this.acceleration.y + this.force.y ) / 2;
}
@Override
public void draw(Batch batch, float parentAlpha) {
super.draw(batch, parentAlpha);
fontDebug.draw(batch, "TTL=" + this.TTL, getX(), getY() + fontDebug.getCapHeight()*5);
fontDebug.draw(batch, "pos=" + getX() + "," + getY(), getX(), getY() + fontDebug.getCapHeight()*4);
fontDebug.draw(batch, "speed=" + this.velocity, getX(), getY() + fontDebug.getCapHeight()*3);
fontDebug.draw(batch, "accel=" + this.acceleration, getX(), getY() + fontDebug.getCapHeight()*2);
fontDebug.draw(batch, "force=" + this.force, getX(), getY() + fontDebug.getCapHeight()*1);
fontDebug.draw(batch, "angle=" + getRotation(), getX(), getY());
}
// ---------- STATIC METHODs ----------
/** // TODO : pass directly an Arrow instead of 3 arguments
* Computes the trajectory of an Arrow,
* given its initial conditions.

View file

@ -50,25 +50,6 @@ class Bow extends Actor {
}
/**
* Generates an Arrow according to the Bow's attributes.
*
* @return an Arrow.
*/
private Arrow getArrow() {
return new Arrow(angle, power, shooter);
}
/**
* Converts the Bow's attributes to apply it
* to the Arrow's constructor.
*/
private void computeArrow() {
aim = this.anchor.cpy().sub(GameScreen.worldCursor);
angle = aim.angleDeg();
power = MathUtils.clamp(aim.len(), 0, 1000);
}
@Override
public void drawDebug(ShapeRenderer shapes) {
super.drawDebug(shapes);
@ -83,4 +64,23 @@ class Bow extends Actor {
}
}
/**
* Converts the Bow's attributes to apply it
* to the Arrow's constructor.
*/
private void computeArrow() {
aim = this.anchor.cpy().sub(GameScreen.worldCursor);
angle = aim.angleDeg();
power = MathUtils.clamp(aim.len(), 0, 1000);
}
/**
* Generates an Arrow according to the Bow's attributes.
*
* @return an Arrow.
*/
private Arrow getArrow() {
return new Arrow(angle, power, shooter);
}
}