Skip to content

Trebuchet

DLAmeng edited this page Oct 3, 2022 · 2 revisions

Introduction

This page introduces the function of the trebuchet. The main function of the trebuchet is to launch the bullet to attack the ship. When the bullet contacts the ship, the bullet will disappear and the ship's HP will decrease.

  • Spawn bullet at trebuchet location
  • The bullet will move towards the target
  • The bullet disappears when it touches the target

Usage

1. Create a bullet entity by listening to the trigger in the rangedAttackTask through AttackListnerComponent.

public void create() {
        super.create();
        entity.getEvents().addListener("attack", this::attack);
    }

    void attack() {
        gameArea.spawnEntity(EnemyFactory.createBullet(this.entity, target, gameArea));
    }

2. Create a BulletHitShipComponent, which can detect whether the bullet collides with the target. When the bullet collides with the target, the bullet will be destroyed and the target will be damaged.

public void create() {
        super.create();
        entity.getEvents().addListener("collisionStart", this::Hit);
    }

    private void Hit(Fixture attack, Fixture player) {
        Entity bullet = ((BodyUserData) attack.getBody().getUserData()).entity;
        Entity target = ((BodyUserData) player.getBody().getUserData()).entity;
        if(target == this.target) {
            bullet.getComponent(PhysicsComponent.class).getPhysics().addToDestroy(bullet);
            target.getComponent(CombatStatsComponent.class).decreaseHealth(20);
        }
    }

UML

img

Table of Contents

Home

Game

Game Home

Design Influences

Gameplay Features

Style

Story

Friendly Units
Map
City
Buildings
Unit Selections

Spell

Game User Testing: Theme of Unit Selection & Spell System

UI User Testing

Tutorial

Resource Stats Display

Loading Screen Bar

Health Bars
In Game menu
  • Feature
  • User Testing:In Game Menu

Landscape Tile Design

Landscape Tile Design Feedback

Weather Design

Weather Design Feedback

Camera Movement

Enemy design

Enemy Units

Enemy AI

How Animation Works

Map Flooding

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