Class Entity<S extends Observable<S>>
java.lang.Object
nz.ac.vuw.ecs.swen225.gp22.domain.Observable<S>
nz.ac.vuw.ecs.swen225.gp22.domain.Entity<S>
- Direct Known Subclasses:
EnemyEntity,Player
Template for entities in a level, including the player.
Any entities are observable.
- Author:
- Abdul
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordA record used to store an action taken.static enumEnum with values for each direction, which each have a point representing the change in position. -
Field Summary
FieldsModifier and TypeFieldDescriptionThe action which the entity has taken, used for recorder. -
Constructor Summary
ConstructorsConstructorDescriptionEntity(Maze.Point entityPos, Entity.Direction facingDir) Default constructor, sets the position and direction of the entity. -
Method Summary
Modifier and TypeMethodDescriptionvoidCalled when an entity is removed.getDir()getPos()booleanintid()voidmove()Overloaded method for move(), assumes the chosen direction is the direction the entity is facing.voidmove(int moveX, int moveY) Overloaded method for move(), that accepts two individual numbers that represent X and Y, respectively.voidmove(Entity.Direction direction) Moves the entity in a given direction.voidmove(Maze.Point moveVector) Overloaded method for move(), takes in a point.voidCombines methods setDir() and move().abstract voidping()Non-player entities will act based on how often this is called.voidsetDir(Entity.Direction dir) Sets the direction the entity is facing.voidsetPos(Maze.Point pos) Sets the position of the entity.abstract voidunping()Undoes the effects of ping().Methods inherited from class nz.ac.vuw.ecs.swen225.gp22.domain.Observable
addObserver, removeObserver, updateObservers
-
Field Details
-
action
The action which the entity has taken, used for recorder.
-
-
Constructor Details
-
Entity
Default constructor, sets the position and direction of the entity.- Parameters:
entityPos- Point to set the position field to.facingDir- Direction to set the direction field to.
-
-
Method Details
-
ping
public abstract void ping()Non-player entities will act based on how often this is called. -
unping
public abstract void unping()Undoes the effects of ping(). -
hasAction
public boolean hasAction()- Returns:
- Whether or not this entity has done an action since the last call of getChangeMap().
-
pollAction
- Returns:
- The current action and set the field to null.
-
move
Moves the entity in a given direction.- Parameters:
direction- Direction to move the entity in.
-
move
Overloaded method for move(), takes in a point.- Parameters:
moveVector- Amount to move by.
-
move
public void move(int moveX, int moveY) Overloaded method for move(), that accepts two individual numbers that represent X and Y, respectively.- Parameters:
moveX- The amount to change X by.moveY- The amount to change Y by.
-
move
public void move()Overloaded method for move(), assumes the chosen direction is the direction the entity is facing. -
moveAndTurn
Combines methods setDir() and move().- Parameters:
dir- The new direction of the entity.
-
getPos
- Returns:
- The position of the entity.
-
getDir
- Returns:
- The direction the entity is facing.
-
id
public int id()- Returns:
- The ID of the entity.
-
setPos
Sets the position of the entity.- Parameters:
pos- Point that represents the entity's new position.
-
setDir
Sets the direction the entity is facing.- Parameters:
dir- The new direction of the entity.
-
deleteEntity
public void deleteEntity()Called when an entity is removed. This method is not abstract because not all entities will need special code to run on deletion.
-