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

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

View file

@ -6,37 +6,39 @@ 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; import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.audio.Sound; import com.badlogic.gdx.audio.Sound;
import sagittarius.view.GameScreen; import sagittarius.view.GameScreen;
import sagittarius.SagittariusGame; import sagittarius.SagittariusGame;
public class Bow extends Actor { public class Bow extends Actor {
// ---------- ATTRIBUTEs ---------- // ---------- ATTRIBUTEs ----------
private boolean aimAssist = false; private boolean aimAssist = false;
private boolean pressed = false; private boolean pressed = false;
private float angle; 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 anchor = new Vector2();
private Vector2 aim = new Vector2(); private Vector2 aim = new Vector2();
private float power; private float power;
// ---------- CONSTRUCTORs ---------- // ---------- CONSTRUCTORs ----------
public Bow(boolean aimAssist) { public Bow(boolean aimAssist) {
super(); super();
this.aimAssist = aimAssist; this.aimAssist = aimAssist;
} }
// ---------- METHODs ---------- // ---------- METHODs ----------
@Override @Override
public void act(float dt) { public void act(float dt) {
super.act(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(); this.anchor = GameScreen.worldCursor.cpy();
pressed = true; pressed = true;
} else if (Gdx.input.isButtonPressed(SagittariusGame.shootArrowButton) && pressed) { } else if (Gdx.input.isButtonPressed(SagittariusGame.shootArrowButton) && pressed) {
@ -51,9 +53,9 @@ public class Bow extends Actor {
GameScreen.arrows.addActor(arrowShot); GameScreen.arrows.addActor(arrowShot);
// Make a sound when an arrow is shot // Make a sound when an arrow is shot
if ( ! SagittariusGame.disableSounds){ if (!SagittariusGame.disableSounds) {
long shotid = shotSound.play(SagittariusGame.soundsVolume); long shotid = shotSound.play(SagittariusGame.soundsVolume);
shotSound.setPitch(shotid,1.5f); shotSound.setPitch(shotid, 1.5f);
} }
} else { } else {
pressed = false; pressed = false;
@ -64,10 +66,12 @@ public class Bow extends Actor {
public void drawDebug(ShapeRenderer shapes) { public void drawDebug(ShapeRenderer shapes) {
super.drawDebug(shapes); super.drawDebug(shapes);
if (pressed) { if (pressed) {
if (power > 50) shapes.setColor(Color.RED); if (power > 50)
shapes.setColor(Color.RED);
shapes.line(this.anchor, GameScreen.worldCursor); shapes.line(this.anchor, GameScreen.worldCursor);
if (aimAssist) { 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); shapes.polyline(traj.path, 0, traj.actualSize);
} }
} }

View file

@ -12,122 +12,127 @@ import sagittarius.view.GameScreen;
public abstract class Entity extends Actor { public abstract class Entity extends Actor {
// ---------- ATTRIBUTEs ---------- // ---------- ATTRIBUTEs ----------
// private @Null String name; // private @Null String name;
// private Touchable touchable = Touchable.enabled; // private Touchable touchable = Touchable.enabled;
// private boolean visible = true, debug; // private boolean visible = true, debug;
// float x, y; // float x, y;
// float width, height; // float width, height;
// float originX, originY; // float originX, originY;
// float scaleX = 1, scaleY = 1; // float scaleX = 1, scaleY = 1;
// float rotation; // float rotation;
// final Color color = new Color(1, 1, 1, 1); // final Color color = new Color(1, 1, 1, 1);
protected float angle; protected float angle;
protected float mass; protected float mass;
protected Polygon hitbox; protected Polygon hitbox;
// ---------- CONSTRUCTORs ---------- // ---------- CONSTRUCTORs ----------
/** Creates an {@link #Entity}. /**
* @param angle angle associated to the {@link #Entity}. * Creates an {@link #Entity}.
* @param mass mass of the {@link #Entity}. *
* @param color color of the {@link #Entity}. * @param angle angle associated to the {@link #Entity}.
* @param position position of the {@link #Entity}. * @param mass mass of the {@link #Entity}.
*/ * @param color color of the {@link #Entity}.
public Entity(float angle, float mass, Color color, Vector2 position) { * @param position position of the {@link #Entity}.
this.angle = angle; */
this.mass = mass; public Entity(float angle, float mass, Color color, Vector2 position) {
this.setColor(color); this.angle = angle;
this.setPosition(position); this.mass = mass;
this.hitbox = new Polygon(getHitbox()); this.setColor(color);
} this.setPosition(position);
this.hitbox = new Polygon(getHitbox());
}
// ---------- GETTERs ---------- // ---------- GETTERs ----------
/** /**
* @return angle associated to the {@link #Entity}. * @return angle associated to the {@link #Entity}.
*/ */
public float getAngle() { public float getAngle() {
return this.angle; return this.angle;
} }
/** /**
* @return mass of the {@link #Entity}. * @return mass of the {@link #Entity}.
*/ */
public float getMass() { public float getMass() {
return this.mass; return this.mass;
} }
/** /**
* @return position of the {@link #Entity}. * @return position of the {@link #Entity}.
*/ */
public Vector2 getPosition() { public Vector2 getPosition() {
return new Vector2(getX(), getY()); return new Vector2(getX(), getY());
} }
// ---------- SETTERs ---------- // ---------- SETTERs ----------
/** /**
* Sets the angle associated to the {@link #Entity}. * Sets the angle associated to the {@link #Entity}.
* *
* @param angle new angle. * @param angle new angle.
*/ */
public void setAngle(float angle) { public void setAngle(float angle) {
this.angle = angle; this.angle = angle;
} }
/** /**
* Sets the mass of the {@link #Entity}. * Sets the mass of the {@link #Entity}.
* *
* @param mass new mass. * @param mass new mass.
*/ */
public void setMass(float mass) { public void setMass(float mass) {
this.mass = mass; this.mass = mass;
} }
/** /**
* Sets the Position of the {@link #Entity}. * Sets the Position of the {@link #Entity}.
* *
* @param position new position. * @param position new position.
*/ */
public void setPosition(Vector2 position) { public void setPosition(Vector2 position) {
this.setX(position.x); this.setX(position.x);
this.setY(position.y); this.setY(position.y);
} }
// ---------- METHODs ---------- // ---------- METHODs ----------
/** /**
* @return String containing informations about the {@link #Entity} * @return String containing informations about the {@link #Entity}
*/ */
protected abstract String getInfo(); protected abstract String getInfo();
/** /**
* inpired from {@link ShapeRenderer#rect} * inpired from {@link ShapeRenderer#rect}
* @return vertices of the hitbox polygon *
*/ * @return vertices of the hitbox polygon
protected abstract float[] getHitbox(); */
protected abstract float[] getHitbox();
@Override @Override
public void act(float dt) { public void act(float dt) {
super.act(dt); super.act(dt);
hitbox.setVertices(getHitbox()); hitbox.setVertices(getHitbox());
} }
@Override @Override
public void draw(Batch batch, float parentAlpha) { public void draw(Batch batch, float parentAlpha) {
super.draw(batch, parentAlpha); super.draw(batch, parentAlpha);
if (getDebug()) GameScreen.fontDebug.draw(batch, getInfo(), getX(), getY()); if (getDebug())
GameScreen.fontDebug.draw(batch, getInfo(), getX(), getY());
} }
@Override @Override
protected void drawDebugBounds(ShapeRenderer shapes) { protected void drawDebugBounds(ShapeRenderer shapes) {
if (!getDebug()) return; if (!getDebug())
shapes.set(ShapeType.Line); return;
shapes.setColor(this.getColor()); shapes.set(ShapeType.Line);
shapes.polygon(hitbox.getVertices()); shapes.setColor(this.getColor());
} shapes.polygon(hitbox.getVertices());
}
} }

View file

@ -6,56 +6,59 @@ import com.badlogic.gdx.math.Vector2;
public abstract class EntityCircle extends Entity { public abstract class EntityCircle extends Entity {
// ---------- ATTRIBUTEs ---------- // ---------- ATTRIBUTEs ----------
protected float radius; protected float radius;
// ---------- CONSTRUCTORs ---------- // ---------- CONSTRUCTORs ----------
/** Creates an {@link #Entity}. /**
* @param angle angle associated to the {@link #Entity}. * Creates an {@link #Entity}.
* @param mass mass of the {@link #Entity}. *
* @param color color of the {@link #Entity}. * @param angle angle associated to the {@link #Entity}.
* @param position position of the {@link #Entity}. * @param mass mass of the {@link #Entity}.
*/ * @param color color of the {@link #Entity}.
public EntityCircle(float angle, float mass, Color color, Vector2 position, float radius) { * @param position position of the {@link #Entity}.
super(angle, mass, color, position); */
this.radius = radius; public EntityCircle(float angle, float mass, Color color, Vector2 position, float radius) {
} super(angle, mass, color, position);
this.radius = radius;
}
// ---------- GETTERs ---------- // ---------- GETTERs ----------
/** /**
* @return radius of the {@link #EntityCircle}. * @return radius of the {@link #EntityCircle}.
*/ */
public float getRadius() { public float getRadius() {
return this.radius; return this.radius;
} }
// ---------- SETTERs ---------- // ---------- SETTERs ----------
/** /**
* Sets the radius of the {@link #EntityCircle}. * Sets the radius of the {@link #EntityCircle}.
* *
* @param radius new radius. * @param radius new radius.
*/ */
public void setRadius(float radius) { public void setRadius(float radius) {
this.radius = radius; this.radius = radius;
} }
// ---------- METHODs ---------- // ---------- METHODs ----------
@Override @Override
protected float[] getHitbox() { // peut être optimisé protected float[] getHitbox() { // peut être optimisé
int segments = 64; int segments = 64;
float[] vertices = new float[2*segments]; float[] vertices = new float[2 * segments];
float theta = 360.0f / segments; float theta = 360.0f / segments;
for (int i = 0; i < segments; i++) { for (int i = 0; i < segments; i++) {
vertices[2*i] = getX() + MathUtils.cosDeg(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; vertices[2 * i + 1] =
} getY() + MathUtils.sinDeg(theta * (i + 1) + getRotation()) * radius;
}
return vertices; return vertices;
} }
} }

View file

@ -5,53 +5,55 @@ import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector2;
public abstract class EntityQuad extends Entity { public abstract class EntityQuad extends Entity {
// ---------- CONSTRUCTORs ----------
/** Creates an {@link #Entity}. // ---------- CONSTRUCTORs ----------
* @param angle angle associated to the {@link #Entity}.
* @param mass mass of the {@link #Entity}.
* @param color color of the {@link #Entity}.
* @param position position of the {@link #Entity}.
*/
public EntityQuad(float angle, float mass, Color color, Vector2 position) {
super(angle, mass, color, position);
}
// ---------- METHODs ---------- /**
* 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}.
* @param position position of the {@link #Entity}.
*/
public EntityQuad(float angle, float mass, Color color, Vector2 position) {
super(angle, mass, color, position);
}
@Override // ---------- METHODs ----------
protected float[] getHitbox() {
float cos = MathUtils.cosDeg(getRotation());
float sin = MathUtils.sinDeg(getRotation());
float fx = -getOriginX();
float fy = -getOriginY();
float fx2 = getWidth() - getOriginX();
float fy2 = getHeight() - getOriginY();
if (getScaleX() != 1 || getScaleX() != 1) { @Override
fx *= getScaleX(); protected float[] getHitbox() {
fy *= getScaleY(); float cos = MathUtils.cosDeg(getRotation());
fx2 *= getScaleX(); float sin = MathUtils.sinDeg(getRotation());
fy2 *= getScaleY(); float fx = -getOriginX();
} float fy = -getOriginY();
float fx2 = getWidth() - getOriginX();
float fy2 = getHeight() - getOriginY();
float worldOriginX = getX(); if (getScaleX() != 1 || getScaleX() != 1) {
float worldOriginY = getY(); fx *= getScaleX();
fy *= getScaleY();
fx2 *= getScaleX();
fy2 *= getScaleY();
}
float x1 = cos * fx - sin * fy + worldOriginX; float worldOriginX = getX();
float y1 = sin * fx + cos * fy + worldOriginY; float worldOriginY = getY();
float x2 = cos * fx2 - sin * fy + worldOriginX; float x1 = cos * fx - sin * fy + worldOriginX;
float y2 = sin * fx2 + cos * fy + worldOriginY; float y1 = sin * fx + cos * fy + worldOriginY;
float x3 = cos * fx2 - sin * fy2 + worldOriginX; float x2 = cos * fx2 - sin * fy + worldOriginX;
float y3 = sin * fx2 + cos * fy2 + worldOriginY; float y2 = sin * fx2 + cos * fy + worldOriginY;
float x4 = x1 + (x3 - x2); float x3 = cos * fx2 - sin * fy2 + worldOriginX;
float y4 = y3 - (y2 - y1); float y3 = sin * fx2 + cos * fy2 + worldOriginY;
return new float[] { x1, y1, x2, y2, x3, y3, x4, y4 }; float x4 = x1 + (x3 - x2);
} float y4 = y3 - (y2 - y1);
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 Planet sun;
private float altitude; private float altitude;
// ---------- 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(new Vector2(), mass, radius, color);
@ -19,7 +19,7 @@ public class Moon extends Planet {
this.altitude = altitude; this.altitude = altitude;
} }
// ---------- GETTERs ---------- // ---------- GETTERs ----------
/** /**
* @return the Planet which the Moon orbits. * @return the Planet which the Moon orbits.
@ -28,21 +28,22 @@ public class Moon extends Planet {
return this.sun; return this.sun;
} }
// ---------- METHODs ---------- // ---------- METHODs ----------
@Override @Override
public void act(float dt) { public void act(float dt) {
this.angle += 10.0f / this.altitude; this.angle += 10.0f / this.altitude;
this.setX(sun.getX() + this.altitude*MathUtils.cosDeg(this.angle)); this.setX(sun.getX() + this.altitude * MathUtils.cosDeg(this.angle));
this.setY(sun.getY() + this.altitude*MathUtils.sinDeg(this.angle)); this.setY(sun.getY() + this.altitude * MathUtils.sinDeg(this.angle));
super.act(dt); super.act(dt);
} }
@Override @Override
public void drawDebug(ShapeRenderer shapes) { public void drawDebug(ShapeRenderer shapes) {
super.drawDebug(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()); shapes.line(getX(), getY(), sun.getX(), sun.getY());
} }
} }

View file

@ -10,18 +10,18 @@ import com.badlogic.gdx.math.Vector2;
public class Planet extends EntityCircle { public class Planet extends EntityCircle {
// ---------- ATTRIBUTEs ---------- // ---------- ATTRIBUTEs ----------
float revolutionRate = MathUtils.randomTriangular(1) + 1; float revolutionRate = MathUtils.randomTriangular(1) + 1;
private Texture texture, backGround; private Texture texture, backGround;
// ---------- CONSTRUCTORs ---------- // ---------- CONSTRUCTORs ----------
public Planet(Vector2 position, float mass, float radius, Color color) { public Planet(Vector2 position, float mass, float radius, Color color) {
super(0, mass, color, position, radius); super(0, mass, color, position, radius);
Pixmap pm = new Pixmap(Gdx.files.internal("planet" + MathUtils.random(4) + ".png")); Pixmap pm = new Pixmap(Gdx.files.internal("planet" + MathUtils.random(4) + ".png"));
pm.setBlending(Pixmap.Blending.None); pm.setBlending(Pixmap.Blending.None);
for (int x = 0; x < pm.getWidth(); x++) { for (int x = 0; x < pm.getWidth(); x++) {
for (int y = 0; y < pm.getHeight(); y++) { for (int y = 0; y < pm.getHeight(); y++) {
@ -61,7 +61,7 @@ public class Planet extends EntityCircle {
backGround = new Texture(pm); backGround = new Texture(pm);
} }
// ---------- METHODs ---------- // ---------- METHODs ----------
@Override @Override
public void act(float dt) { public void act(float dt) {
@ -71,20 +71,19 @@ public class Planet extends EntityCircle {
@Override @Override
protected String getInfo() { protected String getInfo() {
return return "radius=" + (int) radius + "\n" + "mass=" + (int) mass + "\n" + "pos=" + (int) getX()
"radius=" + (int)radius + "\n" + "," + (int) getY();
+ "mass=" + (int)mass + "\n"
+ "pos=" + (int)getX() + "," + (int)getY()
;
} }
@Override @Override
public void draw(Batch batch, float parentAlpha) { 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, batch.draw(backGround, getPosition().x - this.radius, getPosition().y - this.radius,
1, 1, getRotation(), 0, 0, texture.getWidth(), texture.getHeight(), false, false); this.radius, this.radius, 2 * this.radius, 2 * this.radius, 1, 1, getRotation(), 0,
batch.draw(texture, getPosition().x - this.radius, getPosition().y - this.radius, this.radius, this.radius, 2 * this.radius, 2 * this.radius, 0, texture.getWidth(), texture.getHeight(), false, false);
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); super.draw(batch, parentAlpha);
} }
} }

View file

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

View file

@ -8,7 +8,7 @@ public class Trajectory {
int actualSize; int actualSize;
public Trajectory(int iterations) { public Trajectory(int iterations) {
path = new float[2*iterations]; path = new float[2 * iterations];
} }
public void add(float x, float y) { 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 initialize();
public abstract void update(float dt); public abstract void update(float dt);
@Override @Override
@ -35,7 +36,7 @@ public abstract class BaseScreen implements Screen {
mainStage.act(dt); mainStage.act(dt);
// clear screen // clear screen
Gdx.gl.glClearColor(0,0,0,1); Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL30.GL_COLOR_BUFFER_BIT); Gdx.gl.glClear(GL30.GL_COLOR_BUFFER_BIT);
// draw actors on screnn // draw actors on screnn
@ -43,20 +44,30 @@ public abstract class BaseScreen implements Screen {
uiStage.draw(); 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(); uiStage.dispose();
mainStage.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); mainStage.getViewport().update(width, height, true);
} }
@Override public void pause() {} @Override
@Override public void resume() {} public void pause() {}
@Override public void show() {}
@Override public void hide() {}
} @Override
public void resume() {}
@Override
public void show() {}
@Override
public void hide() {}
}

View file

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

View file

@ -7,11 +7,11 @@ import com.badlogic.gdx.scenes.scene2d.Stage;
public class FPS extends Actor { public class FPS extends Actor {
// ---------- ATTRIBUTEs ---------- // ---------- ATTRIBUTEs ----------
private int frameRate; private int frameRate;
// ---------- METHODs ---------- // ---------- METHODs ----------
public FPS(Stage stage) { public FPS(Stage stage) {
super(); super();
@ -27,7 +27,8 @@ public class FPS extends Actor {
@Override @Override
public void draw(Batch batch, float parentAlpha) { public void draw(Batch batch, float parentAlpha) {
super.draw(batch, 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() { protected String getInfo() {

View file

@ -16,14 +16,14 @@ import sagittarius.model.*;
public class GameScreen extends BaseScreen implements InputProcessor { public class GameScreen extends BaseScreen implements InputProcessor {
// ---------- ATTRIBUTEs ---------- // ---------- ATTRIBUTEs ----------
public static BitmapFont fontDebug = new BitmapFont(); public static BitmapFont fontDebug = new BitmapFont();
// Cursors // Cursors
public static Vector2 screenCursor; public static Vector2 screenCursor;
private static Vector3 unprojectedCursor; private static Vector3 unprojectedCursor;
public static Vector2 worldCursor; public static Vector2 worldCursor;
// Groups // Groups
public static Group attractors; public static Group attractors;
@ -43,19 +43,20 @@ public class GameScreen extends BaseScreen implements InputProcessor {
// test // test
private OrthographicCamera gameCam; private OrthographicCamera gameCam;
// ---------- METHODs ---------- // ---------- METHODs ----------
@Override @Override
public void initialize() { public void initialize() {
if (!SagittariusGame.disableMusic){ if (!SagittariusGame.disableMusic) {
SagittariusGame.music.stop(); SagittariusGame.music.stop();
SagittariusGame.music = Gdx.audio.newMusic(Gdx.files.internal("sounds/music/game_music.mp3")); SagittariusGame.music =
SagittariusGame.music.setLooping(true); Gdx.audio.newMusic(Gdx.files.internal("sounds/music/game_music.mp3"));
SagittariusGame.music.setVolume(SagittariusGame.musicVolume); SagittariusGame.music.setLooping(true);
SagittariusGame.music.play(); SagittariusGame.music.setVolume(SagittariusGame.musicVolume);
SagittariusGame.music.play();
} }
Gdx.input.setInputProcessor(this); Gdx.input.setInputProcessor(this);
@ -124,12 +125,13 @@ public class GameScreen extends BaseScreen implements InputProcessor {
@Override @Override
public void update(float dt) { 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
unprojectedCursor = mainStage.getCamera().unproject(new Vector3(screenCursor, 0)); // fournis par libGDX
worldCursor = new Vector2(unprojectedCursor.x, unprojectedCursor.y); unprojectedCursor = mainStage.getCamera().unproject(new Vector3(screenCursor, 0));
worldCursor = new Vector2(unprojectedCursor.x, unprojectedCursor.y);
if (players.getChildren().size <= 1) { if (players.getChildren().size <= 1) {
SagittariusGame.setActiveScreen( new StartScreen() ); SagittariusGame.setActiveScreen(new StartScreen());
} }
// camera zoom using keys // camera zoom using keys
@ -139,12 +141,12 @@ public class GameScreen extends BaseScreen implements InputProcessor {
if (Gdx.input.isKeyPressed(SagittariusGame.zoomOutKey)) { if (Gdx.input.isKeyPressed(SagittariusGame.zoomOutKey)) {
gameCam.zoom -= dt; gameCam.zoom -= dt;
} }
// clamp zoom // clamp zoom
gameCam.zoom = MathUtils.clamp(gameCam.zoom, 1f, 3f); gameCam.zoom = MathUtils.clamp(gameCam.zoom, 1f, 3f);
// Pause Menu // Pause Menu
if (Gdx.input.isKeyPressed(Keys.ESCAPE)) { if (Gdx.input.isKeyPressed(Keys.ESCAPE)) {
SagittariusGame.setActiveScreen( new ResumeScreen(this) ); SagittariusGame.setActiveScreen(new ResumeScreen(this));
} }
// camera follow focus // camera follow focus
@ -189,7 +191,7 @@ public class GameScreen extends BaseScreen implements InputProcessor {
focus = entity; focus = entity;
} }
// ---------- InputProcessor METHODs ---------- // ---------- InputProcessor METHODs ----------
@Override @Override
public boolean keyDown(int keycode) { public boolean keyDown(int keycode) {

View file

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

View file

@ -15,16 +15,17 @@ public class ResumeScreen extends BaseScreen {
private GameScreen gameScreen; private GameScreen gameScreen;
public ResumeScreen (GameScreen gameScreen){ public ResumeScreen(GameScreen gameScreen) {
this.gameScreen = gameScreen; this.gameScreen = gameScreen;
} }
@Override @Override
public void initialize() { public void initialize() {
if (!SagittariusGame.disableMusic){ if (!SagittariusGame.disableMusic) {
SagittariusGame.music.stop(); 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.setLooping(true);
SagittariusGame.music.setVolume(SagittariusGame.musicVolume); SagittariusGame.music.setVolume(SagittariusGame.musicVolume);
SagittariusGame.music.play(); SagittariusGame.music.play();
@ -35,20 +36,22 @@ public class ResumeScreen extends BaseScreen {
VisTable table = new VisTable(true); VisTable table = new VisTable(true);
table.setFillParent(true); table.setFillParent(true);
uiStage.addActor(table); uiStage.addActor(table);
// disable music checkbox // disable music checkbox
CheckBoxSounded disableMusic = new CheckBoxSounded("disable music"); CheckBoxSounded disableMusic = new CheckBoxSounded("disable music");
disableMusic.setChecked(SagittariusGame.disableMusic); disableMusic.setChecked(SagittariusGame.disableMusic);
// Change volume of the music // 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 // disable sound checkbox
CheckBoxSounded disableSounds= new CheckBoxSounded("disable sounds"); CheckBoxSounded disableSounds = new CheckBoxSounded("disable sounds");
disableSounds.setChecked(SagittariusGame.disableSounds); disableSounds.setChecked(SagittariusGame.disableSounds);
// Change volume of the sound // 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 // save button
ButtonTextSounded applyButton = new ButtonTextSounded("Apply"); 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) { public void tap(InputEvent event, float x, float y, int count, int button) {
super.tap(event, x, y, count, button); super.tap(event, x, y, count, button);
SagittariusGame.music.setVolume(Float.parseFloat(musicVolume.getTextField().getText())); SagittariusGame.music
SagittariusGame.musicVolume = Float.parseFloat(musicVolume.getTextField().getText()); .setVolume(Float.parseFloat(musicVolume.getTextField().getText()));
SagittariusGame.soundsVolume = Float.parseFloat(musicSounds.getTextField().getText()); SagittariusGame.musicVolume =
Float.parseFloat(musicVolume.getTextField().getText());
SagittariusGame.soundsVolume =
Float.parseFloat(musicSounds.getTextField().getText());
// Deactivate music or not // Deactivate music or not
if (disableMusic.isChecked() && SagittariusGame.music.isPlaying()){ if (disableMusic.isChecked() && SagittariusGame.music.isPlaying()) {
SagittariusGame.music.stop(); SagittariusGame.music.stop();
SagittariusGame.disableMusic = true; SagittariusGame.disableMusic = true;
} } else if (!disableMusic.isChecked() && !SagittariusGame.music.isPlaying()) {
else if (!disableMusic.isChecked() && ! SagittariusGame.music.isPlaying()){
SagittariusGame.music.setVolume(SagittariusGame.musicVolume); SagittariusGame.music.setVolume(SagittariusGame.musicVolume);
SagittariusGame.music.play(); SagittariusGame.music.play();
SagittariusGame.disableMusic = false; SagittariusGame.disableMusic = false;
} }
// Deactivate music or not // Deactivate music or not
if (disableSounds.isChecked() ){ if (disableSounds.isChecked()) {
SagittariusGame.disableSounds = true; SagittariusGame.disableSounds = true;
} }
else { 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) { public void tap(InputEvent event, float x, float y, int count, int button) {
super.tap(event, x, y, count, button); super.tap(event, x, y, count, button);
if (!SagittariusGame.disableMusic){ if (!SagittariusGame.disableMusic) {
SagittariusGame.music.stop(); 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.setLooping(true);
SagittariusGame.music.setVolume(SagittariusGame.musicVolume); SagittariusGame.music.setVolume(SagittariusGame.musicVolume);
SagittariusGame.music.play(); SagittariusGame.music.play();
} }
SagittariusGame.setActiveScreen( gameScreen ); SagittariusGame.setActiveScreen(gameScreen);
} }
}); });
@ -109,7 +115,7 @@ public class ResumeScreen extends BaseScreen {
@Override @Override
public void tap(InputEvent event, float x, float y, int count, int button) { public void tap(InputEvent event, float x, float y, int count, int button) {
super.tap(event, x, y, count, button); super.tap(event, x, y, count, button);
SagittariusGame.setActiveScreen( new StartScreen() ); SagittariusGame.setActiveScreen(new StartScreen());
} }
}); });
@ -138,4 +144,4 @@ public class ResumeScreen extends BaseScreen {
super.dispose(); super.dispose();
} }
} }

View file

@ -20,10 +20,11 @@ public class SettingsScreen extends BaseScreen {
@Override @Override
public void initialize() { public void initialize() {
if (!SagittariusGame.disableMusic){ if (!SagittariusGame.disableMusic) {
SagittariusGame.music.stop(); 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.setLooping(true);
SagittariusGame.music.setVolume(SagittariusGame.musicVolume); SagittariusGame.music.setVolume(SagittariusGame.musicVolume);
SagittariusGame.music.play(); SagittariusGame.music.play();
@ -37,25 +38,28 @@ public class SettingsScreen extends BaseScreen {
uiStage.addActor(table); uiStage.addActor(table);
// G constant field // 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 // dubug mode checkbox
CheckBoxSounded debugModeBox = new CheckBoxSounded("debug mode"); CheckBoxSounded debugModeBox = new CheckBoxSounded("debug mode");
debugModeBox.setChecked(SagittariusGame.debugMode); debugModeBox.setChecked(SagittariusGame.debugMode);
// disable music checkbox // disable music checkbox
CheckBoxSounded disableMusic = new CheckBoxSounded("disable music"); CheckBoxSounded disableMusic = new CheckBoxSounded("disable music");
disableMusic.setChecked(SagittariusGame.disableMusic); disableMusic.setChecked(SagittariusGame.disableMusic);
// Change volume of the music // 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 // disable sound checkbox
CheckBoxSounded disableSounds= new CheckBoxSounded("disable sounds"); CheckBoxSounded disableSounds = new CheckBoxSounded("disable sounds");
disableSounds.setChecked(SagittariusGame.disableSounds); disableSounds.setChecked(SagittariusGame.disableSounds);
// Change volume of the sound // 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 // go back button
ButtonTextSounded returnButton = new ButtonTextSounded("Go Back"); ButtonTextSounded returnButton = new ButtonTextSounded("Go Back");
@ -63,7 +67,7 @@ public class SettingsScreen extends BaseScreen {
@Override @Override
public void tap(InputEvent event, float x, float y, int count, int button) { public void tap(InputEvent event, float x, float y, int count, int button) {
super.tap(event, x, y, count, 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 zoomOut = new VisTextButton(Keys.toString(SagittariusGame.zoomOutKey));
VisTextButton[] other_buttons = {shootArrow, moveLeft, moveRight, zoomIn, zoomOut}; VisTextButton[] other_buttons = {shootArrow, moveLeft, moveRight, zoomIn, zoomOut};
shootArrow.addListener( new ClickListener() { shootArrow.addListener(new ClickListener() {
private boolean capturing = false; private boolean capturing = false;
@Override @Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) { public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
if (!shootArrow.isDisabled() && !capturing && button == Buttons.LEFT) { if (!shootArrow.isDisabled() && !capturing && button == Buttons.LEFT) {
@ -110,33 +115,38 @@ public class SettingsScreen extends BaseScreen {
super.tap(event, x, y, count, button); super.tap(event, x, y, count, button);
SagittariusGame.G = Float.parseFloat(gConstField.getTextField().getText()); SagittariusGame.G = Float.parseFloat(gConstField.getTextField().getText());
SagittariusGame.music.setVolume(Float.parseFloat(musicVolume.getTextField().getText())); SagittariusGame.music
SagittariusGame.musicVolume= Float.parseFloat(musicVolume.getTextField().getText()); .setVolume(Float.parseFloat(musicVolume.getTextField().getText()));
SagittariusGame.soundsVolume = Float.parseFloat(musicSounds.getTextField().getText()); SagittariusGame.musicVolume =
Float.parseFloat(musicVolume.getTextField().getText());
SagittariusGame.soundsVolume =
Float.parseFloat(musicSounds.getTextField().getText());
SagittariusGame.debugMode = debugModeBox.isChecked(); SagittariusGame.debugMode = debugModeBox.isChecked();
SagittariusGame.moveLeftKey = Keys.valueOf(moveLeft.getText().toString()); SagittariusGame.moveLeftKey = Keys.valueOf(moveLeft.getText().toString());
SagittariusGame.moveRightKey = Keys.valueOf(moveRight.getText().toString()); SagittariusGame.moveRightKey = Keys.valueOf(moveRight.getText().toString());
SagittariusGame.zoomInKey = Keys.valueOf(zoomIn.getText().toString()); SagittariusGame.zoomInKey = Keys.valueOf(zoomIn.getText().toString());
SagittariusGame.zoomOutKey = Keys.valueOf(zoomOut.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 // Deactivate music or not
if (disableMusic.isChecked() && SagittariusGame.music.isPlaying()){ if (disableMusic.isChecked() && SagittariusGame.music.isPlaying()) {
SagittariusGame.music.stop(); SagittariusGame.music.stop();
SagittariusGame.disableMusic = true; SagittariusGame.disableMusic = true;
} else if (!disableMusic.isChecked() && ! SagittariusGame.music.isPlaying()){ } else if (!disableMusic.isChecked() && !SagittariusGame.music.isPlaying()) {
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.setVolume(SagittariusGame.musicVolume); SagittariusGame.music.setVolume(SagittariusGame.musicVolume);
SagittariusGame.music.play(); SagittariusGame.music.play();
SagittariusGame.disableMusic = false; SagittariusGame.disableMusic = false;
} }
// Deactivate music or not // Deactivate music or not
if (disableSounds.isChecked() ){ if (disableSounds.isChecked()) {
SagittariusGame.disableSounds = true; SagittariusGame.disableSounds = true;
} else { } else {
SagittariusGame.disableSounds= false; SagittariusGame.disableSounds = false;
} }
} }
}); });
@ -183,4 +193,4 @@ public class SettingsScreen extends BaseScreen {
super.dispose(); super.dispose();
} }
} }

View file

@ -31,4 +31,4 @@ public class SetupScreen extends BaseScreen {
super.dispose(); super.dispose();
} }
} }

View file

@ -15,18 +15,20 @@ public class StartScreen extends BaseScreen {
public void initialize() { public void initialize() {
// A welcome music is played // A welcome music is played
if (!SagittariusGame.disableMusic){ if (!SagittariusGame.disableMusic) {
if ( SagittariusGame.music != null ){ if (SagittariusGame.music != null) {
SagittariusGame.music.stop(); 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.setLooping(true);
SagittariusGame.music.setVolume(SagittariusGame.musicVolume); SagittariusGame.music.setVolume(SagittariusGame.musicVolume);
SagittariusGame.music.play(); SagittariusGame.music.play();
} }
else { 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.setLooping(true);
SagittariusGame.music.setVolume(SagittariusGame.musicVolume); SagittariusGame.music.setVolume(SagittariusGame.musicVolume);
SagittariusGame.music.play(); SagittariusGame.music.play();
@ -47,7 +49,7 @@ public class StartScreen extends BaseScreen {
@Override @Override
public void tap(InputEvent event, float x, float y, int count, int button) { public void tap(InputEvent event, float x, float y, int count, int button) {
super.tap(event, x, y, count, 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 @Override
public void tap(InputEvent event, float x, float y, int count, int button) { public void tap(InputEvent event, float x, float y, int count, int button) {
super.tap(event, x, y, count, 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 @Override
public void tap(InputEvent event, float x, float y, int count, int button) { public void tap(InputEvent event, float x, float y, int count, int button) {
super.tap(event, x, y, count, button); super.tap(event, x, y, count, button);
SagittariusGame.setActiveScreen( new CreditScreen() ); SagittariusGame.setActiveScreen(new CreditScreen());
} }
}); });
@ -102,4 +104,4 @@ public class StartScreen extends BaseScreen {
super.dispose(); super.dispose();
} }
} }