Package de.tum.cit.fop.maze.objects
Class Player
java.lang.Object
de.tum.cit.fop.maze.objects.GameObject
de.tum.cit.fop.maze.objects.Player
- All Implemented Interfaces:
Saveable<PlayerMemento>
Main player character with health, abilities, inventory, and effects management.
-
Field Summary
Fields inherited from class de.tum.cit.fop.maze.objects.GameObject
bounds, currentAnimationType, drawable, position, sizes, speed, speedMultiplier, spriteSizes, texture, velocity -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddOrReapplyEffect(Effect effect) Adds or refreshes an effect on the player.voidanimate(com.badlogic.gdx.graphics.g2d.Batch batch) Renders the object using its drawable or texture.voidchangeAnimation(AnimationType animationType) Changes the current animation.voidCollects a key and updates inventory.voiddie()Handles player death sound.voidEnds a specific effect type on the player.Gets achievement UI.intGets current health value.intGets current number of keys collected.intgetDamageOrHeal(int damage) Applies damage or healing to the player.floatgetEffectDuration(Class<? extends Effect> effectType) Gets remaining duration of an active effect.intgetKills()Gets number of kills.intGets maximum health value.Creates a memento capturing the current state of this object.Gets the player as a GameObject.intGets number of keys required.Gets the sound controller.intgetXp()Gets player XP.booleanChecks if player has a specific effect active.booleanhasKeys()Checks if player has all required keys.intincreaseMaxHealth(int extraHealth) Increases player's maximum and current health.booleanChecks if player is currently attacking.booleanChecks if player can use dash ability.booleanChecks if player can use invisibility ability.voidloadFromMemento(PlayerMemento memento) Restores the object's state from a memento.intreceiveXP(int xpReceived) Adds experience points to the player.voidsetAttacking(boolean attacking) Sets attacking state.voidsetCanDash(boolean canDash) Sets dash ability availability.voidsetCanInvis(boolean canInvis) Sets invisibility ability availability.voidsetCurrentHealth(int currentHealth) Sets current health value.voidsetCurrentKeys(int keys) Sets current number of keys.voidsetHasKeys(boolean hasKey) Sets whether player has all keys.voidsetKills(int kills) Sets number of kills.voidsetMaxHealth(int maxHealth) Sets maximum health value.voidsetPosition(com.badlogic.gdx.math.Vector2 pos) Sets player position.voidsetRequiredKeys(int requiredKeys) Sets number of keys required.voidsetXp(int xp) Sets player XP.voidtickEffects(float deltaTime) Updates all active effects on the player.voidUpdates required keys from current game field.Methods inherited from class de.tum.cit.fop.maze.objects.GameObject
entitiesOverlap, getBounds, getDrawable, getSize, getSpeed, getVelocity, increaseSpeed, move, multiplySpeed, nextPosition, setAnimationTime, updateAnimation
-
Constructor Details
-
Player
-
-
Method Details
-
receiveXP
public int receiveXP(int xpReceived) Adds experience points to the player.- Parameters:
xpReceived- Amount of XP to add- Returns:
- New total XP
-
getDamageOrHeal
public int getDamageOrHeal(int damage) Applies damage or healing to the player.- Parameters:
damage- Positive for damage, negative for healing- Returns:
- New health value
-
increaseMaxHealth
public int increaseMaxHealth(int extraHealth) Increases player's maximum and current health.- Parameters:
extraHealth- Amount of health to add- Returns:
- New maximum health
-
animate
public void animate(com.badlogic.gdx.graphics.g2d.Batch batch) Description copied from class:GameObjectRenders the object using its drawable or texture.- Overrides:
animatein classGameObject- Parameters:
batch- Sprite batch for rendering
-
endEffect
Ends a specific effect type on the player.- Parameters:
effectTypeClass- The effect class to remove
-
addOrReapplyEffect
Adds or refreshes an effect on the player.- Parameters:
effect- The effect to apply
-
tickEffects
public void tickEffects(float deltaTime) Updates all active effects on the player.- Parameters:
deltaTime- Time since last tick
-
changeAnimation
Description copied from class:GameObjectChanges the current animation.- Overrides:
changeAnimationin classGameObject- Parameters:
animationType- New animation type
-
getCurrentHealth
public int getCurrentHealth()Gets current health value.- Returns:
- Current health
-
setCurrentHealth
public void setCurrentHealth(int currentHealth) Sets current health value.- Parameters:
currentHealth- New health value
-
getMaxHealth
public int getMaxHealth()Gets maximum health value.- Returns:
- Maximum health
-
setMaxHealth
public void setMaxHealth(int maxHealth) Sets maximum health value.- Parameters:
maxHealth- New maximum health
-
getEffectDuration
Gets remaining duration of an active effect.- Parameters:
effectType- The effect class to check- Returns:
- Time remaining, or 0 if not active
-
hasEffect
Checks if player has a specific effect active.- Parameters:
effectType- The effect class to check- Returns:
- True if effect is active
-
getPlayerGameObject
Gets the player as a GameObject.- Returns:
- This player instance
-
collectKey
public void collectKey()Collects a key and updates inventory. -
isAttacking
public boolean isAttacking()Checks if player is currently attacking.- Returns:
- True if attacking
-
setAttacking
public void setAttacking(boolean attacking) Sets attacking state.- Parameters:
attacking- New attacking state
-
die
public void die()Handles player death sound. -
hasKeys
public boolean hasKeys()Checks if player has all required keys.- Returns:
- True if has all keys
-
getXp
public int getXp()Gets player XP.- Returns:
- Current XP
-
setXp
public void setXp(int xp) Sets player XP.- Parameters:
xp- New XP value
-
isCanDash
public boolean isCanDash()Checks if player can use dash ability.- Returns:
- True if dash is unlocked
-
setCanDash
public void setCanDash(boolean canDash) Sets dash ability availability.- Parameters:
canDash- New dash availability
-
isCanInvis
public boolean isCanInvis()Checks if player can use invisibility ability.- Returns:
- True if invis is unlocked
-
setCanInvis
public void setCanInvis(boolean canInvis) Sets invisibility ability availability.- Parameters:
canInvis- New invis availability
-
getSoundController
Gets the sound controller.- Returns:
- Sound controller instance
-
setHasKeys
public void setHasKeys(boolean hasKey) Sets whether player has all keys.- Parameters:
hasKey- New key status
-
getCurrentKeys
public int getCurrentKeys()Gets current number of keys collected.- Returns:
- Number of keys
-
setCurrentKeys
public void setCurrentKeys(int keys) Sets current number of keys.- Parameters:
keys- New key count
-
getRequiredKeys
public int getRequiredKeys()Gets number of keys required.- Returns:
- Required key count
-
setRequiredKeys
public void setRequiredKeys(int requiredKeys) Sets number of keys required.- Parameters:
requiredKeys- New required count
-
setPosition
public void setPosition(com.badlogic.gdx.math.Vector2 pos) Sets player position.- Parameters:
pos- New position vector
-
getAchievementUI
Gets achievement UI.- Returns:
- Achievement UI instance
-
getKills
public int getKills()Gets number of kills.- Returns:
- Kill count
-
setKills
public void setKills(int kills) Sets number of kills.- Parameters:
kills- New kill count
-
updateRequiredKeys
public void updateRequiredKeys()Updates required keys from current game field. -
getMemento
Description copied from interface:SaveableCreates a memento capturing the current state of this object.- Specified by:
getMementoin interfaceSaveable<PlayerMemento>- Returns:
- A memento containing the object's state
-
loadFromMemento
Description copied from interface:SaveableRestores the object's state from a memento.- Specified by:
loadFromMementoin interfaceSaveable<PlayerMemento>- Parameters:
memento- The memento containing the state to restore
-