Skip to content

Sprint 2 Technical Implementation

Josephjmet edited this page Sep 13, 2022 · 4 revisions

Link back to the main page

Spawning of Ranged Enemy

The current implementation to spawn a ranged enemy can be found in NPCFactory(). Updated movement tasks were created to allow for better AI movement of enemies.

multiple AI tasks have been implemented into enemies, with one new task RangedMovementTask(). these tasks have been given priority values to ensure that the enemies fucntion correctly, with targeting the crystal first, and the main character second but with higher priority to all for the main character to kite enemies.

 private static Enemy createBaseRangeNPC(Entity target, Entity crystal) {
    //Vector2 RangeHitbox = new Vector2(2f, 1f);
    AITaskComponent aiComponent =
            new AITaskComponent()
                    .addTask(new WanderTask(new Vector2(3f, 3f), 2f))
                    .addTask(new RangedMovementTask(crystal, 10, 2f, 20f, 30f))
                    .addTask(new RangedMovementTask(target, 20, 2f, 3f, 5f));
    Enemy enemy =
            (Enemy) new Enemy()
                    .addComponent(new PhysicsComponent())
                    .addComponent(new PhysicsMovementComponent())
                    .addComponent(new ColliderComponent())
                    .addComponent(new HitboxComponent().setLayer(PhysicsLayer.RangeNPC))
                    .addComponent(new TouchAttackComponent(PhysicsLayer.RangeNPC))
                    .addComponent(aiComponent);

    PhysicsUtils.setScaledCollider(enemy, 0.9f, 0.4f);
    return enemy;
  }

improving ranged movement

This code is updated to stop the enemy when it gets to a certain range close to the main character, as ranged units will stay at a distance to attack.

private int getActivePriority() {
        float dst = getDistanceToTarget();
        if (dst <= range || !isTargetVisible()) {
            stop();
            return -1; // Stop and get ready to shoot
        } else if (dst > maxChaseDistance || !isTargetVisible()) {
            return -1; // Too far, stop chasing
        }
        return priority;
    }

Testing was completed and recorded below

Testing of updated AI task Priority and ranged enemy movement:

https://youtu.be/rGwg272r65w

Testing of pathfinding for ranged enemy movement:

https://www.youtube.com/watch?v=omrx_Rw0bsc

Table of Contents

Home

How to Play

Introduction

Game Features

Main Character

Enemies
The Final Boss

Landscape Objects

Shop
Inventory
Achievements
Camera

Crystal

Infrastructure

Audio

User Interfaces Across All Pages
Juicy UI
User Interfaces Buildings
Guidebook
[Resource Management](Resource-Management)
Map
Day and Night Cycle
Unified Grid System (UGS)
Polishing

Game Engine

Getting Started

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