From 2d377766df4d979e5f6c16731701b26b4c8aee69 Mon Sep 17 00:00:00 2001 From: Damien Date: Fri, 14 May 2021 11:32:31 +0200 Subject: [PATCH] des ptit bonhommes --- core/src/sagittarius/model/Player.java | 45 +++++++++++++++++--------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/core/src/sagittarius/model/Player.java b/core/src/sagittarius/model/Player.java index 28682ce..f3b4687 100644 --- a/core/src/sagittarius/model/Player.java +++ b/core/src/sagittarius/model/Player.java @@ -1,5 +1,7 @@ package sagittarius.model; +import java.util.ArrayList; + import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Input.Keys; import com.badlogic.gdx.files.FileHandle; @@ -16,7 +18,7 @@ public class Player extends EntityQuad { private Planet home; private boolean active; - private Texture texture; + private ArrayList texture; // ---------- CONSTRUCTORs ---------- @@ -29,24 +31,35 @@ public class Player extends EntityQuad { this.home = home; - Pixmap pm = new Pixmap(new FileHandle("core/assets/player1.png")); - pm.setBlending(Pixmap.Blending.None); - for (int x = 0; x < pm.getWidth(); x++) { - for (int y = 0; y < pm.getHeight(); y++) { + texture = new ArrayList<>(); + String path = "core/assets/player0"; - Color pc = new Color(); - Color.rgba8888ToColor(pc, pm.getPixel(x, y)); + int i = 0; + while (true) { + try { + Pixmap pm = new Pixmap(new FileHandle(path + "-" + i + ".png")); + pm.setBlending(Pixmap.Blending.None); + for (int x = 0; x < pm.getWidth(); x++) { + for (int y = 0; y < pm.getHeight(); y++) { - if (pc.r == 1 && pc.g == 1 && pc.b == 1) { - pc.r = color.r; - pc.g = color.g; - pc.b = color.b; + 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)); + } } - - pm.drawPixel(x, y, Color.rgba8888(pc)); + texture.add(new Texture(pm)); + i++; + } catch (com.badlogic.gdx.utils.GdxRuntimeException e) { + break; } } - texture = new Texture(pm); } // ---------- METHODs ---------- @@ -60,8 +73,8 @@ public class Player extends EntityQuad { @Override public void draw(Batch batch, float parentAlpha) { - batch.draw(texture, getPosition().x - getWidth()/2, getPosition().y - getHeight()/2, this.getWidth()/2, this.getHeight()/2, getWidth(), getHeight(), - 1, 1, getRotation(), 0, 0, texture.getWidth(), texture.getHeight(), false, false); + batch.draw(texture.get(0), getPosition().x - getWidth()/2, getPosition().y - getHeight()/2, getWidth()/2, getHeight()/2, getWidth(), getHeight(), + 1, 1, getRotation(), 0, 0, texture.get(0).getWidth(), texture.get(0).getHeight(), false, false); super.draw(batch, parentAlpha); }