From b76cb1d15916df1048324d32d0cdf595993ee1ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laure=CE=B7t?= Date: Thu, 27 May 2021 11:04:00 +0200 Subject: [PATCH] chore: formatting --- .editorconfig | 15 ++ core/src/sagittarius/model/Arrow.java | 119 ++++++----- core/src/sagittarius/model/Bow.java | 28 +-- core/src/sagittarius/model/Entity.java | 189 +++++++++--------- core/src/sagittarius/model/EntityCircle.java | 85 ++++---- core/src/sagittarius/model/EntityQuad.java | 78 ++++---- core/src/sagittarius/model/Moon.java | 15 +- core/src/sagittarius/model/Planet.java | 27 ++- core/src/sagittarius/model/Player.java | 32 +-- core/src/sagittarius/model/Trajectory.java | 2 +- core/src/sagittarius/view/BaseScreen.java | 29 ++- core/src/sagittarius/view/CreditScreen.java | 19 +- core/src/sagittarius/view/FPS.java | 7 +- core/src/sagittarius/view/GameScreen.java | 40 ++-- core/src/sagittarius/view/MouseInfo.java | 12 +- core/src/sagittarius/view/ResumeScreen.java | 54 ++--- core/src/sagittarius/view/SettingsScreen.java | 56 +++--- core/src/sagittarius/view/SetupScreen.java | 2 +- core/src/sagittarius/view/StartScreen.java | 20 +- 19 files changed, 447 insertions(+), 382 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..e5ce663 --- /dev/null +++ b/.editorconfig @@ -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 \ No newline at end of file diff --git a/core/src/sagittarius/model/Arrow.java b/core/src/sagittarius/model/Arrow.java index fc32414..f33b15f 100644 --- a/core/src/sagittarius/model/Arrow.java +++ b/core/src/sagittarius/model/Arrow.java @@ -12,14 +12,14 @@ import com.badlogic.gdx.math.Intersector; import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.scenes.scene2d.Actor; -import com.badlogic.gdx.audio.Sound; +import com.badlogic.gdx.audio.Sound; import sagittarius.SagittariusGame; 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; -// ---------- CONSTRUCTORs ---------- + // ---------- CONSTRUCTORs ---------- /** * Constructs an Arrow using its initial conditions. @@ -52,11 +52,13 @@ public class Arrow extends EntityQuad { this.setSize(50, 4); this.force = computeForce(); this.landed = false; - + 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); @@ -68,16 +70,16 @@ public class Arrow extends EntityQuad { pm.setBlending(Pixmap.Blending.None); for (int x = 0; x < pm.getWidth(); x++) { for (int y = 0; y < pm.getHeight(); y++) { - + Color pc = new Color(); Color.rgba8888ToColor(pc, pm.getPixel(x, y)); - + if (pc.r == 1 && pc.g == 1 && pc.b == 1) { pc.r = getColor().r; pc.g = getColor().g; pc.b = getColor().b; } - + pm.drawPixel(x, y, Color.rgba8888(pc)); } } @@ -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 https://gamedev.stackexchange.com/a/41917. + * @see https://gamedev.stackexchange.com/a/41917. */ 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; } /** @@ -179,15 +184,15 @@ public class Arrow extends EntityQuad { Planet planet = (Planet) actor; if (planet.hitbox.contains(this.getPosition())) { landed = true; - + // Make a sound when an arrow lands - if ( ! SagittariusGame.disableSounds){ - long shotid = arrowLandedSound.play(SagittariusGame.soundsVolume); - arrowLandedSound.setPitch(shotid,1.5f); + if (!SagittariusGame.disableSounds) { + long shotid = arrowLandedSound.play(SagittariusGame.soundsVolume); + 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,18 +216,18 @@ 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); break; - + } } } @@ -230,31 +235,33 @@ 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() ) { - break; + if (dummyArrow.hasLanded() || dummyArrow.hasHit()) { + break; } } return traj; @@ -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(); } } diff --git a/core/src/sagittarius/model/Bow.java b/core/src/sagittarius/model/Bow.java index b0270cd..68badc1 100644 --- a/core/src/sagittarius/model/Bow.java +++ b/core/src/sagittarius/model/Bow.java @@ -6,37 +6,39 @@ import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.math.Vector2; 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.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; - } + 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); } } diff --git a/core/src/sagittarius/model/Entity.java b/core/src/sagittarius/model/Entity.java index 05c856c..e3935d1 100644 --- a/core/src/sagittarius/model/Entity.java +++ b/core/src/sagittarius/model/Entity.java @@ -12,122 +12,127 @@ import sagittarius.view.GameScreen; public abstract class Entity extends Actor { -// ---------- ATTRIBUTEs ---------- + // ---------- ATTRIBUTEs ---------- - // private @Null String name; - // private Touchable touchable = Touchable.enabled; - // private boolean visible = true, debug; - // float x, y; - // float width, height; - // float originX, originY; - // float scaleX = 1, scaleY = 1; - // float rotation; - // final Color color = new Color(1, 1, 1, 1); + // private @Null String name; + // private Touchable touchable = Touchable.enabled; + // private boolean visible = true, debug; + // float x, y; + // float width, height; + // float originX, originY; + // float scaleX = 1, scaleY = 1; + // float rotation; + // final Color color = new Color(1, 1, 1, 1); - protected float angle; - protected float mass; + protected float angle; + protected float mass; protected Polygon hitbox; -// ---------- CONSTRUCTORs ---------- + // ---------- CONSTRUCTORs ---------- - /** 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 Entity(float angle, float mass, Color color, Vector2 position) { - this.angle = angle; - this.mass = mass; - this.setColor(color); - this.setPosition(position); - this.hitbox = new Polygon(getHitbox()); - } + /** + * 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 Entity(float angle, float mass, Color color, Vector2 position) { + this.angle = angle; + this.mass = mass; + this.setColor(color); + this.setPosition(position); + this.hitbox = new Polygon(getHitbox()); + } -// ---------- GETTERs ---------- + // ---------- GETTERs ---------- - /** - * @return angle associated to the {@link #Entity}. - */ - public float getAngle() { - return this.angle; - } + /** + * @return angle associated to the {@link #Entity}. + */ + public float getAngle() { + return this.angle; + } - /** - * @return mass of the {@link #Entity}. - */ - public float getMass() { - return this.mass; - } + /** + * @return mass of the {@link #Entity}. + */ + public float getMass() { + return this.mass; + } - /** - * @return position of the {@link #Entity}. - */ - public Vector2 getPosition() { - return new Vector2(getX(), getY()); - } + /** + * @return position of the {@link #Entity}. + */ + public Vector2 getPosition() { + return new Vector2(getX(), getY()); + } -// ---------- SETTERs ---------- + // ---------- SETTERs ---------- - /** - * Sets the angle associated to the {@link #Entity}. - * - * @param angle new angle. - */ - public void setAngle(float angle) { - this.angle = angle; - } + /** + * Sets the angle associated to the {@link #Entity}. + * + * @param angle new angle. + */ + public void setAngle(float angle) { + this.angle = angle; + } - /** - * Sets the mass of the {@link #Entity}. - * - * @param mass new mass. - */ - public void setMass(float mass) { - this.mass = mass; - } + /** + * Sets the mass of the {@link #Entity}. + * + * @param mass new mass. + */ + public void setMass(float mass) { + this.mass = mass; + } - /** - * Sets the Position of the {@link #Entity}. - * - * @param position new position. - */ - public void setPosition(Vector2 position) { - this.setX(position.x); - this.setY(position.y); - } + /** + * Sets the Position of the {@link #Entity}. + * + * @param position new position. + */ + public void setPosition(Vector2 position) { + this.setX(position.x); + this.setY(position.y); + } -// ---------- METHODs ---------- + // ---------- METHODs ---------- - /** - * @return String containing informations about the {@link #Entity} - */ - protected abstract String getInfo(); + /** + * @return String containing informations about the {@link #Entity} + */ + protected abstract String getInfo(); - /** - * inpired from {@link ShapeRenderer#rect} - * @return vertices of the hitbox polygon - */ - protected abstract float[] getHitbox(); + /** + * inpired from {@link ShapeRenderer#rect} + * + * @return vertices of the hitbox polygon + */ + protected abstract float[] getHitbox(); - @Override - public void act(float dt) { - super.act(dt); - hitbox.setVertices(getHitbox()); - } + @Override + public void act(float dt) { + super.act(dt); + hitbox.setVertices(getHitbox()); + } @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; - shapes.set(ShapeType.Line); - shapes.setColor(this.getColor()); - shapes.polygon(hitbox.getVertices()); - } + if (!getDebug()) + return; + shapes.set(ShapeType.Line); + shapes.setColor(this.getColor()); + shapes.polygon(hitbox.getVertices()); + } } diff --git a/core/src/sagittarius/model/EntityCircle.java b/core/src/sagittarius/model/EntityCircle.java index 183ddf1..10a7a64 100644 --- a/core/src/sagittarius/model/EntityCircle.java +++ b/core/src/sagittarius/model/EntityCircle.java @@ -6,56 +6,59 @@ import com.badlogic.gdx.math.Vector2; 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}. - * @param mass mass of the {@link #Entity}. - * @param color color of the {@link #Entity}. - * @param position position of the {@link #Entity}. - */ - public EntityCircle(float angle, float mass, Color color, Vector2 position, float radius) { - super(angle, mass, color, position); - this.radius = radius; - } + /** + * 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 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}. - */ - public float getRadius() { - return this.radius; - } + /** + * @return radius of the {@link #EntityCircle}. + */ + public float getRadius() { + return this.radius; + } -// ---------- SETTERs ---------- + // ---------- SETTERs ---------- - /** - * Sets the radius of the {@link #EntityCircle}. - * - * @param radius new radius. - */ - public void setRadius(float radius) { - this.radius = radius; - } -// ---------- METHODs ---------- + /** + * Sets the radius of the {@link #EntityCircle}. + * + * @param radius new radius. + */ + public void setRadius(float radius) { + this.radius = radius; + } + // ---------- METHODs ---------- - @Override - protected float[] getHitbox() { // peut être optimisé - int segments = 64; - float[] vertices = new float[2*segments]; + @Override + protected float[] getHitbox() { // peut être optimisé + int segments = 64; + 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; - } + 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; + } - return vertices; - } + return vertices; + } } diff --git a/core/src/sagittarius/model/EntityQuad.java b/core/src/sagittarius/model/EntityQuad.java index 811a849..4151572 100644 --- a/core/src/sagittarius/model/EntityQuad.java +++ b/core/src/sagittarius/model/EntityQuad.java @@ -5,53 +5,55 @@ import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.math.Vector2; public abstract class EntityQuad extends Entity { - -// ---------- CONSTRUCTORs ---------- - /** 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); - } + // ---------- CONSTRUCTORs ---------- -// ---------- 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 - 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(); + // ---------- METHODs ---------- - if (getScaleX() != 1 || getScaleX() != 1) { - fx *= getScaleX(); - fy *= getScaleY(); - fx2 *= getScaleX(); - fy2 *= getScaleY(); - } + @Override + 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(); - float worldOriginX = getX(); - float worldOriginY = getY(); + if (getScaleX() != 1 || getScaleX() != 1) { + fx *= getScaleX(); + fy *= getScaleY(); + fx2 *= getScaleX(); + fy2 *= getScaleY(); + } - float x1 = cos * fx - sin * fy + worldOriginX; - float y1 = sin * fx + cos * fy + worldOriginY; + float worldOriginX = getX(); + float worldOriginY = getY(); - float x2 = cos * fx2 - sin * fy + worldOriginX; - float y2 = sin * fx2 + cos * fy + worldOriginY; + float x1 = cos * fx - sin * fy + worldOriginX; + float y1 = sin * fx + cos * fy + worldOriginY; - float x3 = cos * fx2 - sin * fy2 + worldOriginX; - float y3 = sin * fx2 + cos * fy2 + worldOriginY; + float x2 = cos * fx2 - sin * fy + worldOriginX; + float y2 = sin * fx2 + cos * fy + worldOriginY; - float x4 = x1 + (x3 - x2); - float y4 = y3 - (y2 - y1); + float x3 = cos * fx2 - sin * fy2 + worldOriginX; + 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}; + } } diff --git a/core/src/sagittarius/model/Moon.java b/core/src/sagittarius/model/Moon.java index c0257db..e8a53b6 100644 --- a/core/src/sagittarius/model/Moon.java +++ b/core/src/sagittarius/model/Moon.java @@ -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,21 +28,22 @@ 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()); } -} \ No newline at end of file +} diff --git a/core/src/sagittarius/model/Planet.java b/core/src/sagittarius/model/Planet.java index 1c7f669..57cf6fa 100644 --- a/core/src/sagittarius/model/Planet.java +++ b/core/src/sagittarius/model/Planet.java @@ -10,18 +10,18 @@ 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); Pixmap pm = new Pixmap(Gdx.files.internal("planet" + MathUtils.random(4) + ".png")); - + pm.setBlending(Pixmap.Blending.None); for (int x = 0; x < pm.getWidth(); x++) { for (int y = 0; y < pm.getHeight(); y++) { @@ -61,7 +61,7 @@ public class Planet extends EntityCircle { backGround = new Texture(pm); } -// ---------- METHODs ---------- + // ---------- METHODs ---------- @Override public void act(float dt) { @@ -71,20 +71,19 @@ 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); - } + } } diff --git a/core/src/sagittarius/model/Player.java b/core/src/sagittarius/model/Player.java index cd8ab07..95e75dd 100644 --- a/core/src/sagittarius/model/Player.java +++ b/core/src/sagittarius/model/Player.java @@ -13,21 +13,21 @@ import sagittarius.SagittariusGame; public class Player extends EntityQuad { -// ---------- ATTRIBUTEs ---------- + // ---------- ATTRIBUTEs ---------- private Planet home; private boolean active; private ArrayList 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()); } @@ -76,11 +77,13 @@ public class Player extends EntityQuad { T++; 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); - } + } @Override 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)); - 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) { diff --git a/core/src/sagittarius/model/Trajectory.java b/core/src/sagittarius/model/Trajectory.java index 8491db0..6b7807c 100644 --- a/core/src/sagittarius/model/Trajectory.java +++ b/core/src/sagittarius/model/Trajectory.java @@ -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) { diff --git a/core/src/sagittarius/view/BaseScreen.java b/core/src/sagittarius/view/BaseScreen.java index 1516e8a..31e8322 100644 --- a/core/src/sagittarius/view/BaseScreen.java +++ b/core/src/sagittarius/view/BaseScreen.java @@ -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() {} -} \ No newline at end of file + @Override + public void resume() {} + + @Override + public void show() {} + + @Override + public void hide() {} + +} diff --git a/core/src/sagittarius/view/CreditScreen.java b/core/src/sagittarius/view/CreditScreen.java index a6167b0..0d22579 100644 --- a/core/src/sagittarius/view/CreditScreen.java +++ b/core/src/sagittarius/view/CreditScreen.java @@ -15,13 +15,14 @@ public class CreditScreen extends BaseScreen { public void initialize() { // A music is played - if (!SagittariusGame.disableMusic){ - - SagittariusGame.music.stop(); - 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(); + if (!SagittariusGame.disableMusic) { + + SagittariusGame.music.stop(); + 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()); } }); @@ -59,4 +60,4 @@ public class CreditScreen extends BaseScreen { super.dispose(); } -} \ No newline at end of file +} diff --git a/core/src/sagittarius/view/FPS.java b/core/src/sagittarius/view/FPS.java index f581349..67f26d3 100644 --- a/core/src/sagittarius/view/FPS.java +++ b/core/src/sagittarius/view/FPS.java @@ -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() { diff --git a/core/src/sagittarius/view/GameScreen.java b/core/src/sagittarius/view/GameScreen.java index 7379011..d1b34b0 100644 --- a/core/src/sagittarius/view/GameScreen.java +++ b/core/src/sagittarius/view/GameScreen.java @@ -16,14 +16,14 @@ import sagittarius.model.*; public class GameScreen extends BaseScreen implements InputProcessor { -// ---------- ATTRIBUTEs ---------- + // ---------- ATTRIBUTEs ---------- public static BitmapFont fontDebug = new BitmapFont(); // Cursors public static Vector2 screenCursor; private static Vector3 unprojectedCursor; - public static Vector2 worldCursor; + public static Vector2 worldCursor; // Groups public static Group attractors; @@ -43,19 +43,20 @@ public class GameScreen extends BaseScreen implements InputProcessor { // test private OrthographicCamera gameCam; -// ---------- METHODs ---------- + // ---------- METHODs ---------- @Override public void initialize() { - if (!SagittariusGame.disableMusic){ - - SagittariusGame.music.stop(); - 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(); - + if (!SagittariusGame.disableMusic) { + + SagittariusGame.music.stop(); + 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(); + } Gdx.input.setInputProcessor(this); @@ -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 - unprojectedCursor = mainStage.getCamera().unproject(new Vector3(screenCursor, 0)); - worldCursor = new Vector2(unprojectedCursor.x, unprojectedCursor.y); + 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 @@ -139,12 +141,12 @@ public class GameScreen extends BaseScreen implements InputProcessor { if (Gdx.input.isKeyPressed(SagittariusGame.zoomOutKey)) { gameCam.zoom -= dt; } - // clamp zoom + // clamp zoom gameCam.zoom = MathUtils.clamp(gameCam.zoom, 1f, 3f); - // Pause Menu + // 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) { diff --git a/core/src/sagittarius/view/MouseInfo.java b/core/src/sagittarius/view/MouseInfo.java index 221f1e1..33089f3 100644 --- a/core/src/sagittarius/view/MouseInfo.java +++ b/core/src/sagittarius/view/MouseInfo.java @@ -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; } } diff --git a/core/src/sagittarius/view/ResumeScreen.java b/core/src/sagittarius/view/ResumeScreen.java index d86612a..e11e514 100644 --- a/core/src/sagittarius/view/ResumeScreen.java +++ b/core/src/sagittarius/view/ResumeScreen.java @@ -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(); @@ -35,20 +36,22 @@ public class ResumeScreen extends BaseScreen { VisTable table = new VisTable(true); table.setFillParent(true); uiStage.addActor(table); - + // disable music checkbox CheckBoxSounded disableMusic = new CheckBoxSounded("disable music"); 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()){ + // Deactivate music or not + 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() ){ + // Deactivate music or not + 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()); } }); @@ -138,4 +144,4 @@ public class ResumeScreen extends BaseScreen { super.dispose(); } -} \ No newline at end of file +} diff --git a/core/src/sagittarius/view/SettingsScreen.java b/core/src/sagittarius/view/SettingsScreen.java index f7b4dc0..5503f6b 100644 --- a/core/src/sagittarius/view/SettingsScreen.java +++ b/core/src/sagittarius/view/SettingsScreen.java @@ -20,10 +20,11 @@ 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,25 +38,28 @@ 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"); debugModeBox.setChecked(SagittariusGame.debugMode); - + // disable music checkbox CheckBoxSounded disableMusic = new CheckBoxSounded("disable music"); 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()){ + // Deactivate music or not + 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() ){ + // Deactivate music or not + if (disableSounds.isChecked()) { SagittariusGame.disableSounds = true; } else { - SagittariusGame.disableSounds= false; + SagittariusGame.disableSounds = false; } } }); @@ -183,4 +193,4 @@ public class SettingsScreen extends BaseScreen { super.dispose(); } -} \ No newline at end of file +} diff --git a/core/src/sagittarius/view/SetupScreen.java b/core/src/sagittarius/view/SetupScreen.java index d4579e0..ef7239f 100644 --- a/core/src/sagittarius/view/SetupScreen.java +++ b/core/src/sagittarius/view/SetupScreen.java @@ -31,4 +31,4 @@ public class SetupScreen extends BaseScreen { super.dispose(); } -} \ No newline at end of file +} diff --git a/core/src/sagittarius/view/StartScreen.java b/core/src/sagittarius/view/StartScreen.java index 31d11d8..67eef01 100644 --- a/core/src/sagittarius/view/StartScreen.java +++ b/core/src/sagittarius/view/StartScreen.java @@ -15,18 +15,20 @@ 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(); - + } 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()); } }); @@ -102,4 +104,4 @@ public class StartScreen extends BaseScreen { super.dispose(); } -} \ No newline at end of file +}