From 962dde9db26628e01d2c1e44f60173191cad8ec4 Mon Sep 17 00:00:00 2001 From: Allexit Date: Wed, 8 Apr 2015 20:50:13 +0300 Subject: [PATCH] Animation now renders, and rendered entities now must have position --- core/assets/sprites/player/player.png | Bin 0 -> 755 bytes core/assets/sprites/staticplayer.png | Bin 742 -> 742 bytes .../saltosion/gladiator/GladiatorBrawler.java | 20 ++++---- .../saltosion/gladiator/SpriteSequence.java | 12 ++++- .../gladiator/components/CPosition.java | 10 ++++ .../gladiator/components/CRenderedObject.java | 43 ++++++++++++++++-- .../gladiator/systems/RenderingSystem.java | 15 ++++-- .../gladiator/util/GlobalStrings.java | 1 + .../gladiator/util/SpriteLoader.java | 3 +- 9 files changed, 83 insertions(+), 21 deletions(-) create mode 100644 core/assets/sprites/player/player.png create mode 100644 core/src/com/saltosion/gladiator/components/CPosition.java diff --git a/core/assets/sprites/player/player.png b/core/assets/sprites/player/player.png new file mode 100644 index 0000000000000000000000000000000000000000..92e7518871c66e43300c2f6df0b24499fafed397 GIT binary patch literal 755 zcmVWFU8GbZ8()Nlj2>E@cM*00LJ@L_t(|+U=dOO2beT zhEFd=bSW+tiXD9diwL4lPNHw(;v@(~Tm&cI#lfkYI27rkK0={TA3)GzTug|U)SB4l zoSXmuA&`VF|2f}1IXO+6S`f_JsTFMk+pT6L z0+2W9apJSi!Bha>JVNsQ1gDQfj)&vQpRK?64HW{nh+v>4KjfIGH-VRDOUeGl^*dZs zsqNocF`spelzc7!oCAQ101yC*04OVNek?YD?N&2$%QHi;?B4_car0xf2^@~bKejX& z(-NI$E}-e3mw*B**$2U&1x%YBat;un;<^8{743uIpC}?>EujgN-2|U?ph=|DA9%iyF`7c}n=H2xk9$?>)X!&~A!nSGh(1 zr6c#0x^k=zwnRjv(|Lq}z?%P30oXnMNcLZzH{mLPMgOH;0?toYlKrcjH@WRSB*%mA zl~83__3t#y$4ZyJx@^NF-;#f)Wj-qiNXfV2-)Wjp2Vo+8xa3>#@3hUMu6!$UOg^@M zXU%-*)4-Bya8UhRc)hdAhV8m|^N>ou+{Hs-f?$J7QnYZGfzY72t0U!Vr0iXx~ zMF1!QK%uFo`O291KXLklPZ7Zz0bB6T3cyPMMF1!QKoJ0n08j*gA^;SQObmk3LK+HL l@Xrds3c$CAvj?DH^#zLEAfO>I9CiQz002ovPDHLkV1fxNK_&nI literal 0 HcmV?d00001 diff --git a/core/assets/sprites/staticplayer.png b/core/assets/sprites/staticplayer.png index 6e60cea04a00f1f3130208f567d505ae5b660ae1..b80908eccf70530b22bda7d9a148a98360396c31 100644 GIT binary patch delta 18 ZcmaFH`iyl#2)m%RMT{KV(T&mFOaMHy1{44Q delta 18 acmaFH`iyl#2s=Ly 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