[Add] Entity class.
This commit is contained in:
parent
e150b70113
commit
7eb171b491
BIN
bin/tfg/Entity.class
Normal file
BIN
bin/tfg/Entity.class
Normal file
Binary file not shown.
Binary file not shown.
27
src/tfg/Entity.java
Normal file
27
src/tfg/Entity.java
Normal file
@ -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;
|
||||
}
|
||||
}
|
@ -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. */
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user