Weapon Overlay Function - UQdeco2800/2022-studio-2 GitHub Wiki

Summary

This wiki page will explain the code implementation, which displays and animates Hera's Dagger and Level 3 Dagger on the player. To follow consistency, we collaborated with @TEAM08 to do an overlay effect, rather than our original plan of changing the whole graphic regarding adding elements to the player. This implementation has been inspired by the implementation of the skills team (team08) of the overlay effect. The thread for this collaboration can be found in Weapon Appearance On Hand - #111.

Key Binds

Hera's Dagger: Press 'SPACE' to display and play the attack animation of Hera's dagger. It will also give you the same functionality as Attack function, which is to deal damage to the closest enemy.

Level 3 Dagger: Press 'n' to display and play the attack animation of the level 3 dagger. Note this will not allow you to deal damage to the closest enemy. For a future consideration attack, damage and animation will be dependent on the equipped weapon.

attackAnimation and attackAnimation2

Located in: _source/core/src/main/com/deco2800/game/components/player/PlayerActions.java

AttackAnimation and attackAnimation2 is a new function created which triggers the displaying and playing of the attack animation.

Firstly, we defined the player input needed to trigger displaying and animating the combat item on the player. This is located in com/deco2800/game/components/player/KeyboardPlayerInputComponent.java

  1. Hera's Dagger

        case Keys.SPACE:
        entity.getEvents().trigger("attack");
        return true;
  1. Level 3 Dagger

        case Keys.N:
        entity.getEvents().trigger("attack2");
        return true;

The display animation listeners are created in create() which actively checks if the player has pressed the key binds.

  1. Hera's Dagger

       entity.getEvents().addListener("attack", this::attackAnimation);
  1. Level 3 Dagger


       entity.getEvents().addListener("attack2", this::attackAnimation2);

PlayerCombatAnimationContoller

Located in: _source/core/src/main/com/deco2800/game/components/player/PlayerCombatAnimationController.java

We created a new class that uses the event trigger to 'secure' either the level 3 dagger or Hera's dagger to overlay the player. The securement is done by the following line of code:

 public void update() {
        this.entity.setPosition(playerEntity.getPosition().x, playerEntity.getPosition().y);
    }

createCombatAnimator

Located in: _source/core/src/main/com/deco2800/game/entities/factories/PlayerFactory.java

We created a new function that takes the atlas file to create the animations of the items. The atlas file gives the properties of the animations that are linked to the sprite file that contains the png images of all the frames of the two combat items.

AnimationRenderComponent animator =
            new AnimationRenderComponent(
                    ServiceLocator.getResourceService().getAsset("images/CombatItems/animations/combatanimation.atlas", TextureAtlas.class));
    animator.addAnimation("noAnimation", 0.1f);
    animator.addAnimation("level3Dagger", 0.1f);
    animator.addAnimation("hera", 0.1f);

We then created a new entity of this animation that overlays it on the player entity.

    Entity combatAnimator =
            new Entity().addComponent(animator)
                    .addComponent(new PlayerCombatAnimationController(playerEntity));

    combatAnimator.getComponent(AnimationRenderComponent.class).scaleEntity();
    return combatAnimator;

#spawnPlayer() Located in: _source/core/src/main/com/deco2800/game/areas/ForestGameArea.java

We added these lines of code

  Entity newSkillAnimator = PlayerFactory.createSkillAnimator(newPlayer);
    Entity newCombatAnimator = PlayerFactory.createCombatAnimator(newPlayer);
    ...
    spawnEntityAt(newCombatAnimator, PLAYER_SPAWN, true, true);
    ...
    newPlayer.getComponent(PlayerActions.class).setCombatAnimator(newCombatAnimator);

into the spawnPlayer() function to spawn the overlay animation of the player into the game.

Back to Combat Items Contents Page

Author

  • Nisha Vashist, Caleb Ang
  • GitHub: @NishaVashist0, @PurrplePanda
  • Discord: nishavashist #4270, 🅰nneyeong Haseyo™#8083
  • Slack: Nisha Vashist, Caleb Ang