Skip to content

Asteroid fire animation functionalities

raneechu edited this page Oct 2, 2021 · 6 revisions

Purpose

The purpose of asteroid fire animation is to simulate the real fire to enhance the visual experience of the game and make the game more playable.

Design

image

Implementation

Key components

  • asteroidFire.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 asteroid fire within createAsteroidAnimatedFire().

Usage

  1. In asteroidFire.atlas write the atlas of the animation based on the asteroid_animation_3.png.
asteroid_animation_3.png
size: 2440, 2076
format: RGBA8888
filter: Nearest,Nearest
repeat: none
float
  rotate: false
  xy: 0, 0
  size: 400, 630
  orig: 400, 630
  offset: 0, 0
  index: 0
float
  rotate: false
  xy: 400, 0
  size: 400, 630
  orig: 400, 630
  offset: 0, 0
  index: 1
float
  rotate: false
  xy: 800, 0
  size: 400, 630
  orig: 400, 630
  offset: 0, 0
  index: 2
  1. Add the animation when creating the asteroid fire obstacle.
public static Entity createAsteroidAnimatedFire(Entity target) {
    AsteroidFireConfig config = configs.asteroidFire;
    AITaskComponent aiComponent =
            new AITaskComponent()
                    .addTask(new WanderTask(new Vector2(0f, 0f), 0f));
    AnimationRenderComponent animator =
            new AnimationRenderComponent(
                    ServiceLocator.getResourceService()
                            .getAsset("images/asteroidFire.atlas", TextureAtlas.class));
    animator.addAnimation("float", 0.2f, Animation.PlayMode.LOOP);
    Entity asteroidFire =
            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);
    asteroidFire.addComponent(new CombatStatsComponent(config.health, config.baseAttack))
            .addComponent(animator)
            .addComponent(new ObstacleAnimationController());
    asteroidFire.getComponent(PhysicsComponent.class).setBodyType(BodyType.DynamicBody);
    asteroidFire.scaleHeight(1f);
    // Make hit box smaller 
    asteroidFire.getComponent(HitboxComponent.class).setAsBox(new Vector2(0.3f, 1f));
    // Allows player to pass through fire while taking damage
    asteroidFire.getComponent(ColliderComponent.class).setSensor(true);
    return asteroidFire;
  }

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