feat: more dynamic colors !

This commit is contained in:
Laureηt 2021-05-12 18:54:51 +02:00
parent f5d9cbc011
commit bb713b0d61
5 changed files with 54 additions and 10 deletions

View file

@ -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<Float> path = new ArrayList<Float>();
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());

View file

@ -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 {

View file

@ -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 ----------

View file

@ -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));

View file

@ -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;