Sprint 4: Main Player Character - UQdeco2800/2021-ext-studio-2 GitHub Wiki
Contents
- Refining the Main Player Character
 - Integration of new animations
 - Refactoring the PlayerAnimationController
 - Texture Atlases
 - Testing
 - UML Diagrams
 - Relevant Files
 
Refining the Main Player Character
Fixing the Main Player Character Size
We have fixed the MPC size according to the size of the game area, type and positioning of enemies and obstacles.
        PhysicsUtils.setScaledCollider(player, 0.6f, 0.3f);
        player.getComponent(TextureRenderComponent.class).scaleEntity();
        player.setScale(2.5f,2.5f);
        player.getComponent(ColliderComponent.class).setDensity(1.5f);
        return player;
Making walking the default starting MPC behaviour
The default starting movement of the MPC is move walking instead of standing still at the start of the game.
public void create() {
        loadAssets();
       ...
        MPCConfig.updateValues();
        player = spawnPlayer();
        player.getEvents().trigger("startMPCAnimation");
        ...
    }
Integration of new animations for the new map
Adding the new hurt and burn animations on the new map, to the PlayerFactory
/* Burning animation with buffs */
        mpcAnimator.addAnimation("main_player_burn_dizzy", 0.1f, Animation.PlayMode.LOOP);
        mpcAnimator.addAnimation("main_player_burn_health-down", 0.1f, Animation.PlayMode.LOOP);
        mpcAnimator.addAnimation("main_player_burn_health-limit-up", 0.1f, Animation.PlayMode.LOOP);
        mpcAnimator.addAnimation("main_player_burn_health-up", 0.1f, Animation.PlayMode.LOOP);
        mpcAnimator.addAnimation("main_player_burn_hungry", 0.1f, Animation.PlayMode.LOOP);
        mpcAnimator.addAnimation("main_player_burn_poisoned", 0.1f, Animation.PlayMode.LOOP);
        mpcAnimator.addAnimation("main_player_burn_recovered", 0.1f, Animation.PlayMode.LOOP);
        mpcAnimator.addAnimation("main_player_burn_speed-down", 0.1f, Animation.PlayMode.LOOP);
        mpcAnimator.addAnimation("main_player_burn_thirsty", 0.1f, Animation.PlayMode.LOOP);
        /* Hurt animation with buffs */
        mpcAnimator.addAnimation("main_player_hurt_dizzy", 0.1f, Animation.PlayMode.LOOP);
        mpcAnimator.addAnimation("main_player_hurt_health-down", 0.1f, Animation.PlayMode.LOOP);
        mpcAnimator.addAnimation("main_player_hurt_health-limit-up", 0.1f, Animation.PlayMode.LOOP);
        mpcAnimator.addAnimation("main_player_hurt_health-up", 0.1f, Animation.PlayMode.LOOP);
        mpcAnimator.addAnimation("main_player_hurt_hungry", 0.1f, Animation.PlayMode.LOOP);
        mpcAnimator.addAnimation("main_player_hurt_poisoned", 0.1f, Animation.PlayMode.LOOP);
        mpcAnimator.addAnimation("main_player_hurt_recovered", 0.1f, Animation.PlayMode.LOOP);
        mpcAnimator.addAnimation("main_player_hurt_speed-down", 0.1f, Animation.PlayMode.LOOP);
        mpcAnimator.addAnimation("main_player_hurt_thirsty", 0.1f, Animation.PlayMode.LOOP);
Method to handle the burning animations in the new map
/**
     * When the monitored event is triggered, play the mpc burning animation.
     */
  void magmaCollision(Fixture me, Fixture other) {
      if (hitboxComponent.getFixture() != me) {
          // Not triggered by hitbox, ignore
          return;
      }
      if (!PhysicsLayer.contains(PhysicsLayer.PLAYER, other.getFilterData().categoryBits) && !PhysicsLayer.contains(PhysicsLayer.WEAPON, other.getFilterData().categoryBits)) {
          // Doesn't match our target layer, ignore
          return;
      }
        entity.getEvents().trigger("burn");
      if (count == 0) { // Avoid an entity from repeatedly triggering an attack
          count++;
          logger.debug(COLLISION_LOGGER_INFO, entity.toString());
          this.entity.getEvents().trigger("burn");
          if (PhysicsLayer.contains(PhysicsLayer.WEAPON, other.getFilterData().categoryBits)) {
              this.entity.setRemoveCollision();
          }
      }
    }
Refactoring the PlayerAnimationController
Refactored the code from using switch statements to dynamically concatenating the current running animation and the required buff animation.

...
 /**
     *  Activate the hungry animation debuff
     */
    private void animateHungry() {
        animationName = animator.getCurrentAnimation();
        preAnimationCleanUp();
        if(animationName != null) {
            animator.startAnimation(animationName + "_hungry");
        } else {
            animator.startAnimation("main_player_walk_hungry");
        }
    }
    /**
     *  Activate the poison animation debuff
     */
    private void animatePoison() {
        animationName = animator.getCurrentAnimation();
        preAnimationCleanUp();
        if(animationName != null) {
            animator.startAnimation(animationName + "_poisoned");
        } else {
            animator.startAnimation("main_player_walk_poisoned");
        }
    }
  ...
Texture Atlases
All the animation atlases for the 4 attires:
Example texture atlas:

Testing
We've added animation atlas tests for the new burn and hurt animations - PlayerAnimationAtlasTest.java
        testAnimator.addAnimation("main_player_right", 1f);
        assertTrue(testAnimator.hasAnimation("main_player_right"));
        testAnimator.addAnimation("main_player_hurt", 1f);
        assertTrue(testAnimator.hasAnimation("main_player_hurt"));
        testAnimator.addAnimation("main_player_burn", 1f);
        assertTrue(testAnimator.hasAnimation("main_player_burn"));
        assertNotNull(atlas.findRegion("main_player_right"));
        assertTrue(testAnimator.hasAnimation("main_player_right"));
        assertNotNull(atlas.findRegion("main_player_hurt"));
        assertTrue(testAnimator.hasAnimation("main_player_hurt"));
        assertNotNull(atlas.findRegion("main_player_burn"));
        assertTrue(testAnimator.hasAnimation("main_player_burn"));
We've also included new unit tests to verify the triggering of the new animations - PlayerAnimationRenderTest.java
 @Test
    void shouldTriggerBurnMovement() {
        player.getEvents().trigger("burn");
        verify(animator).startAnimation("main_player_burn");
    }
    @Test
    void shouldTriggerHurtMovement() {
        player.getEvents().trigger("hurt");
        verify(animator).startAnimation("main_player_hurt");
    }
    @Test
    void shouldTriggerWalkRightMovement() {
        player.getEvents().trigger("stopAnimations");
        verify(animator).startAnimation("main_player_walk");
    }
UML Diagrams
magmaCollision()

animateBurn()
