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();
|
player = new Entity();
|
||||||
|
|
||||||
CRenderedObject renderedObject = new CRenderedObject();
|
CRenderedObject renderedObject = new CRenderedObject();
|
||||||
Sprite player1 = SpriteLoader.loadSprite(Name.PLAYERIMG, 0, 0, 64, 64);
|
Sprite playertorso1 = SpriteLoader.loadSprite(Name.PLAYERIMG, 0, 0, 128, 112);
|
||||||
Sprite player2 = SpriteLoader.loadSprite(Name.PLAYERIMG, 1, 0, 64, 64);
|
Sprite playertorso2 = SpriteLoader.loadSprite(Name.PLAYERIMG, 0, 1, 128, 112);
|
||||||
SpriteSequence sequence = new SpriteSequence(1).addSprite(player1).addSprite(player2);
|
Sprite playerlegs1 = SpriteLoader.loadSprite(Name.PLAYERIMG, 1, 0, 128, 112);
|
||||||
renderedObject.addSequence("Idle", sequence);
|
Sprite playerlegs2 = SpriteLoader.loadSprite(Name.PLAYERIMG, 1, 1, 128, 112);
|
||||||
renderedObject.playAnimation("Idle");
|
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(renderedObject);
|
||||||
player.add(new CPhysics().setSize(2, 4).setPosition(0, 5));
|
player.add(new CPhysics().setSize(2, 4).setPosition(0, 5));
|
||||||
player.add(new CCombat().setBaseDamage(100).setHealth(1000));
|
player.add(new CCombat().setBaseDamage(100).setHealth(1000));
|
||||||
@ -125,11 +132,18 @@ public class GladiatorBrawler extends ApplicationAdapter {
|
|||||||
public void initializeTestDummy() {
|
public void initializeTestDummy() {
|
||||||
Entity dummy = new Entity();
|
Entity dummy = new Entity();
|
||||||
CRenderedObject renderedObject = new CRenderedObject();
|
CRenderedObject renderedObject = new CRenderedObject();
|
||||||
Sprite player1 = SpriteLoader.loadSprite(Name.PLAYERIMG, 0, 0, 64, 64);
|
Sprite playertorso1 = SpriteLoader.loadSprite(Name.PLAYERIMG, 0, 0, 128, 112);
|
||||||
Sprite player2 = SpriteLoader.loadSprite(Name.PLAYERIMG, 1, 0, 64, 64);
|
Sprite playertorso2 = SpriteLoader.loadSprite(Name.PLAYERIMG, 0, 1, 128, 112);
|
||||||
SpriteSequence sequence = new SpriteSequence(1).addSprite(player1).addSprite(player2);
|
Sprite playerlegs1 = SpriteLoader.loadSprite(Name.PLAYERIMG, 1, 0, 128, 112);
|
||||||
renderedObject.addSequence("Idle", sequence);
|
Sprite playerlegs2 = SpriteLoader.loadSprite(Name.PLAYERIMG, 1, 1, 128, 112);
|
||||||
renderedObject.playAnimation("Idle");
|
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(renderedObject);
|
||||||
dummy.add(new CPhysics().setSize(2, 4).setPosition(-6, 5));
|
dummy.add(new CPhysics().setSize(2, 4).setPosition(-6, 5));
|
||||||
dummy.add(new CCombat().setBaseDamage(100).setHealth(1000).setSwingCD(.5f).setCombatListener(
|
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) {
|
public void playAnimation(String key, int startingframe) {
|
||||||
playAnimation("default", key, 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) {
|
public void addChannel(String channelName) {
|
||||||
Set<String> sequences = spritesequences.keySet();
|
Set<String> sequences = spritesequences.keySet();
|
||||||
|
@ -62,9 +62,9 @@ public class CombatSystem extends EntitySystem {
|
|||||||
} else if (combat.getSwingDirection() == Direction.RIGHT) {
|
} else if (combat.getSwingDirection() == Direction.RIGHT) {
|
||||||
pos.add(combat.getSwingSize().x/2, 0);
|
pos.add(combat.getSwingSize().x/2, 0);
|
||||||
} else if (combat.getSwingDirection() == Direction.UP) {
|
} 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) {
|
} 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);
|
createSwingHitbox(e, pos);
|
||||||
|
|
||||||
|
@ -113,8 +113,8 @@ public class RenderingSystem extends EntitySystem {
|
|||||||
physics.getPosition().y - spriteHeight / 2);
|
physics.getPosition().y - spriteHeight / 2);
|
||||||
currSprite.draw(batch);
|
currSprite.draw(batch);
|
||||||
|
|
||||||
float nextFrame = renderedObject.getCurrentFrame() + deltaTime * currSequence.getPlayspeed();
|
float nextFrame = renderedObject.getCurrentFrame(channel) + deltaTime * currSequence.getPlayspeed();
|
||||||
renderedObject.setCurrentFrame(nextFrame % currSequence.frameCount());
|
renderedObject.setCurrentFrame(channel, nextFrame % currSequence.frameCount());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
batch.end();
|
batch.end();
|
||||||
|
Loading…
Reference in New Issue
Block a user