Channels now actually work.
For testing reasons, player is now also divided in torso and legs
This commit is contained in:
parent
f441b6c164
commit
b12816f9b0
Binary file not shown.
Before Width: | Height: | Size: 755 B After Width: | Height: | Size: 1.6 KiB |
@ -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(
|
||||
|
@ -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<String> sequences = spritesequences.keySet();
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user