From bb713b0d612dd6ae934b88e9b1471cd8243e8837 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laure=CE=B7t?= Date: Wed, 12 May 2021 18:54:51 +0200 Subject: [PATCH 1/3] feat: more dynamic colors ! --- core/src/sagittarius/model/Arrow.java | 29 +++++++++++++++++++++-- core/src/sagittarius/model/Bow.java | 2 +- core/src/sagittarius/model/Planet.java | 20 ++++++++++++++++ core/src/sagittarius/model/Player.java | 9 ++++--- core/src/sagittarius/view/GameScreen.java | 4 ++-- 5 files changed, 54 insertions(+), 10 deletions(-) diff --git a/core/src/sagittarius/model/Arrow.java b/core/src/sagittarius/model/Arrow.java index 73d6996..999bfa0 100644 --- a/core/src/sagittarius/model/Arrow.java +++ b/core/src/sagittarius/model/Arrow.java @@ -2,6 +2,9 @@ package sagittarius.model; import java.util.ArrayList; +import com.badlogic.gdx.files.FileHandle; +import com.badlogic.gdx.graphics.Color; +import com.badlogic.gdx.graphics.Pixmap; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.graphics.glutils.ShapeRenderer; @@ -37,7 +40,7 @@ public class Arrow extends EntityQuad { * @param power power given to the Arrow by the Bow. * @param shooter Bow's shooter. */ - Arrow(float angle, float power, Player shooter) { + Arrow(float angle, float power, Player shooter, boolean preview) { super(0, 1, shooter.getColor(), shooter.getPosition()); this.velocity = new Vector2(power, 0).setAngleDeg(angle); this.acceleration = new Vector2(); @@ -47,6 +50,28 @@ public class Arrow extends EntityQuad { this.landed = false; this.texture = new Texture("core/assets/arrow1.png"); + + if (!preview) { + Pixmap pm = new Pixmap(new FileHandle("core/assets/arrow1.png")); + 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)); + } + } + texture = new Texture(pm); + } + } // ---------- METHODs ---------- @@ -192,7 +217,7 @@ public class Arrow extends EntityQuad { */ static float[] traj(float angle, float power, Player shooter, int iterations, float timeStep) { ArrayList path = new ArrayList(); - Arrow dummyArrow = new Arrow(angle, power, shooter); + Arrow dummyArrow = new Arrow(angle, power, shooter, true); for (int i = 0; i < iterations; i++) { dummyArrow.integrationVerlet(timeStep); path.add(dummyArrow.getX()); diff --git a/core/src/sagittarius/model/Bow.java b/core/src/sagittarius/model/Bow.java index cd41593..79fb42d 100644 --- a/core/src/sagittarius/model/Bow.java +++ b/core/src/sagittarius/model/Bow.java @@ -45,7 +45,7 @@ public class Bow extends Actor { } else if (pressed && power > 50) { pressed = false; GameScreen.playerCurrent.setActive(false); - Arrow arrowShot = new Arrow(angle, power, GameScreen.playerCurrent); + Arrow arrowShot = new Arrow(angle, power, GameScreen.playerCurrent, false); GameScreen.setFocus(arrowShot); // do not use constructor 2 times GameScreen.arrows.addActor(arrowShot); } else { diff --git a/core/src/sagittarius/model/Planet.java b/core/src/sagittarius/model/Planet.java index 58b4f67..05d0f60 100644 --- a/core/src/sagittarius/model/Planet.java +++ b/core/src/sagittarius/model/Planet.java @@ -1,6 +1,8 @@ package sagittarius.model; +import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.graphics.Color; +import com.badlogic.gdx.graphics.Pixmap; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.math.MathUtils; @@ -18,6 +20,24 @@ public class Planet extends EntityCircle { public Planet(Vector2 position, float mass, float radius, Color color) { super(0, mass, color, position, radius); this.texture = new Texture("core/assets/planet1.png"); + Pixmap pm = new Pixmap(new FileHandle("core/assets/planet1.png")); + 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 = color.r; + pc.g = color.g; + pc.b = color.b; + } + + pm.drawPixel(x, y, Color.rgba8888(pc)); + } + } + texture = new Texture(pm); } // ---------- METHODs ---------- diff --git a/core/src/sagittarius/model/Player.java b/core/src/sagittarius/model/Player.java index d260716..d611b8c 100644 --- a/core/src/sagittarius/model/Player.java +++ b/core/src/sagittarius/model/Player.java @@ -38,11 +38,10 @@ public class Player extends EntityQuad { Color pc = new Color(); Color.rgba8888ToColor(pc, pm.getPixel(x, y)); - if (pc.equals(Color.WHITE)) { // pc.r == 1 && pc.g == 1 && pc.b == 1 - pc = Color.RED; - // pc.r = 1; - // pc.g = 0; - // pc.b = 0; + if (pc.r == 1 && pc.g == 1 && pc.b == 1) { + pc.r = color.r; + pc.g = color.g; + pc.b = color.b; } pm.drawPixel(x, y, Color.rgba8888(pc)); diff --git a/core/src/sagittarius/view/GameScreen.java b/core/src/sagittarius/view/GameScreen.java index 1da58eb..579d3b2 100644 --- a/core/src/sagittarius/view/GameScreen.java +++ b/core/src/sagittarius/view/GameScreen.java @@ -96,8 +96,8 @@ public class GameScreen extends BaseScreen implements InputProcessor { MouseInfo mouseInfo = new MouseInfo(); uiStage.addActor(mouseInfo); - mainStage.setDebugAll(SagittariusGame.debugMode); - uiStage.setDebugAll(SagittariusGame.debugMode); + // mainStage.setDebugAll(SagittariusGame.debugMode); + // uiStage.setDebugAll(SagittariusGame.debugMode); // game turns playerIndex = 0; From 34aada744b97c894b08936f690a6c41c2b2c8982 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laure=CE=B7t?= Date: Wed, 12 May 2021 19:00:10 +0200 Subject: [PATCH 2/3] fix: debug mode deactivated temporarily --- core/src/sagittarius/SagittariusGame.java | 2 +- core/src/sagittarius/view/GameScreen.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/sagittarius/SagittariusGame.java b/core/src/sagittarius/SagittariusGame.java index f07989a..5e417c1 100644 --- a/core/src/sagittarius/SagittariusGame.java +++ b/core/src/sagittarius/SagittariusGame.java @@ -9,7 +9,7 @@ public class SagittariusGame extends Game { // Constants public static float G = 100; - public static boolean debugMode = true; + public static boolean debugMode = false; private static Game game; diff --git a/core/src/sagittarius/view/GameScreen.java b/core/src/sagittarius/view/GameScreen.java index 579d3b2..1da58eb 100644 --- a/core/src/sagittarius/view/GameScreen.java +++ b/core/src/sagittarius/view/GameScreen.java @@ -96,8 +96,8 @@ public class GameScreen extends BaseScreen implements InputProcessor { MouseInfo mouseInfo = new MouseInfo(); uiStage.addActor(mouseInfo); - // mainStage.setDebugAll(SagittariusGame.debugMode); - // uiStage.setDebugAll(SagittariusGame.debugMode); + mainStage.setDebugAll(SagittariusGame.debugMode); + uiStage.setDebugAll(SagittariusGame.debugMode); // game turns playerIndex = 0; From 63f9ad8a836f27f29f668a0e543615c0baedd73e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laure=CE=B7t?= Date: Wed, 12 May 2021 19:06:26 +0200 Subject: [PATCH 3/3] fix: arrows are now behind planets --- core/src/sagittarius/view/GameScreen.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/src/sagittarius/view/GameScreen.java b/core/src/sagittarius/view/GameScreen.java index 1da58eb..06d828e 100644 --- a/core/src/sagittarius/view/GameScreen.java +++ b/core/src/sagittarius/view/GameScreen.java @@ -50,6 +50,10 @@ public class GameScreen extends BaseScreen implements InputProcessor { Gdx.input.setInputProcessor(this); + // arrows + arrows = new Group(); + mainStage.addActor(arrows); + // planets & moons attractors = new Group(); @@ -81,10 +85,6 @@ public class GameScreen extends BaseScreen implements InputProcessor { mainStage.addActor(players); - // arrows - arrows = new Group(); - mainStage.addActor(arrows); - // The one and only Bow Bow bow = new Bow(true); mainStage.addActor(bow);