Trap creation - UQdeco2800/2021-studio-2 GitHub Wiki
A function that creates the trap in the game.
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
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.