-
Notifications
You must be signed in to change notification settings - Fork 4
Sprint 1 Main Character Movement and Animation
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.
Action | Key Control | Comment |
---|---|---|
Jump | W / UP | Implemented |
Walk | Default movement | Implemented |
Run Right | D / RIGHT | Implemented |
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 |
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;
}
}
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);
KeyboardPlayerInputComponent.java
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.
An AnimationRenderComponent is used to define the animation of the character, itβs movement and the FPS:
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");
}
The atlas that was used for creating the animations was generated using a texture packer. The atlas has player representation in three states:
- Standing (facing right, static)
- Walking (facing right, animated)
- Running (facing right, animated)
- Standing (facing forward, static)
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
PlayerActions
PlayerAnimationController
animateJump
animateAttack
animateCrouch
stopAnimateAll
preAnimationCleanUp
PlayerAnimationController
Camera Angle and The Player's Perspective
Achievements Trophies and Cards
πΎ Obstacle/Enemy
βMonster Manual
βObstacles/Enemies
ββ- Alien Plants
ββ- Variation thorns
ββ- Falling Meteorites
ββ- FaceHugger
ββ- AlienMonkey
βSpaceship & Map Entry
βParticle effect
[code for debuff animations](code for debuff animations)
Main Character Movement, Interactions and Animations - Code Guidelines
ItemBar & Recycle system
πΎ Obstacle/Enemy
βObstacle/Enemy
βMonster Manual
βSpaceship Boss
βParticle effects
βOther Related Code
βUML & Sequence diagram of enemies/obstacles
Scoring System Implementation Explanation
Buff and Debuff Implementation
Infinite generating terrains Implementation Explanation
Game Over Screen and functions explaination
Buffer timer before game start
Rocks and woods layout optimization
Magma and nails code implementation
Guide: Adding Background music for a particular screen
History Scoreboard - Score Details
Listening for important events in the Achievements ecosystem
Hunger and Thirst icon code guidelines
Hunger and Thirst User Testing
Buff and Debuff Manual User Testing
The New Button User Test in Setting Page
The Main Menu Buttons User Testing
Infinite loop game and Terrain Testing
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
Sprint 1
Sprint 2
Sprint 3
Sprint 4
Changeable background & Buffer time testing
Game over screen test sprint 4
New terrain textures on bonus map test sprint 4
Achievements System, Game Records and Unlockable Chapters
Musics Implementation Testing plan