Skip to content

UFO_animation Function

ShiyanSu edited this page Sep 14, 2021 · 3 revisions

Purpose

The purpose of UFO animation is to Increase the difficulty of the game, When the player is close to ufo for a certain distance, ufo will chase the player.

Design

image

Implementation

Key Components

  • ufo_animation.atlas This file sets up different animation effects for obstacles.
  • UfoAnimationController This class listens to events relevant to a ufo state and plays the animation when one of the events is triggered.
  • ObstacleFactory Create ufo obstacle by creatUFO(), createUFO can add tasks and animation effects to UFO.

Code of ufo_animation.atlas

ufo_animation-01.png
size: 8334, 7500
format: RGBA8888
filter: Nearest,Nearest
repeat: none
ufo
  rotate: false
  xy: 166, 705
  size: 1237, 1667
  orig: 1237, 1667
  offset: 0, 0
  index: 0
default
  rotate: false
  xy: 166, 705
  size: 1237, 1667
  orig: 1237, 1667
  offset: 0, 0
  index: 0
hit_ufo
  rotate: false
  xy: 166, 705
  size: 1237, 1667
  orig: 1237, 1667
  offset: 0, 0
  index: 0
hit_ufo
  rotate: false
  xy: 1831, 705
  size: 1237, 1667
  orig: 1237, 1667
  offset: 0, 0
  index: 1
hit_ufo
  rotate: false
  xy: 3498, 705
  size: 1237, 1667
  orig: 1237, 1667
  offset: 0, 0
  index: 2
hit_ufo
  rotate: false
  xy: 5165, 705
  size: 1237, 1667
  orig: 1237, 1667
  offset: 0, 0
  index: 3

Code of add tasks in the createUFO()

AITaskComponent aiComponent =
     new AITaskComponent()
         .addTask(new WanderTask(new Vector2(3f, 2f), 0f))
         .addTask(new ChaseTask(target, 2,2f,2.5f));
ufo.addComponent(aiComponent);

Code of add animation in the createUFO()

AnimationRenderComponent animator =
     new AnimationRenderComponent(
          ServiceLocator.getResourceService().getAsset("images/ufo_animation.atlas", TextureAtlas.class));
animator.addAnimation("hit_ufo", 0.5f, Animation.PlayMode.LOOP_REVERSED);
animator.addAnimation("ufo", 0.5f, Animation.PlayMode.LOOP);
ufo.addComponent(animator);
ufo.addComponent(new UfoAnimationController());
ufo.getComponent(AnimationRenderComponent.class).scaleEntity();

Code of UfoAnimationController.java

public class UfoAnimationController extends Component {
    AnimationRenderComponent animator;

    @Override
    public void create() {
        super.create();
        animator = this.entity.getComponent(AnimationRenderComponent.class);
        entity.getEvents().addListener("wanderStart", this::animateWander);
        entity.getEvents().addListener("chaseStart", this::animateChase);
    }

   void animateWander() {
       animator.startAnimation("ufo");
    }

   void animateChase() {
       animator.startAnimation("hit_ufo");
   }
}

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