chore: added some javadoc

chore: trimmed some whitespaces
This commit is contained in:
Laureηt 2021-04-07 19:38:48 +02:00
parent 52b0b8f957
commit b7f6b5bd69
9 changed files with 83 additions and 22 deletions

12
README.md Normal file
View file

@ -0,0 +1,12 @@
# TODO-list
0. do a better README
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 ...

View file

@ -15,7 +15,7 @@ class Arrow extends Entity {
private Vector2 acceleration = new Vector2(); private Vector2 acceleration = new Vector2();
private Vector2 force = new Vector2(); private Vector2 force = new Vector2();
float TTL = 20; protected float TTL = 20;
private final float length = 100; private final float length = 100;
private boolean active = true; private boolean active = true;
@ -24,6 +24,13 @@ class Arrow extends Entity {
// ---------- CONSTRUCTORs ---------- // ---------- CONSTRUCTORs ----------
/**
* Constructs an Arrow using its initial conditions.
*
* @param angle initial angle of the Arrow (in degrees).
* @param power power given to the Arrow a Bow.
* @param shooter Bow's shooter.
*/
Arrow(float angle, float power, Player shooter) { Arrow(float angle, float power, Player shooter) {
super(shooter.position, 1); super(shooter.position, 1);
this.velocity = new Vector2(power, 0).setAngleDeg(angle); this.velocity = new Vector2(power, 0).setAngleDeg(angle);
@ -33,6 +40,10 @@ class Arrow extends Entity {
// ---------- METHODs ---------- // ---------- METHODs ----------
/**
* Computes the {@link Arrow#force} exerted on the Arrow,
* according to the other weighted entities.
*/
private Vector2 computeForce() { private Vector2 computeForce() {
Vector2 force = new Vector2(); Vector2 force = new Vector2();
for (Planet attractor : SagittariusGame.planetList) { for (Planet attractor : SagittariusGame.planetList) {
@ -48,6 +59,9 @@ class Arrow extends Entity {
return force; return force;
} }
/**
* Verify whether or not the Arrow contacts an Entity.
*/
private void verifyActivity() { private void verifyActivity() {
for (Planet planet : SagittariusGame.planetList) { for (Planet planet : SagittariusGame.planetList) {
if (this.distanceTo(planet) < planet.getRadius()) { if (this.distanceTo(planet) < planet.getRadius()) {
@ -65,6 +79,12 @@ class Arrow extends Entity {
} }
} }
/**
* Updates the physical attributes of the Arrow,
* must be called in the main update loop.
*
* @param deltaTime time elapsed between 2 frames.
*/
void update(float deltaTime) { void update(float deltaTime) {
if (this.active) { if (this.active) {
@ -77,9 +97,15 @@ class Arrow extends Entity {
} }
} }
/**
* Computes the next position of the Arrow
* according to its physical attributes
* using the Verlet integration scheme.
*
* @param deltaTime time difference used in the integration.
* @see <a href="https://gamedev.stackexchange.com/a/41917">https://gamedev.stackexchange.com/a/41917</a>.
*/
private void integrationVerlet(float deltaTime) { private void integrationVerlet(float deltaTime) {
// Verlet integration
// https://gamedev.stackexchange.com/questions/15708/how-can-i-implement-gravity/41917#41917
this.acceleration = this.force.cpy(); this.acceleration = this.force.cpy();
@ -92,6 +118,8 @@ class Arrow extends Entity {
this.velocity.y += deltaTime * ( this.acceleration.y + this.force.y ) / 2; this.velocity.y += deltaTime * ( this.acceleration.y + this.force.y ) / 2;
} }
// ---------- GRAPHICAL METHODs ----------
void render(ShapeRenderer shapeRenderer) { void render(ShapeRenderer shapeRenderer) {
Vector2 tail = new Vector2(-this.length, 0).rotateDeg(this.angle).add(this.position); Vector2 tail = new Vector2(-this.length, 0).rotateDeg(this.angle).add(this.position);
shapeRenderer.line(this.position, tail); shapeRenderer.line(this.position, tail);
@ -99,7 +127,7 @@ class Arrow extends Entity {
void renderDebug(Batch batch, BitmapFont font) { void renderDebug(Batch batch, BitmapFont font) {
// TODO : dirty, do it in an other way // TODO : dirty, do it in an other way ?
if (active) { if (active) {
font.draw(batch, "TTL = " + this.TTL, this.position.x, this.position.y + font.getCapHeight()*5); font.draw(batch, "TTL = " + this.TTL, this.position.x, this.position.y + font.getCapHeight()*5);
font.draw(batch, "pos = " + this.position, this.position.x, this.position.y + font.getCapHeight()*4); font.draw(batch, "pos = " + this.position, this.position.x, this.position.y + font.getCapHeight()*4);
@ -112,6 +140,13 @@ class Arrow extends Entity {
// ---------- STATIC METHODs ---------- // ---------- STATIC METHODs ----------
/** // TODO : pass directly an Arrow instead of 3 arguments
* Computes the trajectory of an Arrow,
* given its initial conditions.
*
* @param iterations number of iterations for the integration.
* @param timeStep time period used for the integration.
*/
static float[] traj(float angle, float power, Player shooter, int iterations, float timeStep) { static float[] traj(float angle, float power, Player shooter, int iterations, float timeStep) {
ArrayList<Float> path = new ArrayList<Float>(); ArrayList<Float> path = new ArrayList<Float>();
Arrow dummyArrow = new Arrow(angle, power, shooter); Arrow dummyArrow = new Arrow(angle, power, shooter);
@ -124,6 +159,7 @@ class Arrow extends Entity {
} }
// TODO : optimize, lots of useless stuff + change name // TODO : optimize, lots of useless stuff + change name
// or ignore and use adapters
final float[] arr = new float[path.size()]; final float[] arr = new float[path.size()];
int index = 0; int index = 0;

View file

@ -26,7 +26,7 @@ class GameScreen extends ScreenAdapter {
private BitmapFont font; private BitmapFont font;
// camera stuff // camera stuff
private Viewport viewport; private Viewport viewport; // TODO : useless ?
protected static Camera camera; protected static Camera camera;
// TODO: categorize better ? // TODO: categorize better ?
@ -132,6 +132,7 @@ class GameScreen extends ScreenAdapter {
camera.update(); camera.update();
batch.setProjectionMatrix(camera.combined); batch.setProjectionMatrix(camera.combined);
shapeRenderer.setProjectionMatrix(camera.combined); shapeRenderer.setProjectionMatrix(camera.combined);
hud.resize();
} }
@Override @Override

View file

@ -1,5 +1,6 @@
package sagittarius; package sagittarius;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
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;
@ -40,4 +41,8 @@ class HUD implements Disposable {
font.dispose(); font.dispose();
} }
public void resize() {
// TODO
}
} }

View file

@ -32,6 +32,7 @@ class Planet extends Entity {
} }
void renderDebug(Batch batch, BitmapFont font) { void renderDebug(Batch batch, BitmapFont font) {
font.draw(batch, "mass = " + mass, position.x, position.y + 15);
font.draw(batch, "x = " + (int) position.x + ", y = " + (int) position.y, position.x, position.y); font.draw(batch, "x = " + (int) position.x + ", y = " + (int) position.y, position.x, position.y);
} }

View file

@ -25,6 +25,7 @@ public class SagittariusGame extends Game {
static ArrayList<Moon> moonList; static ArrayList<Moon> moonList;
static ArrayList<Player> playerList; static ArrayList<Player> playerList;
static ArrayList<Arrow> arrowList; static ArrayList<Arrow> arrowList;
// TODO : fix this shit, too many for loops
// ---------- METHODs ---------- // ---------- METHODs ----------
@ -34,7 +35,7 @@ public class SagittariusGame extends Game {
planetList = new ArrayList<Planet>(); planetList = new ArrayList<Planet>();
planetList.add( new Planet(new Vector2(400, 400), 1000, 50) ); planetList.add( new Planet(new Vector2(400, 400), 1000, 50) );
planetList.add( new Planet(new Vector2(1000, 400), 1000, 100, Color.CYAN) ); planetList.add( new Planet(new Vector2(1400, 700), 1000, 100, Color.CYAN) );
moonList = new ArrayList<Moon>(); moonList = new ArrayList<Moon>();
moonList.add( new Moon(planetList.get(1), 100, 20, 300) ); moonList.add( new Moon(planetList.get(1), 100, 20, 300) );
@ -45,6 +46,11 @@ public class SagittariusGame extends Game {
arrowList = new ArrayList<Arrow>(); arrowList = new ArrayList<Arrow>();
} }
/**
* Main update loop.
*
* @param deltaTime time elapsed between 2 frames.
*/
static void update(float deltaTime) { static void update(float deltaTime) {
// cursors // cursors