From b12816f9b05523ef28c56b2be92c1a933912ab1b Mon Sep 17 00:00:00 2001 From: Allexit Date: Thu, 14 May 2015 23:54:33 +0300 Subject: [PATCH] Channels now actually work. For testing reasons, player is now also divided in torso and legs --- core/assets/sprites/player/player.png | Bin 755 -> 1595 bytes .../saltosion/gladiator/GladiatorBrawler.java | 34 ++++++++++++------ .../gladiator/components/CRenderedObject.java | 9 +++++ .../gladiator/systems/CombatSystem.java | 4 +-- .../gladiator/systems/RenderingSystem.java | 4 +-- 5 files changed, 37 insertions(+), 14 deletions(-) diff --git a/core/assets/sprites/player/player.png b/core/assets/sprites/player/player.png index 92e7518871c66e43300c2f6df0b24499fafed397..a5a1c909a466fc6a6a5db3ace2b3b8f792fb13a4 100644 GIT binary patch literal 1595 zcmcJPdrVVT9LLWsg6`i(jpou0`pcxtgKK>E$Wt0Gb*513RE5<?HS`@BN)~?!CYB z{oLO%L0AZd%pd~*D7-D3wgCX)5@=x?ynn;JCBO$;*_NHj0N6QME(jE#UxWuqavndJ z)Mrhd@8iC#et?OGoa2N$C>FY(zlRSvD)W+&rV8r^xjj?@6ReW!2AX}`_-X2zcnSinR^l1ASg@QQ)_ra?ml+N0H>kp$OxB!$dri+?hO`gY z@(Erj+S)hmXW3@iFDSY&m~`3TNMsha<{Im8@!D!3nKHc<-1MC0LwYwp-@Y11Do&F`eLs{cG{Hy_)d34;6*#Y}?8P=UWYQPL~HJ!VmCo3qFX)?MILk z!Mv5j`^~wUKD&pfU9W?~yQ-<#M~Szkr!Y5c52?v{ zBtTrP_YjdI8Ro_ZT(C~|vwCV>xnT32 z^cvaNpMXJUjqZe^X=E+8AG;c$DR96mY>&>h6nPcOk!L3(5ROvh~lNWO%n|!v(6ZJ@w7Cs8q(6lUxXURO0qHwlm~AW#jGRY zYurXMPSXoQb*5mDGTM%&-~I05|BdZx@;|VZcq#%p@$P0#AMr*SbwralZ-BAbv#~5j zdqG9CMqe9s>81IOG;oPwto(6Oxd4Jtx?{!8K{a0(^R|2KL81!4aTChjXB#3;(1Gy9 zQ`6*cm166UW#J>70=Ju1PNEEdS%#OaJQTfbf#9?HQc+-+4Obd6pk0qxl#T^ny{D6rAs-0@2oWnLrV%@)kx46m0#`{yK~#9!?VYho!%!54PcKDuDJ~X@ z9eo0e2%=6-qHp5jBnU-Z1Sj9c!Ks@#6zQTqLZMI}K+s}bOo*4%n%L%?oB#hIkc2M( zIo~}wIZc~d6h)CxuyPCm0iXx~g{nG3kWcMaGua=G#=-lk6>S3Bt!5aZ;JVNsQ1gDQfj)&vQpRK?64HW{nh+v>4KjfIGH-VRDOUeGl^*dZssqNocF`spe zlzc7!oCAQ101yC*04OVNek?YD?N&2$%QHi;?B4_car0xf2^@~bKejX&(-NI$E}-e3 zmw*B**$2U&1x%YBat;un;<^8{743t6;GZV|6@g$LpJ5Y75dew+%)A{!73^&wldtDr zr3pOQX^4o(+8$=IE%`580p{KH9v)!dkZAdLTJ)nrV9kH20PJrxpjWv?|D_}Ml)7@P z4z@%@q|{QeSCaj!n>V@bJtW72@0C!0Wm)y_ zG|b0Jm%h4e!zAC5f2U|#3ei<493;xwAfd62`Zx2dwR8dy^t5tyR(K>XQx8k3_3jh}ZAOI8rpa=j(04M@L zp{b_%%9!{+ar%Q#5y2Y)Tky{cz)Ju{04M@L5dew+Py~P?02Gc)41&@^8VXtP&kDc_ gz_*992cTf}1&ZAupdm0Eb^rhX07*qoM6N<$f~C?nxBvhE diff --git a/core/src/com/saltosion/gladiator/GladiatorBrawler.java b/core/src/com/saltosion/gladiator/GladiatorBrawler.java index fcd8208..39b06bc 100644 --- a/core/src/com/saltosion/gladiator/GladiatorBrawler.java +++ b/core/src/com/saltosion/gladiator/GladiatorBrawler.java @@ -109,11 +109,18 @@ public class GladiatorBrawler extends ApplicationAdapter { player = new Entity(); CRenderedObject renderedObject = new CRenderedObject(); - Sprite player1 = SpriteLoader.loadSprite(Name.PLAYERIMG, 0, 0, 64, 64); - Sprite player2 = SpriteLoader.loadSprite(Name.PLAYERIMG, 1, 0, 64, 64); - SpriteSequence sequence = new SpriteSequence(1).addSprite(player1).addSprite(player2); - renderedObject.addSequence("Idle", sequence); - renderedObject.playAnimation("Idle"); + Sprite playertorso1 = SpriteLoader.loadSprite(Name.PLAYERIMG, 0, 0, 128, 112); + Sprite playertorso2 = SpriteLoader.loadSprite(Name.PLAYERIMG, 0, 1, 128, 112); + Sprite playerlegs1 = SpriteLoader.loadSprite(Name.PLAYERIMG, 1, 0, 128, 112); + Sprite playerlegs2 = SpriteLoader.loadSprite(Name.PLAYERIMG, 1, 1, 128, 112); + SpriteSequence torsosequence = new SpriteSequence(1).addSprite(playertorso1).addSprite(playertorso2); + SpriteSequence legsequence = new SpriteSequence(1).addSprite(playerlegs1).addSprite(playerlegs2); + renderedObject.setChannelName("default", "torso"); + renderedObject.addChannel("legs"); + renderedObject.addSequence("Torso-Idle", torsosequence); + renderedObject.addSequence("Legs-Idle", legsequence); + renderedObject.playAnimation("torso", "Torso-Idle"); + renderedObject.playAnimation("legs", "Legs-Idle"); player.add(renderedObject); player.add(new CPhysics().setSize(2, 4).setPosition(0, 5)); player.add(new CCombat().setBaseDamage(100).setHealth(1000)); @@ -125,11 +132,18 @@ public class GladiatorBrawler extends ApplicationAdapter { public void initializeTestDummy() { Entity dummy = new Entity(); CRenderedObject renderedObject = new CRenderedObject(); - Sprite player1 = SpriteLoader.loadSprite(Name.PLAYERIMG, 0, 0, 64, 64); - Sprite player2 = SpriteLoader.loadSprite(Name.PLAYERIMG, 1, 0, 64, 64); - SpriteSequence sequence = new SpriteSequence(1).addSprite(player1).addSprite(player2); - renderedObject.addSequence("Idle", sequence); - renderedObject.playAnimation("Idle"); + Sprite playertorso1 = SpriteLoader.loadSprite(Name.PLAYERIMG, 0, 0, 128, 112); + Sprite playertorso2 = SpriteLoader.loadSprite(Name.PLAYERIMG, 0, 1, 128, 112); + Sprite playerlegs1 = SpriteLoader.loadSprite(Name.PLAYERIMG, 1, 0, 128, 112); + Sprite playerlegs2 = SpriteLoader.loadSprite(Name.PLAYERIMG, 1, 1, 128, 112); + SpriteSequence torsosequence = new SpriteSequence(1).addSprite(playertorso1).addSprite(playertorso2); + SpriteSequence legsequence = new SpriteSequence(1).addSprite(playerlegs1).addSprite(playerlegs2); + renderedObject.setChannelName("default", "torso"); + renderedObject.addChannel("legs"); + renderedObject.addSequence("Torso-Idle", torsosequence); + renderedObject.addSequence("Legs-Idle", legsequence); + renderedObject.playAnimation("torso", "Torso-Idle"); + renderedObject.playAnimation("legs", "Legs-Idle"); dummy.add(renderedObject); dummy.add(new CPhysics().setSize(2, 4).setPosition(-6, 5)); dummy.add(new CCombat().setBaseDamage(100).setHealth(1000).setSwingCD(.5f).setCombatListener( diff --git a/core/src/com/saltosion/gladiator/components/CRenderedObject.java b/core/src/com/saltosion/gladiator/components/CRenderedObject.java index 8d79248..36f4b8d 100644 --- a/core/src/com/saltosion/gladiator/components/CRenderedObject.java +++ b/core/src/com/saltosion/gladiator/components/CRenderedObject.java @@ -102,6 +102,15 @@ public class CRenderedObject extends Component { public void playAnimation(String key, int startingframe) { playAnimation("default", key, startingframe); } + + /** + * Plays animation on "channelName" starting on frame 0 + * @param channelName channel name + * @param key animation name + */ + public void playAnimation(String channelName, String key) { + playAnimation(channelName, key, 0); + } public void addChannel(String channelName) { Set sequences = spritesequences.keySet(); diff --git a/core/src/com/saltosion/gladiator/systems/CombatSystem.java b/core/src/com/saltosion/gladiator/systems/CombatSystem.java index 2cb3493..917e0f7 100644 --- a/core/src/com/saltosion/gladiator/systems/CombatSystem.java +++ b/core/src/com/saltosion/gladiator/systems/CombatSystem.java @@ -62,9 +62,9 @@ public class CombatSystem extends EntitySystem { } else if (combat.getSwingDirection() == Direction.RIGHT) { pos.add(combat.getSwingSize().x/2, 0); } else if (combat.getSwingDirection() == Direction.UP) { - pos.add(0, combat.getSwingSize().y); + pos.add(0, combat.getSwingSize().y/3*2); } else if (combat.getSwingDirection() == Direction.DOWN) { - pos.add(0, -combat.getSwingSize().y/3*2); + pos.add(0, -combat.getSwingSize().y/3*2); } createSwingHitbox(e, pos); diff --git a/core/src/com/saltosion/gladiator/systems/RenderingSystem.java b/core/src/com/saltosion/gladiator/systems/RenderingSystem.java index 586f61c..51ca7bb 100644 --- a/core/src/com/saltosion/gladiator/systems/RenderingSystem.java +++ b/core/src/com/saltosion/gladiator/systems/RenderingSystem.java @@ -113,8 +113,8 @@ public class RenderingSystem extends EntitySystem { physics.getPosition().y - spriteHeight / 2); currSprite.draw(batch); - float nextFrame = renderedObject.getCurrentFrame() + deltaTime * currSequence.getPlayspeed(); - renderedObject.setCurrentFrame(nextFrame % currSequence.frameCount()); + float nextFrame = renderedObject.getCurrentFrame(channel) + deltaTime * currSequence.getPlayspeed(); + renderedObject.setCurrentFrame(channel, nextFrame % currSequence.frameCount()); } } batch.end();