Technisch Ontwerp - rzfvansuijdam/Project_Kaiju GitHub Wiki

Audio manager

Introduction

The AudioManager is a component responsible for managing audio playback in a software application. It provides functionality to play, stop, and control the volume and pitch of audio clips. This document outlines the technical design of the AudioManager system.

System architecture

The AudioManager system consists of the following components:

  • AudioManager: The central component responsible for managing the audio playback.
  • Sound class: A collection of audio clips organized by name for easy retrieval.
  • Audio Source: The component responsible for playing the audio clips.

1.1 AudioManager

The AudioManager acts as a central hub for controlling the audio playback.

Responsibilities:

  • Initializing the audio system.
  • Loading and unloading audio clips.
  • Providing methods to play, stop, and control the volume and pitch of audio clips.
  • Managing the state of audio clips (playing, paused, stopped).

1.2 Sound class

The Sound Database is a data structure that holds references to audio clips. It maps sound names to their corresponding audio clip assets.

Key features of the Sound Database include:

  • Storing audio clips by name for easy retrieval.
  • Providing methods to add, remove, and retrieve audio clips.
  • Managing the loading and unloading of audio clips.

1.3 Audio Source

The Audio Source is a component attached to game objects that need to play audio clips. It interfaces with the underlying audio system to play the specified audio clip.

Example workflow

  • Attach the audiomanager script to a gameobject it doesn’t matter which.

  • The sound class should automatically be added to the gameobject.

  • In the sound class you can add a sound and give it a name and adjust volume and pitch .

  • In an other script where the audio should be triggered like gun fire make a reference to the audiomanager and tell it to play the name of the audioclip.

Conclusion

The audio manager is a good allround system to play and use audio within the game it is also easily intergratable and adjustable because every sound is adjustable in volume and pitch and you can always add other variables to the class


Health System

Purpose

The health system provides a framework for managing the health of players and enemies in a game. It allows for tracking health values, applying damage, triggering events on health changes.

Components

  1. PlayerHealth

Responsibilities:

  • Tracks the current health value of the player.
  • Provides methods to take damage and update the health value.
  • Triggers events on health changes and zero health.

Interfaces:

  • GetCurrentHealth(): Returns the current health value of the player.

Events:

  • onHealthChanged(health): Event triggered when the player's health changes. Provides the updated health value.
  • onDeath(): Event triggered when the player's health reaches zero.
  1. EnemyHealth

Responsibilities:

  • Tracks the current health value of an enemy.
  • Provides methods to take damage, handle enemy death, and update the health value.
  • Triggers events on health changes and enemy death.

Interfaces:

  • GetCurrentHealth(): Returns the current health value of the enemy.

Events:

  • onHealthChanged(health): Event triggered when the enemy's health changes. Provides the updated health value.
  • onDeath(): Event triggered when the enemy dies.
  1. IDamage

Interface

  • TakeDamage(Damage): this is an interface that gives the damage to both player and enemy

Usage

  1. Attach the PlayerHealth script to the player object in the game.

  2. Attach the EnemyHealth script to enemy objects.

  3. IDamage doesn’t need to be attached to anything

Example Workflow

  1. The player or enemy takes damage by calling the TakeDamage(amount) method of their respective health scripts.

  2. The health script updates the current health value and triggers the onHealthChanged(health) event.

  3. Any scripts listening to the onHealthChanged event, such as a healthslider, receive the updated health value and update the UI accordingly.

  4. If the health value reaches zero, the health script triggers the OnDeath() event.

  5. Any scripts listening to the OnDeath event can perform actions such as game over for the player or enemy death.

Conclusion

The health system provides a flexible and modular solution for managing health in a game. It separates the logic for tracking health, applying damage. thus keeping it seperate and organized


Waypoint System

Waypoints worden verzameld in de Waypoint Manager Singleton, en worden vervolgens een Bezier path erdoor aangewezen. Deze gebruikt een Quadratic Bezier calculatie waar de curve strength de deviatie van de twee onzichtbare punten voorstelt. Hieronder heb ik een voorbeeld van mijn workflow in Unity, waar ik gebruik maak van editor buttons om een level lay-out te creëren.

Een gif van hoe het waypoint systeem werkt

Hier is een visueel voorbeeld hoe een Bezier Curve werkt in een wiskundige manier.

Bezier path wiskunde

Lijnen worden getrokken, allemaal met dezelfde positite tussen A en B gerepresenteerd door t die tussen 0.0 en 1.0 staat. Het bezier punt is waar al deze lijnen gezamelijk bij elkaar komen. De formule daarvoor is:

9079c197914f4bb93341b43c37018543920684fd


Attack system

Purpose

  • The purpose of the Attack System is to indicate to a player where an attack will be and what area they need to avoid in order to avoid being damaged. The place and size of the attack is conveyed through the use of 2D sprites that are placed at the level where the attack is.

Components

  1. AttackSystem

Responsibilities:

  • Managing the Floor Marker
  • Moving the Floor Market to the appropriate position (from the store position, to the desired position, and back to the store position).
  • Applying damage.
  • Check if attack is cancelled.

Interfaces:

  • FloorMarketAttack(Vector3 spawnPosition, float timeToWait, int sprite): Performs all the aforementioned tasks.

https://github.com/rzfvansuijdam/Project_Kaiju/assets/43441605/6cfbccba-959f-4839-b30a-515c206de43b

Shown here: White rectangle is floor marker, black rectangle is the boat. White rectangle gets moved over to black rectangle and detects that it's a hit.

Substantiation

A Floor Marker is very easily recognisable, because of this a player will not feel like they are being attacked by nothing or an attack they couldn't have seen coming. This function is done in a coroutine in order to use the WaitForSeconds() to apply the delay instead of using a float timer in the Update().