Skip to content

Trap creation

parker334 edited this page Sep 14, 2021 · 13 revisions

Introduction

A function that creates the trap in the game.

Usage

Traps are created and added to the map using Entity [nameOfTheTrap] = ObstacleFactory.createPhysicalTrap(); and using spawnEntityAt([nameOfTheTrap], [position], true, true); to adjust the spawn location to [postion].
The trap's damage can be changed by adjusting x in trap.getComponent(CombatStatsComponent.class).setBaseAttack(x);
To change the trap image copy the public static Entity createPhysicalTrap() function in ObstacleFactory.java and change the image path.

Trap placeholder can be found and replace at the image path (\source\core\assets\images). Placeholder upload commit

Dedicate hitbox trap layer has been added. The trap hitbox on the player is separated and the only slightly is bigger than the player collision box. It can resize in playerFactoy.java

Trap testing:

Junit test

Resizeable Traps

To create traps which can be imported from the JSON, a variation to the currently traps was made in which there is no placeholder image (as textures are already on terrain) and that could be made of varying size.

The traps are created using the following code.

public static Entity createRSPhysicalTrap(float width, float height) {
    Entity trap = new Entity()
            .addComponent(new PhysicsComponent().setBodyType(BodyType.StaticBody))
            .addComponent(new ColliderComponent().setLayer(PhysicsLayer.OBSTACLE))
            .addComponent(new CombatStatsComponent(1000000, 10))
            .addComponent(new HitboxComponent().setLayer(PhysicsLayer.OBSTACLE))
            .addComponent(new TouchAttackComponent(PhysicsLayer.TRAP, 4));
    trap.setScale(width, height);
    return trap;
  }

(note in non-phycial traps .addComponent(new ColliderComponent().setLayer(PhysicsLayer.OBSTACLE)) is removed

where width and height are the size of the trap in world units.

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