diff --git a/bin/tfg/Entity.class b/bin/tfg/Entity.class new file mode 100644 index 0000000..3934c27 Binary files /dev/null and b/bin/tfg/Entity.class differ diff --git a/bin/tfg/Player.class b/bin/tfg/Player.class index 2fd159f..47c0638 100644 Binary files a/bin/tfg/Player.class and b/bin/tfg/Player.class differ diff --git a/src/tfg/Entity.java b/src/tfg/Entity.java new file mode 100644 index 0000000..b457b36 --- /dev/null +++ b/src/tfg/Entity.java @@ -0,0 +1,27 @@ +package tfg; + +/** + * The base class for all players, NPCs, Monsters, items etc. + */ +public class Entity { + /** + * The entity location. + */ + protected Location entityLoc; + + /** + * Get the entity location. + * @return Entity location. + */ + public Location getLocation() { + return entityLoc; + } + + /** + * Set the entity location. + * @param l New location. + */ + public void setLocation(Location l) { + entityLoc = l; + } +} diff --git a/src/tfg/Player.java b/src/tfg/Player.java index 6aff622..7b8ae73 100644 --- a/src/tfg/Player.java +++ b/src/tfg/Player.java @@ -16,7 +16,7 @@ import java.nio.file.Paths; * Holds everything that pertains to the player (you?). * @author Ritchie Cunningham */ -public class Player implements Drawable { +public class Player extends Entity implements Drawable { /** * The players location. */ @@ -52,7 +52,7 @@ public class Player implements Drawable { * @param y Starting y pos. */ public Player(int x, int y) { - playerLoc = new Location(x, y); + entityLoc = new Location(x, y); /* Load sprite texture and 'stuck' sound. */ try { playerSpritesheetTexture.loadFromFile(Paths.get("res/player.png")); @@ -63,7 +63,7 @@ public class Player implements Drawable { Sprite sprite = new Sprite(); /* Create a new regular sprite. */ sprite.setTexture(playerSpritesheetTexture); /* Create a new animated sprite from the regular sprite. */ - playerSprite = new AnimatedSprite(sprite, playerLoc); + playerSprite = new AnimatedSprite(sprite, entityLoc); cannotMove.setBuffer(cannotMoveBuffer); } @@ -100,11 +100,11 @@ public class Player implements Drawable { * Get the location relative to the current location. * e.g. NORTH would return the location above the current location. */ - Location newLoc = playerLoc.getRelativeLocation(d); + Location newLoc = entityLoc.getRelativeLocation(d); playerLoc.setDirection(d); if(currentMap.isValidLocation(newLoc)) { currentAction = PlayerAction.MOVING; - playerLoc.setDirection(d); + entityLoc.setDirection(d); playerSprite.startWalkingAnimation(); } else if(cannotMove.getStatus() == SoundSource.Status.STOPPED) { cannotMove.play(); @@ -121,9 +121,9 @@ public class Player implements Drawable { if(playerSprite.finishedAnimating()) { currentAction = PlayerAction.NONE; /* Actually move the location. */ - playerLoc = playerLoc.getRelativeLocation(playerLoc.getDirection()); + entityLoc = entityLoc.getRelativeLocation(entityLoc.getDirection()); /* Update the sprite with new location. */ - playerSprite.updatePosition(playerLoc); + playerSprite.updatePosition(entityLoc); } else { playerSprite.animate(); /* Proceed with the animation. */ }