fix: arrow position

This commit is contained in:
Laureηt 2021-04-10 12:22:48 +02:00
parent bbf9a24092
commit f9c1f258bc
6 changed files with 84 additions and 23 deletions

View file

@ -25,15 +25,14 @@ To export the game to a .jar file:
The resulting .jar files should be in `*/build/libs/`
## TODO LIST
1. player turn
2. kill player
3. move freely camera
4. lerp camera arrow
5. event based shit
6. menus test
7. améliorer trajectoires arrows en simulant tout n'univers
8. rotating planets and moons (on themselves)
9. faire des sous-packages, sgittarius.modele, sagittarius.view, saggitarius.control ...
* create BaseActor to concatenate code
* player turn
* kill player
* move freely camera
* lerp camera arrow
* menus test
* améliorer trajectoires arrows en simulant tout n'univers
* rotating planets and moons (on themselves)
## Contributing
Please use [conventionnal commits](https://www.conventionalcommits.org/).

View file

@ -5,6 +5,7 @@ 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;
@ -39,9 +40,9 @@ public class Arrow extends Actor {
shooter.getY() + shooter.getWidth() * MathUtils.sinDeg(shooter.getRotation()));
this.velocity = new Vector2(power, 0).setAngleDeg(angle);
this.acceleration = new Vector2();
this.setOrigin(80, 0);
this.setSize(100, 4);
this.force = computeForce();
this.setSize(100, 0);
this.setOrigin(50, 0);
}
// ---------- METHODs ----------
@ -70,6 +71,27 @@ public class Arrow extends Actor {
fontDebug.draw(batch, "angle=" + getRotation(), getX(), getY());
}
@Override
public void drawDebug(ShapeRenderer shapes) {
super.drawDebug(shapes);
for (Actor actor : GameScreen.planets.getChildren()) {
shapes.line(getX(), getY(), actor.getX(), actor.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(),
getOriginX(), getOriginY(),
getWidth(), getHeight(),
getScaleX(), getScaleY(),
getRotation());
}
/**
* Computes the {@link Arrow#force} exerted on the Arrow,
* according to the other weighted entities.
@ -78,7 +100,7 @@ public class Arrow extends Actor {
private Vector2 computeForce() {
Vector2 force = new Vector2();
for (Actor actor : GameScreen.planets.getChildren()) {
float dx = actor.getX() - this.getX();
float dy = actor.getY() - this.getY();

View file

@ -1,23 +1,30 @@
package sagittarius.model;
import javax.print.attribute.standard.PrinterLocation;
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.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.Actor;
public class Moon extends Planet {
public class Moon extends Actor {
private BitmapFont fontDebug = new BitmapFont();
private float mass;
private Planet sun;
private float altitude;
private float radius;
// ---------- CONSTRUCTORs ----------
public Moon(Planet sun, float mass, float radius, float altitude, Color color) {
super(new Vector2(), mass, radius, color);
super();
this.sun = sun;
this.mass = mass;
this.setColor(color);
this.altitude = altitude;
this.radius = radius;
}
// ---------- METHODs ----------
@ -29,6 +36,21 @@ public class Moon extends Planet {
this.setY(sun.getY() + this.altitude*MathUtils.sinDeg(this.getRotation()));
}
@Override
public void draw(Batch batch, float parentAlpha) {
super.draw(batch, parentAlpha);
fontDebug.draw(batch, "radius=" + (int)radius, getX(), getY() + fontDebug.getCapHeight()*2);
fontDebug.draw(batch, "mass=" + (int)mass, getX(), getY() + fontDebug.getCapHeight());
fontDebug.draw(batch, "pos=" + (int)getX() + "," + (int)getY(), getX(), getY());
}
@Override
public void drawDebug(ShapeRenderer shapes) {
super.drawDebug(shapes);
shapes.setColor(this.getColor());
shapes.circle(this.getX(), this.getY(), this.radius);
}
/**
* @return the Planet which the Moon orbits.
*/
@ -36,4 +58,12 @@ public class Moon extends Planet {
return this.sun;
}
public float getMass() {
return mass;
}
public Vector2 getPosition() {
return new Vector2( getX(), getY() );
}
}

View file

@ -5,15 +5,17 @@ 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.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.Group;
public class Planet extends Group {
public class Planet extends Actor {
// ---------- ATTRIBUTEs ----------
private BitmapFont fontDebug = new BitmapFont();
private float radius;
private float mass;
private Group moons;
// ---------- CONSTRUCTORs ----------
@ -23,17 +25,25 @@ public class Planet extends Group {
this.radius = radius;
this.mass = mass;
this.setColor(color);
moons = new Group();
}
// ---------- METHODs ----------
@Override
public void act(float dt) {
super.act(dt);
moons.setDebug(getDebug(), true);
moons.act(dt);
}
@Override
public void draw(Batch batch, float parentAlpha) {
super.draw(batch, parentAlpha);
fontDebug.draw(batch, "radius=" + (int)radius, getX(), getY() + fontDebug.getCapHeight()*2);
fontDebug.draw(batch, "mass=" + (int)mass, getX(), getY() + fontDebug.getCapHeight());
fontDebug.draw(batch, "pos=" + (int)getX() + "," + (int)getY(), getX(), getY());
drawChildren(batch, parentAlpha);
moons.draw(batch, parentAlpha);
}
@Override
@ -41,7 +51,7 @@ public class Planet extends Group {
super.drawDebug(shapes);
shapes.setColor(this.getColor());
shapes.circle(this.getX(), this.getY(), this.radius);
drawDebugChildren(shapes);
moons.drawDebug(shapes);
}
/**
@ -52,7 +62,7 @@ public class Planet extends Group {
}
public void addMoon(Moon moon) {
this.addActor(moon);
moons.addActor(moon);
}
public float getMass() {

View file

@ -41,6 +41,7 @@ public class Player extends Actor {
@Override
public void drawDebug(ShapeRenderer shapes) {
super.drawDebug(shapes);
bow.drawDebug(shapes);
}
@Override
@ -55,7 +56,6 @@ public class Player extends Actor {
getScaleX(), getScaleY(),
getRotation());
shapes.line(home.getX(), home.getY(), getX(), getY());
bow.drawDebug(shapes);
}
@Override

View file

@ -26,8 +26,6 @@ public class GameScreen extends BaseScreen {
@Override
public void initialize() {
mainStage.setDebugAll(true); // TODO: disable later
// planets
planets = new Group();
@ -55,6 +53,8 @@ public class GameScreen extends BaseScreen {
MouseInfo mouseInfo = new MouseInfo();
uiStage.addActor(mouseInfo);
mainStage.setDebugAll(true); // TODO: disable later
}
@Override