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/` The resulting .jar files should be in `*/build/libs/`
## TODO LIST ## TODO LIST
1. player turn * create BaseActor to concatenate code
2. kill player * player turn
3. move freely camera * kill player
4. lerp camera arrow * move freely camera
5. event based shit * lerp camera arrow
6. menus test * menus test
7. améliorer trajectoires arrows en simulant tout n'univers * améliorer trajectoires arrows en simulant tout n'univers
8. rotating planets and moons (on themselves) * rotating planets and moons (on themselves)
9. faire des sous-packages, sgittarius.modele, sagittarius.view, saggitarius.control ...
## Contributing ## Contributing
Please use [conventionnal commits](https://www.conventionalcommits.org/). 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.Batch;
import com.badlogic.gdx.graphics.g2d.BitmapFont; 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.math.Vector2; import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.scenes.scene2d.Actor;
@ -39,9 +40,9 @@ public class Arrow extends Actor {
shooter.getY() + shooter.getWidth() * MathUtils.sinDeg(shooter.getRotation())); shooter.getY() + shooter.getWidth() * MathUtils.sinDeg(shooter.getRotation()));
this.velocity = new Vector2(power, 0).setAngleDeg(angle); this.velocity = new Vector2(power, 0).setAngleDeg(angle);
this.acceleration = new Vector2(); this.acceleration = new Vector2();
this.setOrigin(80, 0);
this.setSize(100, 4);
this.force = computeForce(); this.force = computeForce();
this.setSize(100, 0);
this.setOrigin(50, 0);
} }
// ---------- METHODs ---------- // ---------- METHODs ----------
@ -70,6 +71,27 @@ public class Arrow extends Actor {
fontDebug.draw(batch, "angle=" + getRotation(), getX(), getY()); 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, * Computes the {@link Arrow#force} exerted on the Arrow,
* according to the other weighted entities. * according to the other weighted entities.
@ -78,7 +100,7 @@ public class Arrow extends Actor {
private Vector2 computeForce() { private Vector2 computeForce() {
Vector2 force = new Vector2(); Vector2 force = new Vector2();
for (Actor actor : GameScreen.planets.getChildren()) { for (Actor actor : GameScreen.planets.getChildren()) {
float dx = actor.getX() - this.getX(); float dx = actor.getX() - this.getX();
float dy = actor.getY() - this.getY(); float dy = actor.getY() - this.getY();

View file

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

View file

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

View file

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