diff --git a/bin/tfg/AnimatedSprite.class b/bin/tfg/AnimatedSprite.class index 16c2a12..7287744 100644 Binary files a/bin/tfg/AnimatedSprite.class and b/bin/tfg/AnimatedSprite.class differ diff --git a/bin/tfg/AnimationType.class b/bin/tfg/AnimationType.class new file mode 100644 index 0000000..eaed7b2 Binary files /dev/null and b/bin/tfg/AnimationType.class differ diff --git a/bin/tfg/Game.class b/bin/tfg/Game.class index d4c6755..afb1802 100644 Binary files a/bin/tfg/Game.class and b/bin/tfg/Game.class differ diff --git a/bin/tfg/Player.class b/bin/tfg/Player.class index bc06e22..7fe27f3 100644 Binary files a/bin/tfg/Player.class and b/bin/tfg/Player.class differ diff --git a/src/tfg/AnimatedSprite.java b/src/tfg/AnimatedSprite.java index d0fe7d2..a05794b 100644 --- a/src/tfg/AnimatedSprite.java +++ b/src/tfg/AnimatedSprite.java @@ -22,10 +22,7 @@ public class AnimatedSprite { * Keeps track of time between frame changes. */ private int frameCounter = 0; - /** - * Whether or not the sprite is currently animated. - */ - private boolean animating = false; + /** * The position at which the sprite is rendered. */ @@ -43,6 +40,11 @@ public class AnimatedSprite { */ private final Vector2i spriteSize = new Vector2i(32, 48); + /** + * The current animation to play. + */ + private AnimationType currentAnimationType = AnimationType.NONE; + /** * Create a new animated sprite. * @param s The sprite to animate. @@ -53,21 +55,14 @@ public class AnimatedSprite { entityLoc = l; } - /** - * Start the animation. - */ - public void startWalkingAnimation() { - startAnimation(); - } - /** * Update animation. */ public void animate() { - if(animating) { /* Then update animation. */ + if(currentAnimationType != AnimationType.NONE) { if(frameCounter >= animationSpeed) { /* If 15Hz has passed. */ stopAnimation(); - } else { + } else if(currentAnimationType == AnimationType.WALKING) { /* Get the position between old and new. */ spritePosition = entityLoc.interpolate(animationSpeed, frameCounter); Vector2i entityPos = entityLoc.getPosition(); /* Get the entity position. */ @@ -86,6 +81,17 @@ public class AnimatedSprite { } else if(change >= .75f && change <= 1.0f) { animationFrame = 3; } + } else if(currentAnimationType== AnimationType.STATIONARY_WALK) { + float steps = animationSpeed / 4; + if(frameCounter >= 0.f && frameCounter < steps) { + animationFrame = 0; + } else if(frameCounter >= steps && frameCounter < (2*steps)) { + animationFrame = 1; + } else if(frameCounter >= (2*steps)&&frameCounter<(3*steps)) { + animationFrame = 2; + } else if(frameCounter >= (3*steps)&&frameCounter<=(4*steps)) { + animationFrame = 3; + } } frameCounter++; /* Increment on each update to keep track of time. */ } @@ -96,7 +102,7 @@ public class AnimatedSprite { */ private void stopAnimation() { /* Reset the following. */ - animating = false; + currentAnimationType = AnimationType.NONE; frameCounter = 0; animationFrame = 0; } @@ -104,8 +110,8 @@ public class AnimatedSprite { /** * Start the animation. */ - private void startAnimation() { - animating = true; + public void startAnimation(AnimationType t) { + currentAnimationType = t; } /** @@ -113,7 +119,7 @@ public class AnimatedSprite { * @return If the animation finished. */ public boolean finishedAnimating() { - return !animating; + return currentAnimationType == AnimationType.NONE; } /** diff --git a/src/tfg/AnimationType.java b/src/tfg/AnimationType.java new file mode 100644 index 0000000..b963ccb --- /dev/null +++ b/src/tfg/AnimationType.java @@ -0,0 +1,7 @@ +package tfg; + +public enum AnimationType { + NONE, + WALKING, + STATIONARY_WALK +}; diff --git a/src/tfg/Game.java b/src/tfg/Game.java index 07c66f3..a7312ee 100644 --- a/src/tfg/Game.java +++ b/src/tfg/Game.java @@ -66,6 +66,7 @@ public class Game { windowTitle); player.changeMap(new Map(10, 10, Tile.SAND)); camera = new Camera(window); + // window.setFramerateLimit(60); } /** diff --git a/src/tfg/Player.java b/src/tfg/Player.java index 95856bd..6f18cd2 100644 --- a/src/tfg/Player.java +++ b/src/tfg/Player.java @@ -17,10 +17,6 @@ import java.nio.file.Paths; * @author Ritchie Cunningham */ public class Player extends Entity implements Drawable { - /** - * The players location. - */ - private Location playerLoc; /** * The texture for the sprite. */ @@ -104,9 +100,14 @@ public class Player extends Entity implements Drawable { entityLoc.setDirection(d); if(currentMap.isValidLocation(newLoc)) { currentAction = PlayerAction.MOVING; - entityLoc.setDirection(d); - playerSprite.startWalkingAnimation(); + playerSprite.startAnimation(AnimationType.WALKING); } else if(cannotMove.getStatus() == SoundSource.Status.STOPPED) { + /* + * Play the stationary walk animation. + * It appears like the player is trying to move, but can't. + */ + playerSprite.startAnimation(AnimationType.STATIONARY_WALK); + /* Play an annoying sound. */ cannotMove.play(); } } @@ -123,11 +124,11 @@ public class Player extends Entity implements Drawable { /* Actually move the location. */ entityLoc = entityLoc.getRelativeLocation(entityLoc.getDirection()); /* Update the sprite with new location. */ - playerSprite.updatePosition(entityLoc); - } else { - playerSprite.animate(); /* Proceed with the animation. */ + playerSprite.updatePosition(entityLoc); } } + /* Update the animation, if there is no current animation, ignore. */ + playerSprite.animate(); } /** diff --git a/src/tfg/Tile.java b/src/tfg/Tile.java index b77964a..05a14f0 100644 --- a/src/tfg/Tile.java +++ b/src/tfg/Tile.java @@ -20,7 +20,7 @@ public enum Tile { /** * Get the coords of a specific tile from the tile-set image. - * @param t The tole to get the coordinates of. + * @param t The tile to get the coordinates of. * @return Coords of the tile image in the tile-set. */ public static Vector2f getTextureCoords(Tile t) {