Skip to content

Boss teleportation

MTbir edited this page Oct 4, 2021 · 4 revisions

Overview

The elves boss has the special component (skill) that allow it to randomly teleport away from the player if its health is lower than 50%. The boss will spawn a vortex at its current position, then it will spawn another one at a random position on the map then it will teleport itself to that position.

The implementation of this feature also allowed the boss to spawn at a position outside of the map, and only teleport into the map once all other minions are killed.

Code

@Override
    public int getPriority() {
        if ((ServiceLocator.getGameAreaService().getNumEnemy() == 0 && count == 0)
                || (ServiceLocator.getGameAreaService().getNumEnemy() != 0 && mapBound())) {
            return 100;
        }
        if (canTeleport() || spawn) {
            if (spawn && TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) - lastFired >= 4000) {
                spawn = false;
            }
            return 30;
        }
        return -1;
    }

If all enemies are killed, the boss will spawn on the map, or if canTeleport() satisfy (boss lose health, health lower than 50%, and can see the player) then it will also teleport.

Teleport

public void teleport() {
        if (lastFired == 0) {
            lastFired = TimeUnit.NANOSECONDS.toMillis(System.nanoTime());
        }
        spawn = true;


        Entity entity = new Entity();
        entity.setPosition(owner.getEntity().getPosition());

        Entity vortex = WeaponFactory.createVortex(entity,
                getDirectionOfTarget(), false);

        Vector2 minPos =
                new Vector2(0, 0);
        Vector2 maxPos = new Vector2(10, 10);
        pos2 = RandomUtils.random(minPos, maxPos);
        Entity entity2 = new Entity();
        entity2.setPosition(pos2);
        gameArea.spawnEntityAt(vortex, owner.getEntity().getPosition(), true, true);
        Entity vortex2 = WeaponFactory.createVortex(entity2, getDirectionOfTarget(), false);

        gameArea.spawnEntityAt(vortex2, pos2, true, true);
    }

Two vortices are created, one at the enemy position and one at the position it is teleport. After 800ms (vortex upscale to desire size), the enemy will be teleport using owner.getEntity().setPosition()

Teleportation Task Class Diagram

Teleportation Task System Sequence

Vortex design

Table of Contents

Home

Design Document

Design Document

Design Document

Game Engine

Getting Started

Entities and Components

Item Drops from Entities

Service Locator

Loading Resources

Logging

Unit Testing

Debug Terminal

Input Handling

UI

Animations

Audio

AI

Physics

Game Screens and Areas

Terrain

Map Generation

Concurrency & Threading

Settings

Troubleshooting

MacOS Setup Guide

Clone this wiki locally