diff --git a/core/assets/sprites/player/player.png b/core/assets/sprites/player/player.png new file mode 100644 index 0000000..92e7518 Binary files /dev/null and b/core/assets/sprites/player/player.png differ diff --git a/core/assets/sprites/staticplayer.png b/core/assets/sprites/staticplayer.png index 6e60cea..b80908e 100644 Binary files a/core/assets/sprites/staticplayer.png and b/core/assets/sprites/staticplayer.png differ diff --git a/core/src/com/saltosion/gladiator/GladiatorBrawler.java b/core/src/com/saltosion/gladiator/GladiatorBrawler.java index 1869ed6..af3d223 100644 --- a/core/src/com/saltosion/gladiator/GladiatorBrawler.java +++ b/core/src/com/saltosion/gladiator/GladiatorBrawler.java @@ -6,12 +6,8 @@ import com.badlogic.ashley.core.EntityListener; import com.badlogic.ashley.core.Family; import com.badlogic.gdx.ApplicationAdapter; import com.badlogic.gdx.Gdx; -import com.badlogic.gdx.graphics.GL20; -import com.badlogic.gdx.graphics.OrthographicCamera; -import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.graphics.g2d.Sprite; -import com.badlogic.gdx.graphics.g2d.SpriteBatch; -import com.badlogic.gdx.utils.TimeUtils; +import com.saltosion.gladiator.components.CPosition; import com.saltosion.gladiator.components.CRenderedObject; import com.saltosion.gladiator.systems.RenderingSystem; import com.saltosion.gladiator.util.GlobalStrings; @@ -31,7 +27,7 @@ public class GladiatorBrawler extends ApplicationAdapter { engine.addSystem(new RenderingSystem()); - engine.addEntityListener(Family.getFor(CRenderedObject.class), + engine.addEntityListener(Family.getFor(CRenderedObject.class, CPosition.class), new EntityListener() { @Override public void entityRemoved(Entity entity) { @@ -62,11 +58,15 @@ public class GladiatorBrawler extends ApplicationAdapter { player = new Entity(); CRenderedObject renderedObject = new CRenderedObject(); - Sprite staticplayer = SpriteLoader.loadSprite(GlobalStrings.STATICPLAYER); - renderedObject.spritesequences.put("Idle", new SpriteSequence(staticplayer)); - renderedObject.currentSequence = "Idle"; - + Sprite player1 = SpriteLoader.loadSprite(GlobalStrings.PLAYERIMG, 0, 0, 64, 64); + Sprite player2 = SpriteLoader.loadSprite(GlobalStrings.PLAYERIMG, 1, 0, 64, 64); + SpriteSequence sequence = new SpriteSequence(1).addSprite(player1).addSprite(player2); + renderedObject.addSequence("Idle", sequence); + renderedObject.setCurrentSequence("Idle"); player.add(renderedObject); + player.add(new CPosition()); + player.getComponent(CPosition.class).x = 50; + player.getComponent(CPosition.class).y = 50; engine.addEntity(player); } diff --git a/core/src/com/saltosion/gladiator/SpriteSequence.java b/core/src/com/saltosion/gladiator/SpriteSequence.java index 764d6f9..558f7f0 100644 --- a/core/src/com/saltosion/gladiator/SpriteSequence.java +++ b/core/src/com/saltosion/gladiator/SpriteSequence.java @@ -18,13 +18,18 @@ public class SpriteSequence { defaultPlayspeed = 0; } - public SpriteSequence(float playspeed, ArrayList sprites) { + public SpriteSequence(float playspeed) { this.defaultPlayspeed = playspeed; if (sprites != null) { this.sprites = sprites; } } + public SpriteSequence addSprite(Sprite s) { + sprites.add(s); + return this; + } + public Sprite getSprite(int index) { return sprites.get(index); } @@ -32,5 +37,8 @@ public class SpriteSequence { public float getPlayspeed() { return defaultPlayspeed; } - + + public int frameCount() { + return sprites.size(); + } } diff --git a/core/src/com/saltosion/gladiator/components/CPosition.java b/core/src/com/saltosion/gladiator/components/CPosition.java new file mode 100644 index 0000000..35f79bd --- /dev/null +++ b/core/src/com/saltosion/gladiator/components/CPosition.java @@ -0,0 +1,10 @@ +package com.saltosion.gladiator.components; + +import com.badlogic.ashley.core.Component; + +public class CPosition extends Component { + + public int x = 0; + public int y = 0; + +} diff --git a/core/src/com/saltosion/gladiator/components/CRenderedObject.java b/core/src/com/saltosion/gladiator/components/CRenderedObject.java index d7ee945..c5db95e 100644 --- a/core/src/com/saltosion/gladiator/components/CRenderedObject.java +++ b/core/src/com/saltosion/gladiator/components/CRenderedObject.java @@ -7,8 +7,43 @@ import com.badlogic.gdx.graphics.g2d.Sprite; import com.saltosion.gladiator.SpriteSequence; public class CRenderedObject extends Component { - public HashMap spritesequences = new HashMap(); - public String currentSequence = ""; - public Sprite staticSprite = null; // If this is set, only this image will be shown as the entity - public float currentframe = 0; + private HashMap spritesequences = new HashMap(); + private String currentSequence = ""; + private float currentframe = 0; + + public CRenderedObject() {} + + /** + * Can be used if the Rendered Object is a single static image always. + * @param sprite + */ + public CRenderedObject(Sprite sprite) { + spritesequences.put("Idle", new SpriteSequence(sprite)); + currentSequence = "Idle"; + } + + public void addSequence(String key, SpriteSequence sequence) { + spritesequences.put(key, sequence); + } + + public void setCurrentSequence(String sequence) { + this.currentSequence = sequence; + } + + public void setCurrentFrame(float frame) { + this.currentframe = frame; + } + + public SpriteSequence getSequence(String key) { + return spritesequences.get(key); + } + + public float getCurrentFrame() { + return currentframe; + } + + public String getCurrentSequence() { + return currentSequence; + } + } diff --git a/core/src/com/saltosion/gladiator/systems/RenderingSystem.java b/core/src/com/saltosion/gladiator/systems/RenderingSystem.java index 03aba2f..cdeac41 100644 --- a/core/src/com/saltosion/gladiator/systems/RenderingSystem.java +++ b/core/src/com/saltosion/gladiator/systems/RenderingSystem.java @@ -11,6 +11,7 @@ import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.saltosion.gladiator.SpriteSequence; +import com.saltosion.gladiator.components.CPosition; import com.saltosion.gladiator.components.CRenderedObject; public class RenderingSystem extends EntitySystem { @@ -39,17 +40,23 @@ public class RenderingSystem extends EntitySystem { for (int i=0; i