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

@ -14,8 +14,8 @@ class Arrow extends Entity {
private Vector2 velocity = new Vector2(); private Vector2 velocity = new Vector2();
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);
@ -32,7 +39,11 @@ 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

@ -17,7 +17,7 @@ class Bow {
private Vector2 anchor; private Vector2 anchor;
private Vector2 aim; private Vector2 aim;
private float power; private float power;
// ---------- CONSTRUCTORs ---------- // ---------- CONSTRUCTORs ----------

View file

@ -4,11 +4,11 @@ import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector2;
abstract class Entity { abstract class Entity {
// ---------- ATTRIBUTs ---------- // ---------- ATTRIBUTs ----------
protected Vector2 position; protected Vector2 position;
protected float mass = 1.0f; protected float mass = 1.0f;
protected float angle; protected float angle;
protected Color color = Color.WHITE; protected Color color = Color.WHITE;

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 ?
@ -66,7 +66,7 @@ class GameScreen extends ScreenAdapter {
for (Moon moon : SagittariusGame.moonList) { for (Moon moon : SagittariusGame.moonList) {
moon.renderDebug(batch, font); moon.renderDebug(batch, font);
} }
// players // players
for (Player player : SagittariusGame.playerList) { for (Player player : SagittariusGame.playerList) {
player.renderDebug(batch, font); player.renderDebug(batch, font);
@ -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;
@ -23,14 +24,14 @@ class HUD implements Disposable {
void render() { void render() {
batch.begin(); batch.begin();
// framerate // framerate
font.draw(batch, frameRate + " fps", 3, Gdx.graphics.getHeight() - 3); font.draw(batch, frameRate + " fps", 3, Gdx.graphics.getHeight() - 3);
// cursor positions, oui c'est dégueu // cursor positions, oui c'est dégueu
font.draw(batch, "x_r = " + (int) SagittariusGame.screenCursor.x + ", y_r = " + (int) SagittariusGame.screenCursor.y, SagittariusGame.screenCursor.x + 5, Gdx.graphics.getHeight() - SagittariusGame.screenCursor.y + 5); font.draw(batch, "x_r = " + (int) SagittariusGame.screenCursor.x + ", y_r = " + (int) SagittariusGame.screenCursor.y, SagittariusGame.screenCursor.x + 5, Gdx.graphics.getHeight() - SagittariusGame.screenCursor.y + 5);
font.draw(batch, "x_g = " + (int) SagittariusGame.worldCursor.x + ", y_g = " + (int) SagittariusGame.worldCursor.y, SagittariusGame.screenCursor.x + 5, Gdx.graphics.getHeight() - SagittariusGame.screenCursor.y + 20); font.draw(batch, "x_g = " + (int) SagittariusGame.worldCursor.x + ", y_g = " + (int) SagittariusGame.worldCursor.y, SagittariusGame.screenCursor.x + 5, Gdx.graphics.getHeight() - SagittariusGame.screenCursor.y + 20);
batch.end(); batch.end();
} }
@ -40,4 +41,8 @@ class HUD implements Disposable {
font.dispose(); font.dispose();
} }
public void resize() {
// TODO
}
} }

View file

@ -9,7 +9,7 @@ import com.badlogic.gdx.math.Vector2;
class Planet extends Entity { class Planet extends Entity {
// ---------- ATTRIBUTEs ---------- // ---------- ATTRIBUTEs ----------
private float radius = 10; private float radius = 10;
// ---------- CONSTRUCTORs ---------- // ---------- CONSTRUCTORs ----------
@ -21,7 +21,7 @@ class Planet extends Entity {
Planet(Vector2 position, float mass, float radius, Color color) { Planet(Vector2 position, float mass, float radius, Color color) {
this(position, mass, radius); this(position, mass, radius);
this.color = color; this.color = color;
} }
// ---------- METHODs ---------- // ---------- METHODs ----------
@ -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

@ -27,7 +27,7 @@ class Player extends Entity {
this.bow = new Bow(this, false); this.bow = new Bow(this, false);
this.angle = 45; // TODO : tmp this.angle = 45; // TODO : tmp
} }
// ---------- METHODs ---------- // ---------- METHODs ----------
void render(ShapeRenderer shapeRenderer) { void render(ShapeRenderer shapeRenderer) {

View file

@ -25,26 +25,32 @@ 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 ----------
@Override @Override
public void create() { public void create() {
setScreen(new GameScreen()); setScreen(new GameScreen());
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) );
playerList = new ArrayList<Player>(); playerList = new ArrayList<Player>();
playerList.add( new Player(planetList.get(0)) ); playerList.add( new Player(planetList.get(0)) );
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
@ -70,7 +76,7 @@ public class SagittariusGame extends Game {
it.remove(); it.remove();
} }
} }
} }
} }