Skip to content

Robot animation functionalities

ShiyanSu edited this page Sep 14, 2021 · 3 revisions

Purpose

The purpose of robot animation is to simulate the real robot to enhance the visual experience of the game and make the game more playable. In addition, the attack area will be extended when the animation of the robot changed.

Design

image

Implementation

Key components

  • robot.atlas This file sets up different animation effects for obstacles.
  • ObstacleAnimationController This class listens to events relevant to the obstacle state and plays the animation when one of the events is triggered.
  • ObstacleFactory Implement the animation effect for robot within createRobot().

Usage

  1. In robot.atlas write the atlas of the animation based on the robot_animation.png.
robot_animation.png
size: 5418, 2501
format: RGBA8888
filter: Nearest,Nearest
repeat: none
float
  rotate: false
  xy: 116, 0
  size: 834, 1140
  orig: 834, 1140
  offset: 0, 0
  index: 0
float
  rotate: false
  xy: 116, 0
  size: 834, 1140
  orig: 834, 1140
  offset: 0, 0
  index: 0
float
  rotate: false
  xy: 116, 0
  size: 834, 1140
  orig: 834, 1140
  offset: 0, 0
  index: 0
float
  rotate: false
  xy: 950, 0
  size: 834, 1140
  orig: 834, 1140
  offset: 0, 0
  index: 1
float
  rotate: false
  xy: 1784, 0
  size: 834, 1140
  orig: 834, 1140
  offset: 0, 0
  index: 2
float
  rotate: false
  xy: 2618, 0
  size: 834, 1140
  orig: 834, 1140
  offset: 0, 0
  index: 3
...
  1. Add the animation when creating the robot obstacle.
  public static Entity createRobot(Entity target) {
    RobotConfig config = configs.robot;
    AITaskComponent aiComponent =
            new AITaskComponent()
                    .addTask(new WanderTask(new Vector2(10f, 0f), 0f));

    AnimationRenderComponent animator =
            new AnimationRenderComponent(
                    ServiceLocator.getResourceService()
                            .getAsset("images/robot.atlas", TextureAtlas.class));
    animator.addAnimation("float", 0.5f, Animation.PlayMode.LOOP);

    Entity robot =
            new Entity()
                    .addComponent(new PhysicsComponent())
                    .addComponent(new PhysicsMovementComponent())
                    .addComponent(new ColliderComponent().setLayer(PhysicsLayer.OBSTACLE))
                    .addComponent(new HitboxComponent().setLayer(PhysicsLayer.NPC))
                    .addComponent(new TouchAttackComponent(PhysicsLayer.PLAYER, 0f))
                    .addComponent(aiComponent);

    robot.addComponent(new CombatStatsComponent(config.health, config.baseAttack))
            .addComponent(animator)
            .addComponent(new ObstacleAnimationController());
    robot.getComponent(PhysicsComponent.class).setBodyType(BodyType.DynamicBody);
    robot.scaleHeight(1f);
    return robot;
  }

UML

image

Table of Contents

Home

Introduction

Main Menu

Main Game Screen

Gameplay

Player Movement

Character Animations

Enemy Monster Design and Animations

Game basic functionalities

User Testing

GitHub Wiki Tutorial

Game Engine

Getting Started

Documentation

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