Skip to content

BuildingActions Component

hugh5 edited this page Aug 28, 2022 · 1 revision

Explanation

This is a Component that is added to all building entities when spawn through the BuildingFactory

On create, it registers event handlers to listen to mouse events to provide functionality for placing the building in the GameArea. The building placement feature requires building entity to have the TouchPlayerInputComponent which triggers the various placement events when certain mouse events occur.

  • On Left mouse button down, the building will placed
  • When in placing mode, the Entity's position follows the mouse until placed or dispose.
  • Start placement is not triggered by anything - letting team 1 UI trigger through user interface

This component also registers a callable event to level up the building but is not currently being triggered by any event. This is just to demonstrate support for a building leveling system.

Implementation

public void create() {
    entity.getEvents().addListener("startPlacing", this::startPlacing); // Not triggerd by any event yet
    entity.getEvents().addListener("placing", this::placing);
    entity.getEvents().addListener("place", this::place);
    entity.getEvents().addListener("levelUp", this::addLevel); // Not triggered by any event yet
    physicsComponent = entity.getComponent(PhysicsComponent.class);
    placed = true;
}
public void startPlacing() {
    if (!placed) {return;}
    placed = false;
    physicsComponent.setEnabled(false);
}

public void placing(int screenX, int screenY) {
    if (placed) {return;}
    Vector2 position = mouseToGrid(screenX, screenY);
    entity.setPosition(position);
}

public void place(int screenX, int screenY) {
    if (placed) {return;}
    placed = true;
    physicsComponent.setEnabled(true);
    Vector2 position = mouseToGrid(screenX, screenY);
    entity.setPosition(position);
}

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