chore: formatting

This commit is contained in:
Laureηt 2021-05-27 11:04:00 +02:00
parent 3c351ac996
commit b76cb1d159
19 changed files with 447 additions and 382 deletions

15
.editorconfig Normal file
View file

@ -0,0 +1,15 @@
# EditorConfig is awesome: https://EditorConfig.org
# top-most EditorConfig file
root = true
# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
# 4 space indentation
[*.java]
indent_style = space
indent_size = 4

View file

@ -19,7 +19,7 @@ import sagittarius.view.GameScreen;
public class Arrow extends EntityQuad {
// ---------- ATTRIBUTEs ----------
// ---------- ATTRIBUTEs ----------
private Vector2 velocity;
private Vector2 acceleration;
@ -35,7 +35,7 @@ public class Arrow extends EntityQuad {
private Sound arrowHitSound;
private ArrayList<Texture> texture;
// ---------- CONSTRUCTORs ----------
// ---------- CONSTRUCTORs ----------
/**
* Constructs an Arrow using its initial conditions.
@ -55,8 +55,10 @@ public class Arrow extends EntityQuad {
if (!preview) {
arrowLandedSound = Gdx.audio.newSound(Gdx.files.internal("sounds/effects/arrow_landed.mp3"));
arrowHitSound = Gdx.audio.newSound(Gdx.files.internal("sounds/effects/player_death.wav"));
arrowLandedSound =
Gdx.audio.newSound(Gdx.files.internal("sounds/effects/arrow_landed.mp3"));
arrowHitSound =
Gdx.audio.newSound(Gdx.files.internal("sounds/effects/player_death.wav"));
texture = new ArrayList<>();
String path = "arrow" + MathUtils.random(2);
@ -91,7 +93,7 @@ public class Arrow extends EntityQuad {
}
// ---------- METHODs ----------
// ---------- METHODs ----------
@Override
public void act(float dt) {
@ -119,7 +121,8 @@ public class Arrow extends EntityQuad {
public void drawDebug(ShapeRenderer shapes) {
super.drawDebug(shapes);
if (!landed) {
if (getStage() != null) shapes.setColor(getStage().getDebugColor());
if (getStage() != null)
shapes.setColor(getStage().getDebugColor());
for (Actor actor : GameScreen.attractors.getChildren()) {
shapes.line(getX(), getY(), actor.getX(), actor.getY());
}
@ -129,14 +132,16 @@ public class Arrow extends EntityQuad {
@Override
public void draw(Batch batch, float parentAlpha) {
int i = (int) (TTL * 3) % texture.size();
batch.draw(texture.get(i), getPosition().x - getOriginX(), getPosition().y - getWidth()/2, getOriginX(), getWidth()/2, getWidth(), getWidth(),
1, 1, getRotation(), 0, 0, texture.get(i).getWidth(), texture.get(i).getHeight(), false, false);
batch.draw(texture.get(i), getPosition().x - getOriginX(), getPosition().y - getWidth() / 2,
getOriginX(), getWidth() / 2, getWidth(), getWidth(), 1, 1, getRotation(), 0, 0,
texture.get(i).getWidth(), texture.get(i).getHeight(), false, false);
super.draw(batch, parentAlpha);
}
/**
* Computes the {@link Arrow#force} exerted on the Arrow,
* according to the other weighted entities.
* Computes the {@link Arrow#force} exerted on the Arrow, according to the other weighted
* entities.
*
* @return the complete force exerted on the Arrow.
*/
private Vector2 computeForce() {
@ -144,31 +149,31 @@ public class Arrow extends EntityQuad {
for (Actor actor : GameScreen.attractors.getChildren()) {
Planet attractor = (Planet) actor;
Vector2 diff = attractor.getPosition().cpy().sub(this.getPosition());
Vector2 attraction = diff.scl( SagittariusGame.G * attractor.mass / diff.len2() );
Vector2 attraction = diff.scl(SagittariusGame.G * attractor.mass / diff.len2());
force.add(attraction);
}
return force;
}
/**
* Computes the next position of the Arrow
* according to its physical attributes
* using the Verlet integration scheme.
* Computes the next position of the Arrow according to its physical attributes using the Verlet
* integration scheme.
*
* @param dt time difference used in the integration.
* @see <a href="https://gamedev.stackexchange.com/a/41917">https://gamedev.stackexchange.com/a/41917</a>.
* @see <a href=
* "https://gamedev.stackexchange.com/a/41917">https://gamedev.stackexchange.com/a/41917</a>.
*/
private void integrationVerlet(float dt) {
this.acceleration = this.force.cpy();
this.moveBy(dt * ( this.velocity.x + dt * this.acceleration.x / 2 ),
dt * ( this.velocity.y + dt * this.acceleration.y / 2 ));
this.moveBy(dt * (this.velocity.x + dt * this.acceleration.x / 2),
dt * (this.velocity.y + dt * this.acceleration.y / 2));
this.force = computeForce();
this.velocity.x += dt * ( this.acceleration.x + this.force.x ) / 2;
this.velocity.y += dt * ( this.acceleration.y + this.force.y ) / 2;
this.velocity.x += dt * (this.acceleration.x + this.force.x) / 2;
this.velocity.y += dt * (this.acceleration.y + this.force.y) / 2;
}
/**
@ -181,13 +186,13 @@ public class Arrow extends EntityQuad {
landed = true;
// Make a sound when an arrow lands
if ( ! SagittariusGame.disableSounds){
if (!SagittariusGame.disableSounds) {
long shotid = arrowLandedSound.play(SagittariusGame.soundsVolume);
arrowLandedSound.setPitch(shotid,1.5f);
arrowLandedSound.setPitch(shotid, 1.5f);
}
this.crash = planet;
this.offset = this.getPosition().sub( planet.getPosition() );
this.offset = this.getPosition().sub(planet.getPosition());
GameScreen.nextPlayer();
GameScreen.setFocus(GameScreen.playerCurrent);
break;
@ -211,13 +216,13 @@ public class Arrow extends EntityQuad {
private void verifyHitting() {
for (Actor actor : GameScreen.players.getChildren()) {
Player player = (Player) actor;
if (player == GameScreen.playerCurrent && TTL > 19.5) continue;
if (player == GameScreen.playerCurrent && TTL > 19.5)
continue;
if (Intersector.overlapConvexPolygons(player.hitbox, this.hitbox)) {
// Make a sound when an arrow killed somebody
if ( ! SagittariusGame.disableSounds){
long shotid = arrowHitSound.play(SagittariusGame.soundsVolume);
arrowHitSound.setPitch(shotid,1.5f);
// Make a sound when an arrow kills somebody
if (!SagittariusGame.disableSounds) {
arrowHitSound.play(SagittariusGame.soundsVolume);
}
GameScreen.removePlayer(player);
@ -230,30 +235,32 @@ public class Arrow extends EntityQuad {
private boolean hasHit() {
for (Actor actor : GameScreen.players.getChildren()) {
Player player = (Player) actor;
if (player == GameScreen.playerCurrent) continue;
if (player == GameScreen.playerCurrent)
continue;
if (player.hitbox.contains(this.getPosition())) {
return true;
}
}
return false;
}
/** // TODO : pass directly an Arrow instead of 3 arguments
* Computes the trajectory of an Arrow,
* given its initial conditions.
/**
* // 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.
* @return an array of vertices describing the trajectory of the Arrow.
*/
static Trajectory computeTrajectory(float angle, float power, Player shooter, int iterations, float timeStep) {
static Trajectory computeTrajectory(float angle, float power, Player shooter, int iterations,
float timeStep) {
Trajectory traj = new Trajectory(iterations); // TODO: not optimal
Arrow dummyArrow = new Arrow(angle, power, shooter, true);
for (int i = 0; i < iterations; i++) {
dummyArrow.integrationVerlet(timeStep);
traj.add(dummyArrow.getPosition());
if ( dummyArrow.hasLanded() || dummyArrow.hasHit() ) {
if (dummyArrow.hasLanded() || dummyArrow.hasHit()) {
break;
}
}
@ -262,22 +269,14 @@ public class Arrow extends EntityQuad {
@Override
protected String getInfo() {
if (landed) {
return
"TTL=" + (int)TTL + "\n"
+ "pos=" + (int)getX() + "," + (int)getY() + "\n"
+ "angle=" + (int)getRotation()
;
return "TTL=" + (int) TTL + "\n" + "pos=" + (int) getX() + "," + (int) getY() + "\n"
+ "angle=" + (int) getRotation();
} else {
return
"TTL=" + (int)TTL + "\n"
+ "pos=" + (int)getX() + "," + (int)getY() + "\n"
+ "speed=" + (int)velocity.x + "," + (int)velocity.y + "\n"
+ "accel=" + (int)acceleration.x + "," + (int)acceleration.y +"\n"
+ "force=" + (int)force.x + "," + (int)force.y + "\n"
+ "angle=" + (int)getRotation()
;
return "TTL=" + (int) TTL + "\n" + "pos=" + (int) getX() + "," + (int) getY() + "\n"
+ "speed=" + (int) velocity.x + "," + (int) velocity.y + "\n" + "accel="
+ (int) acceleration.x + "," + (int) acceleration.y + "\n" + "force="
+ (int) force.x + "," + (int) force.y + "\n" + "angle=" + (int) getRotation();
}
}

View file

@ -13,30 +13,32 @@ import sagittarius.SagittariusGame;
public class Bow extends Actor {
// ---------- ATTRIBUTEs ----------
// ---------- ATTRIBUTEs ----------
private boolean aimAssist = false;
private boolean pressed = false;
private float angle;
private Sound shotSound = Gdx.audio.newSound(Gdx.files.internal("sounds/effects/arrow_shot.mp3"));
private Sound shotSound =
Gdx.audio.newSound(Gdx.files.internal("sounds/effects/arrow_shot.mp3"));
private Vector2 anchor = new Vector2();
private Vector2 aim = new Vector2();
private float power;
// ---------- CONSTRUCTORs ----------
// ---------- CONSTRUCTORs ----------
public Bow(boolean aimAssist) {
super();
this.aimAssist = aimAssist;
}
// ---------- METHODs ----------
// ---------- METHODs ----------
@Override
public void act(float dt) {
super.act(dt);
if (GameScreen.playerCurrent.isActive() && Gdx.input.isButtonJustPressed(SagittariusGame.shootArrowButton) && !pressed) {
if (GameScreen.playerCurrent.isActive()
&& Gdx.input.isButtonJustPressed(SagittariusGame.shootArrowButton) && !pressed) {
this.anchor = GameScreen.worldCursor.cpy();
pressed = true;
} else if (Gdx.input.isButtonPressed(SagittariusGame.shootArrowButton) && pressed) {
@ -51,9 +53,9 @@ public class Bow extends Actor {
GameScreen.arrows.addActor(arrowShot);
// Make a sound when an arrow is shot
if ( ! SagittariusGame.disableSounds){
if (!SagittariusGame.disableSounds) {
long shotid = shotSound.play(SagittariusGame.soundsVolume);
shotSound.setPitch(shotid,1.5f);
shotSound.setPitch(shotid, 1.5f);
}
} else {
pressed = false;
@ -64,10 +66,12 @@ public class Bow extends Actor {
public void drawDebug(ShapeRenderer shapes) {
super.drawDebug(shapes);
if (pressed) {
if (power > 50) shapes.setColor(Color.RED);
if (power > 50)
shapes.setColor(Color.RED);
shapes.line(this.anchor, GameScreen.worldCursor);
if (aimAssist) {
Trajectory traj = Arrow.computeTrajectory(angle, power, GameScreen.playerCurrent, 500, 0.03f);
Trajectory traj =
Arrow.computeTrajectory(angle, power, GameScreen.playerCurrent, 500, 0.03f);
shapes.polyline(traj.path, 0, traj.actualSize);
}
}

View file

@ -12,7 +12,7 @@ import sagittarius.view.GameScreen;
public abstract class Entity extends Actor {
// ---------- ATTRIBUTEs ----------
// ---------- ATTRIBUTEs ----------
// private @Null String name;
// private Touchable touchable = Touchable.enabled;
@ -28,9 +28,11 @@ public abstract class Entity extends Actor {
protected float mass;
protected Polygon hitbox;
// ---------- CONSTRUCTORs ----------
// ---------- CONSTRUCTORs ----------
/** Creates an {@link #Entity}.
/**
* Creates an {@link #Entity}.
*
* @param angle angle associated to the {@link #Entity}.
* @param mass mass of the {@link #Entity}.
* @param color color of the {@link #Entity}.
@ -44,7 +46,7 @@ public abstract class Entity extends Actor {
this.hitbox = new Polygon(getHitbox());
}
// ---------- GETTERs ----------
// ---------- GETTERs ----------
/**
* @return angle associated to the {@link #Entity}.
@ -67,7 +69,7 @@ public abstract class Entity extends Actor {
return new Vector2(getX(), getY());
}
// ---------- SETTERs ----------
// ---------- SETTERs ----------
/**
* Sets the angle associated to the {@link #Entity}.
@ -97,7 +99,7 @@ public abstract class Entity extends Actor {
this.setY(position.y);
}
// ---------- METHODs ----------
// ---------- METHODs ----------
/**
* @return String containing informations about the {@link #Entity}
@ -106,6 +108,7 @@ public abstract class Entity extends Actor {
/**
* inpired from {@link ShapeRenderer#rect}
*
* @return vertices of the hitbox polygon
*/
protected abstract float[] getHitbox();
@ -119,12 +122,14 @@ public abstract class Entity extends Actor {
@Override
public void draw(Batch batch, float parentAlpha) {
super.draw(batch, parentAlpha);
if (getDebug()) GameScreen.fontDebug.draw(batch, getInfo(), getX(), getY());
if (getDebug())
GameScreen.fontDebug.draw(batch, getInfo(), getX(), getY());
}
@Override
protected void drawDebugBounds(ShapeRenderer shapes) {
if (!getDebug()) return;
if (!getDebug())
return;
shapes.set(ShapeType.Line);
shapes.setColor(this.getColor());
shapes.polygon(hitbox.getVertices());

View file

@ -6,13 +6,15 @@ import com.badlogic.gdx.math.Vector2;
public abstract class EntityCircle extends Entity {
// ---------- ATTRIBUTEs ----------
// ---------- ATTRIBUTEs ----------
protected float radius;
// ---------- CONSTRUCTORs ----------
// ---------- CONSTRUCTORs ----------
/** Creates an {@link #Entity}.
/**
* Creates an {@link #Entity}.
*
* @param angle angle associated to the {@link #Entity}.
* @param mass mass of the {@link #Entity}.
* @param color color of the {@link #Entity}.
@ -23,7 +25,7 @@ public abstract class EntityCircle extends Entity {
this.radius = radius;
}
// ---------- GETTERs ----------
// ---------- GETTERs ----------
/**
* @return radius of the {@link #EntityCircle}.
@ -32,7 +34,7 @@ public abstract class EntityCircle extends Entity {
return this.radius;
}
// ---------- SETTERs ----------
// ---------- SETTERs ----------
/**
* Sets the radius of the {@link #EntityCircle}.
@ -42,17 +44,18 @@ public abstract class EntityCircle extends Entity {
public void setRadius(float radius) {
this.radius = radius;
}
// ---------- METHODs ----------
// ---------- METHODs ----------
@Override
protected float[] getHitbox() { // peut être optimisé
int segments = 64;
float[] vertices = new float[2*segments];
float[] vertices = new float[2 * segments];
float theta = 360.0f / segments;
for (int i = 0; i < segments; i++) {
vertices[2*i] = getX() + MathUtils.cosDeg(theta * (i+1) + getRotation())*radius;
vertices[2*i+1] = getY() + MathUtils.sinDeg(theta * (i+1) + getRotation())*radius;
vertices[2 * i] = getX() + MathUtils.cosDeg(theta * (i + 1) + getRotation()) * radius;
vertices[2 * i + 1] =
getY() + MathUtils.sinDeg(theta * (i + 1) + getRotation()) * radius;
}
return vertices;

View file

@ -6,9 +6,11 @@ import com.badlogic.gdx.math.Vector2;
public abstract class EntityQuad extends Entity {
// ---------- CONSTRUCTORs ----------
// ---------- CONSTRUCTORs ----------
/** Creates an {@link #Entity}.
/**
* Creates an {@link #Entity}.
*
* @param angle angle associated to the {@link #Entity}.
* @param mass mass of the {@link #Entity}.
* @param color color of the {@link #Entity}.
@ -18,7 +20,7 @@ public abstract class EntityQuad extends Entity {
super(angle, mass, color, position);
}
// ---------- METHODs ----------
// ---------- METHODs ----------
@Override
protected float[] getHitbox() {
@ -51,7 +53,7 @@ public abstract class EntityQuad extends Entity {
float x4 = x1 + (x3 - x2);
float y4 = y3 - (y2 - y1);
return new float[] { x1, y1, x2, y2, x3, y3, x4, y4 };
return new float[] {x1, y1, x2, y2, x3, y3, x4, y4};
}
}

View file

@ -10,7 +10,7 @@ public class Moon extends Planet {
private Planet sun;
private float altitude;
// ---------- CONSTRUCTORs ----------
// ---------- CONSTRUCTORs ----------
public Moon(Planet sun, float mass, float radius, float altitude, Color color) {
super(new Vector2(), mass, radius, color);
@ -19,7 +19,7 @@ public class Moon extends Planet {
this.altitude = altitude;
}
// ---------- GETTERs ----------
// ---------- GETTERs ----------
/**
* @return the Planet which the Moon orbits.
@ -28,20 +28,21 @@ public class Moon extends Planet {
return this.sun;
}
// ---------- METHODs ----------
// ---------- METHODs ----------
@Override
public void act(float dt) {
this.angle += 10.0f / this.altitude;
this.setX(sun.getX() + this.altitude*MathUtils.cosDeg(this.angle));
this.setY(sun.getY() + this.altitude*MathUtils.sinDeg(this.angle));
this.setX(sun.getX() + this.altitude * MathUtils.cosDeg(this.angle));
this.setY(sun.getY() + this.altitude * MathUtils.sinDeg(this.angle));
super.act(dt);
}
@Override
public void drawDebug(ShapeRenderer shapes) {
super.drawDebug(shapes);
if (getStage() != null) shapes.setColor(getStage().getDebugColor());
if (getStage() != null)
shapes.setColor(getStage().getDebugColor());
shapes.line(getX(), getY(), sun.getX(), sun.getY());
}

View file

@ -10,12 +10,12 @@ import com.badlogic.gdx.math.Vector2;
public class Planet extends EntityCircle {
// ---------- ATTRIBUTEs ----------
// ---------- ATTRIBUTEs ----------
float revolutionRate = MathUtils.randomTriangular(1) + 1;
private Texture texture, backGround;
// ---------- CONSTRUCTORs ----------
// ---------- CONSTRUCTORs ----------
public Planet(Vector2 position, float mass, float radius, Color color) {
super(0, mass, color, position, radius);
@ -61,7 +61,7 @@ public class Planet extends EntityCircle {
backGround = new Texture(pm);
}
// ---------- METHODs ----------
// ---------- METHODs ----------
@Override
public void act(float dt) {
@ -71,19 +71,18 @@ public class Planet extends EntityCircle {
@Override
protected String getInfo() {
return
"radius=" + (int)radius + "\n"
+ "mass=" + (int)mass + "\n"
+ "pos=" + (int)getX() + "," + (int)getY()
;
return "radius=" + (int) radius + "\n" + "mass=" + (int) mass + "\n" + "pos=" + (int) getX()
+ "," + (int) getY();
}
@Override
public void draw(Batch batch, float parentAlpha) {
batch.draw(backGround, getPosition().x - this.radius, getPosition().y - this.radius, this.radius, this.radius, 2 * this.radius, 2 * this.radius,
1, 1, getRotation(), 0, 0, texture.getWidth(), texture.getHeight(), false, false);
batch.draw(texture, getPosition().x - this.radius, getPosition().y - this.radius, this.radius, this.radius, 2 * this.radius, 2 * this.radius,
1, 1, getRotation(), 0, 0, texture.getWidth(), texture.getHeight(), false, false);
batch.draw(backGround, getPosition().x - this.radius, getPosition().y - this.radius,
this.radius, this.radius, 2 * this.radius, 2 * this.radius, 1, 1, getRotation(), 0,
0, texture.getWidth(), texture.getHeight(), false, false);
batch.draw(texture, getPosition().x - this.radius, getPosition().y - this.radius,
this.radius, this.radius, 2 * this.radius, 2 * this.radius, 1, 1, getRotation(), 0,
0, texture.getWidth(), texture.getHeight(), false, false);
super.draw(batch, parentAlpha);
}

View file

@ -13,21 +13,21 @@ import sagittarius.SagittariusGame;
public class Player extends EntityQuad {
// ---------- ATTRIBUTEs ----------
// ---------- ATTRIBUTEs ----------
private Planet home;
private boolean active;
private ArrayList<Texture> texture;
private int T = 0;
// ---------- CONSTRUCTORs ----------
// ---------- CONSTRUCTORs ----------
public Player(Planet home, Color color) {
super(MathUtils.random(360), 0, color, home.getPosition());
this.setRotation(home.getRotation() + angle - 90);
this.setSize(50, 100);
this.setOrigin(getWidth()/2, getHeight()/2);
this.setOrigin(getWidth() / 2, getHeight() / 2);
this.home = home;
@ -62,12 +62,13 @@ public class Player extends EntityQuad {
}
}
// ---------- METHODs ----------
// ---------- METHODs ----------
@Override
public void drawDebug(ShapeRenderer shapes) {
super.drawDebug(shapes);
if (getStage() != null) shapes.setColor(getStage().getDebugColor());
if (getStage() != null)
shapes.setColor(getStage().getDebugColor());
shapes.line(home.getX(), home.getY(), getX(), getY());
}
@ -77,8 +78,10 @@ public class Player extends EntityQuad {
T %= 100;
int i = (int) (T * ((float) texture.size() / 100));
batch.draw(texture.get(i), getPosition().x - getWidth()/2, getPosition().y - getHeight()/2, getWidth()/2, getHeight()/2, getWidth(), getHeight(),
1, 1, getRotation(), 0, 0, texture.get(i).getWidth(), texture.get(i).getHeight(), false, false);
batch.draw(texture.get(i), getPosition().x - getWidth() / 2,
getPosition().y - getHeight() / 2, getWidth() / 2, getHeight() / 2, getWidth(),
getHeight(), 1, 1, getRotation(), 0, 0, texture.get(i).getWidth(),
texture.get(i).getHeight(), false, false);
super.draw(batch, parentAlpha);
}
@ -95,17 +98,17 @@ public class Player extends EntityQuad {
}
}
setX(home.getX() + (home.getRadius() + getHeight()/2)*MathUtils.cosDeg(home.getRotation() + angle));
setY(home.getY() + (home.getRadius() + getHeight()/2)*MathUtils.sinDeg(home.getRotation() + angle));
setX(home.getX() + (home.getRadius() + getHeight() / 2)
* MathUtils.cosDeg(home.getRotation() + angle));
setY(home.getY() + (home.getRadius() + getHeight() / 2)
* MathUtils.sinDeg(home.getRotation() + angle));
this.setRotation(home.getRotation() + angle - 90);
}
@Override
protected String getInfo() {
return
"pos=" + (int)getX() + "," + (int)getY()
;
return "pos=" + (int) getX() + "," + (int) getY();
}
/**
@ -117,6 +120,7 @@ public class Player extends EntityQuad {
/**
* Change the active state of the {@link Player}.
*
* @param bool true or false
*/
public void setActive(boolean bool) {

View file

@ -8,7 +8,7 @@ public class Trajectory {
int actualSize;
public Trajectory(int iterations) {
path = new float[2*iterations];
path = new float[2 * iterations];
}
public void add(float x, float y) {

View file

@ -22,6 +22,7 @@ public abstract class BaseScreen implements Screen {
}
public abstract void initialize();
public abstract void update(float dt);
@Override
@ -35,7 +36,7 @@ public abstract class BaseScreen implements Screen {
mainStage.act(dt);
// clear screen
Gdx.gl.glClearColor(0,0,0,1);
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL30.GL_COLOR_BUFFER_BIT);
// draw actors on screnn
@ -43,20 +44,30 @@ public abstract class BaseScreen implements Screen {
uiStage.draw();
}
@Override public void dispose() {
@Override
public void dispose() {
SagittariusGame.music = Gdx.audio.newMusic(Gdx.files.internal("sounds/Ghostrifter-Deflector.mp3"));
SagittariusGame.music =
Gdx.audio.newMusic(Gdx.files.internal("sounds/Ghostrifter-Deflector.mp3"));
uiStage.dispose();
mainStage.dispose();
}
@Override public void resize(int width, int height) {
@Override
public void resize(int width, int height) {
mainStage.getViewport().update(width, height, true);
}
@Override public void pause() {}
@Override public void resume() {}
@Override public void show() {}
@Override public void hide() {}
@Override
public void pause() {}
@Override
public void resume() {}
@Override
public void show() {}
@Override
public void hide() {}
}

View file

@ -15,10 +15,11 @@ public class CreditScreen extends BaseScreen {
public void initialize() {
// A music is played
if (!SagittariusGame.disableMusic){
if (!SagittariusGame.disableMusic) {
SagittariusGame.music.stop();
SagittariusGame.music = Gdx.audio.newMusic(Gdx.files.internal("sounds/music/credit_music.mp3"));
SagittariusGame.music =
Gdx.audio.newMusic(Gdx.files.internal("sounds/music/credit_music.mp3"));
SagittariusGame.music.setLooping(true);
SagittariusGame.music.setVolume(SagittariusGame.musicVolume);
SagittariusGame.music.play();
@ -40,7 +41,7 @@ public class CreditScreen extends BaseScreen {
@Override
public void tap(InputEvent event, float x, float y, int count, int button) {
super.tap(event, x, y, count, button);
SagittariusGame.setActiveScreen( new StartScreen() );
SagittariusGame.setActiveScreen(new StartScreen());
}
});

View file

@ -7,11 +7,11 @@ import com.badlogic.gdx.scenes.scene2d.Stage;
public class FPS extends Actor {
// ---------- ATTRIBUTEs ----------
// ---------- ATTRIBUTEs ----------
private int frameRate;
// ---------- METHODs ----------
// ---------- METHODs ----------
public FPS(Stage stage) {
super();
@ -27,7 +27,8 @@ public class FPS extends Actor {
@Override
public void draw(Batch batch, float parentAlpha) {
super.draw(batch, parentAlpha);
if (getDebug()) GameScreen.fontDebug.draw(batch, getInfo(), getX(), getY());
if (getDebug())
GameScreen.fontDebug.draw(batch, getInfo(), getX(), getY());
}
protected String getInfo() {

View file

@ -16,7 +16,7 @@ import sagittarius.model.*;
public class GameScreen extends BaseScreen implements InputProcessor {
// ---------- ATTRIBUTEs ----------
// ---------- ATTRIBUTEs ----------
public static BitmapFont fontDebug = new BitmapFont();
@ -43,15 +43,16 @@ public class GameScreen extends BaseScreen implements InputProcessor {
// test
private OrthographicCamera gameCam;
// ---------- METHODs ----------
// ---------- METHODs ----------
@Override
public void initialize() {
if (!SagittariusGame.disableMusic){
if (!SagittariusGame.disableMusic) {
SagittariusGame.music.stop();
SagittariusGame.music = Gdx.audio.newMusic(Gdx.files.internal("sounds/music/game_music.mp3"));
SagittariusGame.music =
Gdx.audio.newMusic(Gdx.files.internal("sounds/music/game_music.mp3"));
SagittariusGame.music.setLooping(true);
SagittariusGame.music.setVolume(SagittariusGame.musicVolume);
SagittariusGame.music.play();
@ -124,12 +125,13 @@ public class GameScreen extends BaseScreen implements InputProcessor {
@Override
public void update(float dt) {
screenCursor = new Vector2(Gdx.input.getX(), Gdx.input.getY()); // utiliser les trucs fournis par libGDX
screenCursor = new Vector2(Gdx.input.getX(), Gdx.input.getY()); // utiliser les trucs
// fournis par libGDX
unprojectedCursor = mainStage.getCamera().unproject(new Vector3(screenCursor, 0));
worldCursor = new Vector2(unprojectedCursor.x, unprojectedCursor.y);
if (players.getChildren().size <= 1) {
SagittariusGame.setActiveScreen( new StartScreen() );
SagittariusGame.setActiveScreen(new StartScreen());
}
// camera zoom using keys
@ -144,7 +146,7 @@ public class GameScreen extends BaseScreen implements InputProcessor {
// Pause Menu
if (Gdx.input.isKeyPressed(Keys.ESCAPE)) {
SagittariusGame.setActiveScreen( new ResumeScreen(this) );
SagittariusGame.setActiveScreen(new ResumeScreen(this));
}
// camera follow focus
@ -189,7 +191,7 @@ public class GameScreen extends BaseScreen implements InputProcessor {
focus = entity;
}
// ---------- InputProcessor METHODs ----------
// ---------- InputProcessor METHODs ----------
@Override
public boolean keyDown(int keycode) {

View file

@ -6,7 +6,7 @@ import com.badlogic.gdx.scenes.scene2d.Actor;
public class MouseInfo extends Actor {
// ---------- METHODs ----------
// ---------- METHODs ----------
@Override
public void act(float dt) {
@ -18,14 +18,14 @@ public class MouseInfo extends Actor {
@Override
public void draw(Batch batch, float parentAlpha) {
super.draw(batch, parentAlpha);
if (getDebug()) GameScreen.fontDebug.draw(batch, getInfo(), getX(), getY());
if (getDebug())
GameScreen.fontDebug.draw(batch, getInfo(), getX(), getY());
}
protected String getInfo() {
return
"screen=" + (int)GameScreen.screenCursor.x + "," + (int)GameScreen.screenCursor.y + "\n"
+ "world=" + (int)GameScreen.worldCursor.x + "," + (int)GameScreen.worldCursor.y
;
return "screen=" + (int) GameScreen.screenCursor.x + "," + (int) GameScreen.screenCursor.y
+ "\n" + "world=" + (int) GameScreen.worldCursor.x + ","
+ (int) GameScreen.worldCursor.y;
}
}

View file

@ -15,16 +15,17 @@ public class ResumeScreen extends BaseScreen {
private GameScreen gameScreen;
public ResumeScreen (GameScreen gameScreen){
public ResumeScreen(GameScreen gameScreen) {
this.gameScreen = gameScreen;
}
@Override
public void initialize() {
if (!SagittariusGame.disableMusic){
if (!SagittariusGame.disableMusic) {
SagittariusGame.music.stop();
SagittariusGame.music = Gdx.audio.newMusic(Gdx.files.internal("sounds/music/resumeMenu_music.mp3"));
SagittariusGame.music =
Gdx.audio.newMusic(Gdx.files.internal("sounds/music/resumeMenu_music.mp3"));
SagittariusGame.music.setLooping(true);
SagittariusGame.music.setVolume(SagittariusGame.musicVolume);
SagittariusGame.music.play();
@ -41,14 +42,16 @@ public class ResumeScreen extends BaseScreen {
disableMusic.setChecked(SagittariusGame.disableMusic);
// Change volume of the music
SpinnerSounded musicVolume= new SpinnerSounded("Music Volume:", new SimpleFloatSpinnerModel(SagittariusGame.music.getVolume(), 0f, 1.0f, 0.01f, 3));
SpinnerSounded musicVolume = new SpinnerSounded("Music Volume:",
new SimpleFloatSpinnerModel(SagittariusGame.music.getVolume(), 0f, 1.0f, 0.01f, 3));
// disable sound checkbox
CheckBoxSounded disableSounds= new CheckBoxSounded("disable sounds");
CheckBoxSounded disableSounds = new CheckBoxSounded("disable sounds");
disableSounds.setChecked(SagittariusGame.disableSounds);
// Change volume of the sound
SpinnerSounded musicSounds= new SpinnerSounded("Sounds Volume:", new SimpleFloatSpinnerModel(SagittariusGame.soundsVolume, 0f, 1.0f, 0.01f, 3));
SpinnerSounded musicSounds = new SpinnerSounded("Sounds Volume:",
new SimpleFloatSpinnerModel(SagittariusGame.soundsVolume, 0f, 1.0f, 0.01f, 3));
// save button
ButtonTextSounded applyButton = new ButtonTextSounded("Apply");
@ -57,28 +60,30 @@ public class ResumeScreen extends BaseScreen {
public void tap(InputEvent event, float x, float y, int count, int button) {
super.tap(event, x, y, count, button);
SagittariusGame.music.setVolume(Float.parseFloat(musicVolume.getTextField().getText()));
SagittariusGame.musicVolume = Float.parseFloat(musicVolume.getTextField().getText());
SagittariusGame.soundsVolume = Float.parseFloat(musicSounds.getTextField().getText());
SagittariusGame.music
.setVolume(Float.parseFloat(musicVolume.getTextField().getText()));
SagittariusGame.musicVolume =
Float.parseFloat(musicVolume.getTextField().getText());
SagittariusGame.soundsVolume =
Float.parseFloat(musicSounds.getTextField().getText());
// Deactivate music or not
if (disableMusic.isChecked() && SagittariusGame.music.isPlaying()){
if (disableMusic.isChecked() && SagittariusGame.music.isPlaying()) {
SagittariusGame.music.stop();
SagittariusGame.disableMusic = true;
}
else if (!disableMusic.isChecked() && ! SagittariusGame.music.isPlaying()){
} else if (!disableMusic.isChecked() && !SagittariusGame.music.isPlaying()) {
SagittariusGame.music.setVolume(SagittariusGame.musicVolume);
SagittariusGame.music.play();
SagittariusGame.disableMusic = false;
}
// Deactivate music or not
if (disableSounds.isChecked() ){
if (disableSounds.isChecked()) {
SagittariusGame.disableSounds = true;
}
else {
SagittariusGame.disableSounds= false;
SagittariusGame.disableSounds = false;
}
}
@ -91,14 +96,15 @@ public class ResumeScreen extends BaseScreen {
public void tap(InputEvent event, float x, float y, int count, int button) {
super.tap(event, x, y, count, button);
if (!SagittariusGame.disableMusic){
if (!SagittariusGame.disableMusic) {
SagittariusGame.music.stop();
SagittariusGame.music = Gdx.audio.newMusic(Gdx.files.internal("sounds/music/game_music.mp3"));
SagittariusGame.music =
Gdx.audio.newMusic(Gdx.files.internal("sounds/music/game_music.mp3"));
SagittariusGame.music.setLooping(true);
SagittariusGame.music.setVolume(SagittariusGame.musicVolume);
SagittariusGame.music.play();
}
SagittariusGame.setActiveScreen( gameScreen );
SagittariusGame.setActiveScreen(gameScreen);
}
});
@ -109,7 +115,7 @@ public class ResumeScreen extends BaseScreen {
@Override
public void tap(InputEvent event, float x, float y, int count, int button) {
super.tap(event, x, y, count, button);
SagittariusGame.setActiveScreen( new StartScreen() );
SagittariusGame.setActiveScreen(new StartScreen());
}
});

View file

@ -21,9 +21,10 @@ public class SettingsScreen extends BaseScreen {
@Override
public void initialize() {
if (!SagittariusGame.disableMusic){
if (!SagittariusGame.disableMusic) {
SagittariusGame.music.stop();
SagittariusGame.music = Gdx.audio.newMusic(Gdx.files.internal("sounds/music/resumeMenu_music.mp3"));
SagittariusGame.music =
Gdx.audio.newMusic(Gdx.files.internal("sounds/music/resumeMenu_music.mp3"));
SagittariusGame.music.setLooping(true);
SagittariusGame.music.setVolume(SagittariusGame.musicVolume);
SagittariusGame.music.play();
@ -37,7 +38,8 @@ public class SettingsScreen extends BaseScreen {
uiStage.addActor(table);
// G constant field
SpinnerSounded gConstField = new SpinnerSounded("G constant:", new SimpleFloatSpinnerModel(SagittariusGame.G, 1f, 500f, 0.5f, 3));
SpinnerSounded gConstField = new SpinnerSounded("G constant:",
new SimpleFloatSpinnerModel(SagittariusGame.G, 1f, 500f, 0.5f, 3));
// dubug mode checkbox
CheckBoxSounded debugModeBox = new CheckBoxSounded("debug mode");
@ -48,14 +50,16 @@ public class SettingsScreen extends BaseScreen {
disableMusic.setChecked(SagittariusGame.disableMusic);
// Change volume of the music
SpinnerSounded musicVolume= new SpinnerSounded("Music Volume:", new SimpleFloatSpinnerModel(SagittariusGame.music.getVolume(), 0f, 1.0f, 0.01f, 3));
SpinnerSounded musicVolume = new SpinnerSounded("Music Volume:",
new SimpleFloatSpinnerModel(SagittariusGame.music.getVolume(), 0f, 1.0f, 0.01f, 3));
// disable sound checkbox
CheckBoxSounded disableSounds= new CheckBoxSounded("disable sounds");
CheckBoxSounded disableSounds = new CheckBoxSounded("disable sounds");
disableSounds.setChecked(SagittariusGame.disableSounds);
// Change volume of the sound
SpinnerSounded musicSounds= new SpinnerSounded("Sounds Volume:", new SimpleFloatSpinnerModel(SagittariusGame.soundsVolume, 0f, 1.0f, 0.01f, 3));
SpinnerSounded musicSounds = new SpinnerSounded("Sounds Volume:",
new SimpleFloatSpinnerModel(SagittariusGame.soundsVolume, 0f, 1.0f, 0.01f, 3));
// go back button
ButtonTextSounded returnButton = new ButtonTextSounded("Go Back");
@ -63,7 +67,7 @@ public class SettingsScreen extends BaseScreen {
@Override
public void tap(InputEvent event, float x, float y, int count, int button) {
super.tap(event, x, y, count, button);
SagittariusGame.setActiveScreen( new StartScreen() );
SagittariusGame.setActiveScreen(new StartScreen());
}
});
@ -75,8 +79,9 @@ public class SettingsScreen extends BaseScreen {
VisTextButton zoomOut = new VisTextButton(Keys.toString(SagittariusGame.zoomOutKey));
VisTextButton[] other_buttons = {shootArrow, moveLeft, moveRight, zoomIn, zoomOut};
shootArrow.addListener( new ClickListener() {
shootArrow.addListener(new ClickListener() {
private boolean capturing = false;
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
if (!shootArrow.isDisabled() && !capturing && button == Buttons.LEFT) {
@ -110,33 +115,38 @@ public class SettingsScreen extends BaseScreen {
super.tap(event, x, y, count, button);
SagittariusGame.G = Float.parseFloat(gConstField.getTextField().getText());
SagittariusGame.music.setVolume(Float.parseFloat(musicVolume.getTextField().getText()));
SagittariusGame.musicVolume= Float.parseFloat(musicVolume.getTextField().getText());
SagittariusGame.soundsVolume = Float.parseFloat(musicSounds.getTextField().getText());
SagittariusGame.music
.setVolume(Float.parseFloat(musicVolume.getTextField().getText()));
SagittariusGame.musicVolume =
Float.parseFloat(musicVolume.getTextField().getText());
SagittariusGame.soundsVolume =
Float.parseFloat(musicSounds.getTextField().getText());
SagittariusGame.debugMode = debugModeBox.isChecked();
SagittariusGame.moveLeftKey = Keys.valueOf(moveLeft.getText().toString());
SagittariusGame.moveRightKey = Keys.valueOf(moveRight.getText().toString());
SagittariusGame.zoomInKey = Keys.valueOf(zoomIn.getText().toString());
SagittariusGame.zoomOutKey = Keys.valueOf(zoomOut.getText().toString());
SagittariusGame.shootArrowButton = Keys.valueOf(shootArrow.getText().toString().substring(5));
SagittariusGame.shootArrowButton =
Keys.valueOf(shootArrow.getText().toString().substring(5));
// Deactivate music or not
if (disableMusic.isChecked() && SagittariusGame.music.isPlaying()){
if (disableMusic.isChecked() && SagittariusGame.music.isPlaying()) {
SagittariusGame.music.stop();
SagittariusGame.disableMusic = true;
} else if (!disableMusic.isChecked() && ! SagittariusGame.music.isPlaying()){
SagittariusGame.music = Gdx.audio.newMusic(Gdx.files.internal("sounds/music/resumeMenu_music.mp3"));
} else if (!disableMusic.isChecked() && !SagittariusGame.music.isPlaying()) {
SagittariusGame.music = Gdx.audio
.newMusic(Gdx.files.internal("sounds/music/resumeMenu_music.mp3"));
SagittariusGame.music.setVolume(SagittariusGame.musicVolume);
SagittariusGame.music.play();
SagittariusGame.disableMusic = false;
}
// Deactivate music or not
if (disableSounds.isChecked() ){
if (disableSounds.isChecked()) {
SagittariusGame.disableSounds = true;
} else {
SagittariusGame.disableSounds= false;
SagittariusGame.disableSounds = false;
}
}
});

View file

@ -15,10 +15,11 @@ public class StartScreen extends BaseScreen {
public void initialize() {
// A welcome music is played
if (!SagittariusGame.disableMusic){
if ( SagittariusGame.music != null ){
if (!SagittariusGame.disableMusic) {
if (SagittariusGame.music != null) {
SagittariusGame.music.stop();
SagittariusGame.music = Gdx.audio.newMusic(Gdx.files.internal("sounds/music/mainMenu_music.mp3"));
SagittariusGame.music =
Gdx.audio.newMusic(Gdx.files.internal("sounds/music/mainMenu_music.mp3"));
SagittariusGame.music.setLooping(true);
SagittariusGame.music.setVolume(SagittariusGame.musicVolume);
SagittariusGame.music.play();
@ -26,7 +27,8 @@ public class StartScreen extends BaseScreen {
}
else {
SagittariusGame.music = Gdx.audio.newMusic(Gdx.files.internal("sounds/music/mainMenu_music.mp3"));
SagittariusGame.music =
Gdx.audio.newMusic(Gdx.files.internal("sounds/music/mainMenu_music.mp3"));
SagittariusGame.music.setLooping(true);
SagittariusGame.music.setVolume(SagittariusGame.musicVolume);
SagittariusGame.music.play();
@ -47,7 +49,7 @@ public class StartScreen extends BaseScreen {
@Override
public void tap(InputEvent event, float x, float y, int count, int button) {
super.tap(event, x, y, count, button);
SagittariusGame.setActiveScreen( new GameScreen() );
SagittariusGame.setActiveScreen(new GameScreen());
}
});
@ -56,7 +58,7 @@ public class StartScreen extends BaseScreen {
@Override
public void tap(InputEvent event, float x, float y, int count, int button) {
super.tap(event, x, y, count, button);
SagittariusGame.setActiveScreen( new SettingsScreen() );
SagittariusGame.setActiveScreen(new SettingsScreen());
}
});
@ -65,7 +67,7 @@ public class StartScreen extends BaseScreen {
@Override
public void tap(InputEvent event, float x, float y, int count, int button) {
super.tap(event, x, y, count, button);
SagittariusGame.setActiveScreen( new CreditScreen() );
SagittariusGame.setActiveScreen(new CreditScreen());
}
});