Player (and other NPC) invincibility frames - UQcsse3200/2024-studio-1 GitHub Wiki

Invincibility Frames

Description

After being hit, entities may have a window of time where they can't be hit again. The amount of time the player is invincible is indicated by the player's sprite flashing between being visible and invisible for the duration. This feature is intended for use with the player, as it prevents them from unfairly taking a large amount of damage in a short time frame. Due to the features implementation being through the 'CombatStatsComponent' that all NPCs use, this feature is available to enemies as well as the player. The current amount of invincibility is set to 2 seconds, although this is temporary and may be changed at the design committee's discretion.

Implementation

This feature was implemented by changing the 'CombatStatsComponent' and 'AnimationRenderComponent' classes.

CombatStatsComponent

Whenever the 'hit' method is called, the player state is set to invincible and a 'Timer' object is given the 'InvincibilityRemover' 'TimerTask' that sets the player back to vulnerable after 'timeInvincible' milliseconds. If the player is hit during this time, all effects of being hit are ignored. A second 'Timer' object is also given a 'FlashSprite' 'TimerTask' that activates every 0.25 seconds that changes the opacity of the entity in it's 'AnimationRenderComponent'. The state of the character can be get and set from the 'getIsInvincible' and 'setIsInvincible' methods and the amount of time invincible can be changed by editing the 'timeInvincible' constant in the class.

AnimationRenderComponent

The variable 'opacity' was added hold the alpha component of the sprite's colour so that it could be remotely changed through the 'setOpacity' method. The change in colour was achieved through editing the 'draw' method, where the colour of the 'spriteBatch' is changed before drawing

Example

Player IFrames 2

UML Diagram

Note only methods and attributes relevant to this feature are shown image

Sequence Diagram

Note only methods and attributes relevant to this feature are shown image