From 3daea10663b8e94e01f6678c0c14f8a65eaa1678 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laure=CE=B7t?= Date: Thu, 8 Apr 2021 21:34:17 +0200 Subject: [PATCH] refactor!: reorganized packages, everything is broken for now --- core/src/sagittarius/{ => model}/Arrow.java | 12 ++++++------ core/src/sagittarius/{ => model}/Bow.java | 4 +++- core/src/sagittarius/{ => model}/Entity.java | 2 +- core/src/sagittarius/{ => model}/Moon.java | 6 +++--- core/src/sagittarius/{ => model}/Planet.java | 8 ++++---- core/src/sagittarius/{ => model}/Player.java | 6 +++--- core/src/sagittarius/{ => view}/GameScreen.java | 7 ++++--- core/src/sagittarius/{ => view}/HUD.java | 16 ++++++++++------ 8 files changed, 34 insertions(+), 27 deletions(-) rename core/src/sagittarius/{ => model}/Arrow.java (96%) rename core/src/sagittarius/{ => model}/Bow.java (97%) rename core/src/sagittarius/{ => model}/Entity.java (96%) rename core/src/sagittarius/{ => model}/Moon.java (86%) rename core/src/sagittarius/{ => model}/Planet.java (83%) rename core/src/sagittarius/{ => model}/Player.java (96%) rename core/src/sagittarius/{ => view}/GameScreen.java (95%) rename core/src/sagittarius/{ => view}/HUD.java (51%) diff --git a/core/src/sagittarius/Arrow.java b/core/src/sagittarius/model/Arrow.java similarity index 96% rename from core/src/sagittarius/Arrow.java rename to core/src/sagittarius/model/Arrow.java index 5ca8b49..253b1c2 100644 --- a/core/src/sagittarius/Arrow.java +++ b/core/src/sagittarius/model/Arrow.java @@ -1,4 +1,4 @@ -package sagittarius; +package sagittarius.model; import java.util.ArrayList; @@ -7,7 +7,7 @@ import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.math.Vector2; -class Arrow extends Entity { +public class Arrow extends Entity { // ---------- ATTRIBUTEs ---------- @@ -15,7 +15,7 @@ class Arrow extends Entity { private Vector2 acceleration = new Vector2(); private Vector2 force = new Vector2(); - protected float TTL = 20; + private float TTL = 20; private final float length = 100; private boolean active = true; @@ -86,7 +86,7 @@ class Arrow extends Entity { * * @param deltaTime time elapsed between 2 frames. */ - void update(float deltaTime) { + public void update(float deltaTime) { if (this.active) { verifyActivity(); @@ -121,12 +121,12 @@ class Arrow extends Entity { // ---------- GRAPHICAL METHODs ---------- - void render(ShapeRenderer shapeRenderer) { + public void render(ShapeRenderer shapeRenderer) { Vector2 tail = new Vector2(-this.length, 0).rotateDeg(this.angle).add(this.position); shapeRenderer.line(this.position, tail); } - void renderDebug(Batch batch, BitmapFont font) { + public void renderDebug(Batch batch, BitmapFont font) { // TODO : dirty, do it in an other way ? if (active) { diff --git a/core/src/sagittarius/Bow.java b/core/src/sagittarius/model/Bow.java similarity index 97% rename from core/src/sagittarius/Bow.java rename to core/src/sagittarius/model/Bow.java index 570ae8c..57d2c59 100644 --- a/core/src/sagittarius/Bow.java +++ b/core/src/sagittarius/model/Bow.java @@ -1,4 +1,4 @@ -package sagittarius; +package sagittarius.model; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Input.Buttons; @@ -6,6 +6,8 @@ import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.math.Vector2; +import sagittarius.SagittariusGame; + class Bow { // ---------- ATTRIBUTEs ---------- diff --git a/core/src/sagittarius/Entity.java b/core/src/sagittarius/model/Entity.java similarity index 96% rename from core/src/sagittarius/Entity.java rename to core/src/sagittarius/model/Entity.java index b62d3fc..ed2a202 100644 --- a/core/src/sagittarius/Entity.java +++ b/core/src/sagittarius/model/Entity.java @@ -1,4 +1,4 @@ -package sagittarius; +package sagittarius.model; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.math.Vector2; diff --git a/core/src/sagittarius/Moon.java b/core/src/sagittarius/model/Moon.java similarity index 86% rename from core/src/sagittarius/Moon.java rename to core/src/sagittarius/model/Moon.java index c81b84c..91ab73c 100644 --- a/core/src/sagittarius/Moon.java +++ b/core/src/sagittarius/model/Moon.java @@ -1,16 +1,16 @@ -package sagittarius; +package sagittarius.model; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.math.MathUtils; -class Moon extends Planet { +public class Moon extends Planet { private Planet planet; private float altitude; // ---------- CONSTRUCTORs ---------- - Moon(Planet planet, float mass, float radius, float altitude) { + public Moon(Planet planet, float mass, float radius, float altitude) { super(planet.position, mass, radius); this.planet = planet; this.altitude = altitude; diff --git a/core/src/sagittarius/Planet.java b/core/src/sagittarius/model/Planet.java similarity index 83% rename from core/src/sagittarius/Planet.java rename to core/src/sagittarius/model/Planet.java index 8a1c0e1..ec8cf2b 100644 --- a/core/src/sagittarius/Planet.java +++ b/core/src/sagittarius/model/Planet.java @@ -1,4 +1,4 @@ -package sagittarius; +package sagittarius.model; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.g2d.Batch; @@ -6,7 +6,7 @@ import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.math.Vector2; -class Planet extends Entity { +public class Planet extends Entity { // ---------- ATTRIBUTEs ---------- @@ -14,12 +14,12 @@ class Planet extends Entity { // ---------- CONSTRUCTORs ---------- - Planet(Vector2 position, float mass, float radius) { + public Planet(Vector2 position, float mass, float radius) { super(position, mass); this.radius = radius; } - Planet(Vector2 position, float mass, float radius, Color color) { + public Planet(Vector2 position, float mass, float radius, Color color) { this(position, mass, radius); this.color = color; } diff --git a/core/src/sagittarius/Player.java b/core/src/sagittarius/model/Player.java similarity index 96% rename from core/src/sagittarius/Player.java rename to core/src/sagittarius/model/Player.java index 1105252..cfb581b 100644 --- a/core/src/sagittarius/Player.java +++ b/core/src/sagittarius/model/Player.java @@ -1,4 +1,4 @@ -package sagittarius; +package sagittarius.model; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Input.Keys; @@ -8,7 +8,7 @@ import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.math.Vector2; -class Player extends Entity { +public class Player extends Entity { // ---------- ATTRIBUTEs ---------- @@ -21,7 +21,7 @@ class Player extends Entity { // ---------- CONSTRUCTORs ---------- - Player(Planet home) { + public Player(Planet home) { super(home.position, 1); this.home = home; this.bow = new Bow(this, true); diff --git a/core/src/sagittarius/GameScreen.java b/core/src/sagittarius/view/GameScreen.java similarity index 95% rename from core/src/sagittarius/GameScreen.java rename to core/src/sagittarius/view/GameScreen.java index a6fd612..abc650f 100644 --- a/core/src/sagittarius/GameScreen.java +++ b/core/src/sagittarius/view/GameScreen.java @@ -1,4 +1,4 @@ -package sagittarius; +package sagittarius.view; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.ScreenAdapter; @@ -26,7 +26,7 @@ class GameScreen extends ScreenAdapter { private BitmapFont font; // camera stuff - private Viewport viewport; // TODO : useless ? + static Viewport viewport; // TODO : useless ? protected static Camera camera; // TODO: categorize better ? @@ -54,7 +54,8 @@ class GameScreen extends ScreenAdapter { clearScreen(); // ---------- batch ---------- - batch.setProjectionMatrix(camera.combined); + batch.setProjectionMatrix(camera.projection); + batch.setTransformMatrix(camera.view); batch.begin(); // planets diff --git a/core/src/sagittarius/HUD.java b/core/src/sagittarius/view/HUD.java similarity index 51% rename from core/src/sagittarius/HUD.java rename to core/src/sagittarius/view/HUD.java index 0587361..146631a 100644 --- a/core/src/sagittarius/HUD.java +++ b/core/src/sagittarius/view/HUD.java @@ -1,6 +1,5 @@ -package sagittarius; +package sagittarius.view; -import com.badlogic.gdx.Game; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.graphics.g2d.BitmapFont; @@ -23,14 +22,19 @@ class HUD implements Disposable { } void render() { + batch.setProjectionMatrix(GameScreen.camera.projection); + batch.setTransformMatrix(GameScreen.camera.view); batch.begin(); // framerate - font.draw(batch, frameRate + " fps", 3, Gdx.graphics.getHeight() - 3); + font.draw(batch, frameRate + " fps", 3, GameScreen.viewport.getWorldHeight() - 3); - // cursor positions, oui c'est dégueu - font.draw(batch, "x_r = " + (int) SagittariusGame.screenCursor.x + ", y_r = " + (int) SagittariusGame.screenCursor.y, SagittariusGame.screenCursor.x + 5, Gdx.graphics.getHeight() - SagittariusGame.screenCursor.y + 5); - font.draw(batch, "x_g = " + (int) SagittariusGame.worldCursor.x + ", y_g = " + (int) SagittariusGame.worldCursor.y, SagittariusGame.screenCursor.x + 5, Gdx.graphics.getHeight() - SagittariusGame.screenCursor.y + 20); + // font.draw(batch, "x_r = " + (int) SagittariusGame.screenCursor.x + ", y_r = " + (int) SagittariusGame.screenCursor.y, + // GameScreen.viewport.getWorldWidth() + 5, + // GameScreen.viewport.getWorldHeight() + 5); + // font.draw(batch, "x_g = " + (int) SagittariusGame.worldCursor.x + ", y_g = " + (int) SagittariusGame.worldCursor.y, + // GameScreen.viewport.getWorldWidth() + 5, + // GameScreen.viewport.getWorldHeight() + 20); batch.end(); }