Potions Code Logic - UQdeco2800/2022-studio-2 GitHub Wiki

PotionFactory

PotionFactory class creates potion entities: source\core\src\main\com\deco2800\game\entities\factories\PotionFactory.java

Different types of potions will be created with different create() methods for each potion type. For sprint 1, only createSpeedPotion() has been implemented.

The speed potion was made by creating an entity with the following components: image

PotionEffectComponent

PotionEffectComponent affects the player on collision with a potion: source\core\src\main\com\deco2800\game\components\player\PotionEffectComponent.java

image

Different effectTypes will be made into an enum in later developments. Currently, only one case for effectType, "speed", has been implemented, to increase the players speed by 50%.

The create() method is used to create the component attached to potion entities. This method uses a hitboxComponent to register the collision between the potion and player. The onCollisionStart() method is used to apply the effect when the player and potion collide. image image

The applyEffect() method will be used to apply the relevant effect onto the player entity. In further developments, this method will also use the effectType enum. The applyEffect method makes use of the playerModifer class defined by the player team. It first checks that there is not an already existing modifier with the same parameters before creating a modifier. For the effectType "speed", the playerModifier is used to increases the player's movement speed by the effectValue previously defined (0.50) for 1 minute.

image

Back to Potions Page