Skip to content

Sprint 1 Main Character Movement and Animation

Rohith Palakirti edited this page Sep 13, 2021 · 5 revisions

Contents

Movement

The main player character can be controlled using the WASD keys or the arrow keys. Below is a table including descriptions and controls of how to manipulate the main character.

Key Map:

Action Key Control Comment
Jump W / UP Implemented
Walk Default movement Implemented
Run Right D / RIGHT Implemented
Run Left A / LEFT Deprecated
Crouch To be determined Future Sprints
Attack To be determined Future Sprints
Item Pick Up To be determined Future Sprints
Use Item To be determined Future Sprints
Switch Item To be determined Future Sprints

Movement Implementation

The movement and action controls are implemented by using the KeyboardPlayerInputComponent class, while using functions to detect key presses and releases. Each key press triggers a certain event and is handled using trigger/listener pairs.

Implementation in KeyboardPlayerInputComponent.java:

/**
   * Triggers player events on specific keycodes.
   *
   * @return whether the input was processed
   * @see InputProcessor#keyDown(int)
   */
  @Override
  public boolean keyDown(int keycode) {
    switch (keycode) {

      case Keys.S:
      case Keys.DOWN:
        walkDirection.add(Vector2Utils.DOWN);
        triggerWalkEvent();
        return true;
      case Keys.D:
      case Keys.RIGHT:
        walkDirection.add(Vector2Utils.RIGHT);
        triggerWalkEvent();
        entity.getEvents().trigger(("walkRight"));
        return true;
      case Keys.SPACE:
        entity.getEvents().trigger("attack");
        return true;
      case Keys.W:
      case Keys.UP:
        entity.getEvents().trigger("jump");
        return true;
      default:
        return false;
    }
  }
  /**
   * Triggers player events on specific keycodes.
   *
   * @return whether the input was processed
   * @see InputProcessor#keyUp(int)
   */
  @Override
  public boolean keyUp(int keycode) {
    switch (keycode) {
      case Keys.S:
      case Keys.DOWN:
        walkDirection.sub(Vector2Utils.DOWN);
        triggerWalkEvent();
        return true;
      case Keys.D:
      case Keys.RIGHT:
        walkDirection.sub(Vector2Utils.RIGHT);
        entity.getEvents().trigger(("stopWalkRight"));
        triggerWalkEvent();
        return true;
      case Keys.W:
      case Keys.UP:
        entity.getEvents().trigger("stopJump");
      default:
        return false;
    }
  }

Implementation of Jump

A vertical vector impulse is applied directly to the body of the main player entity to simulate jumping in the game environment.

Implementation in PlayerActions.java:

/**
   * Makes the player jump
   */

void jump() {
    Sound jumpSound = ServiceLocator.getResourceService().getAsset("sounds/jump.ogg", Sound.class);
    jumpSound.play();
    
    Body body = physicsComponent.getBody();
    body.applyForceToCenter(0, 400f, true);

Relevant Files

KeyboardPlayerInputComponent.java

PlayerActions.java

Animations

The main player character starts off as a static texture until the user presses the key for the right movement. Once the movement is triggered, the texture is removed from the game area and replaced with an AnimationRenderComponent. As movement is triggered, the default movement animation is walking. Once the move right key is pressed, the animation switches to running and all the previous animations are stopped for the entity player.

Animation Implementation

An AnimationRenderComponent is used to define the animation of the character, it’s movement and the FPS:

PlayerFactory.java

    AnimationRenderComponent animator =
            new AnimationRenderComponent(
                    ServiceLocator.getResourceService()
                            .getAsset("images/mpcMovement.atlas",
                                    TextureAtlas.class));
    animator.addAnimation("main_player_run", 0.1f, Animation.PlayMode.LOOP);
    animator.addAnimation("main_player_walk", 0.5f, Animation.PlayMode.LOOP);
    animator.addAnimation("mpc_front", 1f, Animation.PlayMode.LOOP);

The listeners implemented here lookout for trigger events and run the corresponding functions in PlayerActions.java:

public void create() {
    animator = this.entity.getComponent(AnimationRenderComponent.class);
    physicsComponent = entity.getComponent(PhysicsComponent.class);
    entity.getEvents().addListener("walk", this::walk);
    entity.getEvents().addListener("walkStop", this::stopWalking);
    entity.getEvents().addListener("walkRight", this::walkRight);
    entity.getEvents().addListener("stopWalkRight", this::stopWalkRight);
    entity.getEvents().addListener("walkLeft", this::walkLeft);
    entity.getEvents().addListener("attack", this::attack);
    entity.getEvents().addListener("jump", this::jump);
  }

The below functions are triggered on key press events and are responsible for switching between the running and walking animation - PlayerActions.java:

/**
   * Updates the player sprite to run right
   */

  void walkRight() {
    animator.getEntity().setRemoveTexture();
    animator.stopAnimation();
    animator.startAnimation("main_player_run");
    Sound turnSound = ServiceLocator.getResourceService().getAsset("sounds/turnDirection.ogg", Sound.class);
    turnSound.play();
  }
  void stopWalkRight() {
    animator.stopAnimation();
    animator.startAnimation("main_player_walk");

  }

Relevant Files

PlayerFactory.java

PlayerActions.java

mpcMovement.atlas

mpcMovement.png

PlayerAnimationController

In-game Animations Demonstration

Walking

Walking

Running

Running

Texture atlas

The atlas that was used for creating the animations was generated using a texture packer. The atlas has player representation in three states:

  1. Standing (facing right, static)
  2. Walking (facing right, animated)
  3. Running (facing right, animated)
  4. Standing (facing forward, static)

Generated Texture pack

mpcMovement.png

Generated Texture atlas

mpcMovement.png
size: 4096, 1024
format: RGBA8888
filter: Nearest, Nearest
repeat: none
main_player_right
  rotate: false
  xy: 2717, 2
  size: 541, 541
  orig: 541, 541
  offset: 0, 0
  index: -1
main_player_run
  rotate: false
  xy: 545, 2
  size: 541, 541
  orig: 541, 541
  offset: 0, 0
  index: 2
main_player_run
  rotate: false
  xy: 2174, 2
  size: 541, 541
  orig: 541, 541
  offset: 0, 0
  index: 1
main_player_walk
  rotate: false
  xy: 2, 2
  size: 541, 541
  orig: 541, 541
  offset: 0, 0
  index: 2
main_player_walk
  rotate: false
  xy: 1088, 2
  size: 541, 541
  orig: 541, 541
  offset: 0, 0
  index: 1
mpc_front
  rotate: false
  xy: 1631, 2
  size: 541, 541
  orig: 541, 541
  offset: 0, 0
  index: -1

Relevant Files

mpcMovement.atlas

mpcMovement.png

UML Diagrams

Class Diagrams

PlayerActions

PlayerActions

PlayerAnimationController

PlayerAnimationController

Sequence Diagrams

animateJump

animateJump

animateAttack

animateAttack

animateCrouch

animateCrouch

stopAnimateAll

stopAnimateAll

preAnimationCleanUp

preAnimationCleanUp

PlayerAnimationController

PlayerAnimationController

Gameplay

Home

Main Character

πŸ‘Ύ Obstacle/Enemy

Food & Water

Pickable Items

Game achievements

Game Design

Emotional Goals

Game Story

Influences

Style

Pixel Grid Resolution

Camera Angle and The Player's Perspective

Features Design

Achievements Screen

Achievements Trophies and Cards

Music Selection GUI

πŸ‘Ύ Obstacle/Enemy

 Monster Manual
 Obstacles/Enemies
  - Alien Plants
  - Variation thorns
  - Falling Meteorites
  - FaceHugger
  - AlienMonkey
 Spaceship & Map Entry
 Particle effect

Buffs

Debuffs

Buffs and Debuffs manual

Game Instruction

[code for debuff animations](code for debuff animations)

Infinite loop game system

Main Menu Screen

New Setting Screen

Hunger and Thirst

Goals and Objectives

HUD User Interface

Inventory System

Item Bar System

Scoring System

Props store

BGM design

Sound Effect design

Main game interface

Invisible ceiling

New terrain sprint 4

New game over screen sprint 4

Code Guidelines

Main Character Movement, Interactions and Animations - Code Guidelines

Item Pickup

ItemBar & Recycle system

Main Menu Button Code

Game Instructions Code

πŸ‘Ύ Obstacle/Enemy

 Obstacle/Enemy
 Monster Manual
 Spaceship Boss
 Particle effects
 Other Related Code
 UML & Sequence diagram of enemies/obstacles

Scoring System Implementation Explanation

Music Implementation

Buff and Debuff Implementation

Score History Display

code improvement explanation

Infinite generating terrains Implementation Explanation

Game Over Screen and functions explaination

Buffer timer before game start

Scrolling background

Multiple Maps

Invisible ceiling

Rocks and woods layout optimization

Magma and nails code implementation

Background Music Selection

Chooser GUI Implementation

Chooser GUI Logic Persistence

Guide: Adding Background music for a particular screen

Achievements Ecosystem - Code Guidelines

Achievements System

Achievements Screen

Adding Achievements (Guide)

Game Records

DateTimeUtils

History Scoreboard - Score Details

Listening for important events in the Achievements ecosystem

Food and Water System

Food System Water System

Hunger and Thirst icon code guidelines

Asset Creation

In Game Background Music

User Testing

Hunger and Thirst User Testing

Main Character Testing

Buffs and Debuffs Testing

Buff and Debuff Manual User Testing

Game Instruction User Testing

The Main Menu User Test

The New Button User Test in Setting Page

The Main Menu Buttons User Testing

Hunger and Thirst User Test

Infinite loop game and Terrain Testing

Item Bar System Testing

Randomised Item Drops

Recycle System Testing

Scoring System Testing

Music User test

https://github.com/UQdeco2800/2021-ext-studio-2.wiki.git

πŸ‘Ύ Obstacle/Enemy

 Obstacle testing
  - Alien Plants & Variation Thorns
  - Falling Meteorites
 Enemy testing
  - Alien Monkeys & Facehugger
  - Spaceship Boss
 Monster Manual
 Particle-effect
 Player attack testing
  - Player Attack

Inventory system UI layout

Props store user testing

Achievements User Testing

Sprint 1

Sprint 2

Sprint 3

Sprint 4

Items testing

Player Status testing

Changeable background & Buffer time testing

Main game interface test

Invisible ceiling test

Game over screen test sprint 4

New terrain textures on bonus map test sprint 4

Buying Props User Testing

Testing

Hunger and Thirst Testing

Main Character Player

Achievements System, Game Records and Unlockable Chapters

DateTimeUtils Testing

Scoring System Testing Plan

Distance Display Testing Plan

Musics Implementation Testing plan

History Board Testing plan

Rocks and woods testing plan

Sprint 4 terrain tests

Items

Item Bar System Testing Plan

Recycle System Testing Plan

Game Engine

Game Engine Help

Getting Started

Entities and Components

Service Locator

Loading Resources

Logging

Unit Testing

Debug Terminal

Input Handling

UI

Animations

Audio

AI

Physics

Game Screens and Areas

Terrain

Concurrency & Threading

Settings

Troubleshooting

MacOS Setup Guide

Clone this wiki locally