Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #56 Implement enemy waves logic #75

Merged
merged 2 commits into from Oct 22, 2020

Conversation

vittorio-del-bianco
Copy link
Contributor

Wave logic is implemented by 3 scene and 3 matching script (fully documented) in the subfolder enemy_wave:

  1. enemy_wave_manager -> handles waves lifecycle.
  2. enemy_wave -> handle the single wave, each of which is made up of groups of enemies.
  3. enemy_group -> handle a single group of enemies inside a wave
    Most important is the enemy_waves_manager: has all the method and signal to manage all the wave logic gameplay (you don’t need to use enemy_wave and enemy_group, except to design the level wave using only the editor…no script).
    This system is generic and can be used in every level.

To create custom waves in your level, follow these 5 steps:

  1. Place an enemy_wave_manager in your scene.
  2. Place any number of enemy_wave (as many as you need; each of them represents a wave) as childs of enemy_wave_manager.
  3. Set (optionally) in the editor, for each enemy_wave, the description (description text of the wave) and the delay time between the spawn of groups of enemies (in seconds).
  4. Place any number of enemy_group (as many as you need; each of them represents a group of enemies of the same type) as childs of an enemy_wave of your choice.
  5. Select enemy_group of your choice in the editor and set type and grade of the enemies in the group. Set the number of the units in the group. You can set the time (in seconds) between the spawn on a single enemy and the next.
    That’s all.

enemy_waves_manager has a main method to start the next wave: start_next_wave()
Call this, to start the next wave in the list (the first wave if that is the first call).
enemy_waves_manager use 4 signals to inform you about wave lifecycle:

  1. spawn_enemy(enemy_type, enemy_grade) -> Emitted when an enemy from a wave need to be spawn (provides type and grade for the enemy).
  2. last_enemy_in_actual_wave_spawned() -> Emitted when the last enemy of the actual wave is spawned: this means that the actual wave is completed spawned (there are no enemy in queue for this wave).
  3. last_wave() -> Emitted when last wave in the wave list is spawned.
  4. last_enemy_spawned() -> Emitted when the last enemy of the last wave in the wave list is spawned. There are no more enemies to spawn after this (for this level).

Lastly, enemy_waves_manager provides you 2 method to know wave description: get_actual_wave_description()
get_next_wave_description()
And one method to know if there is a wave ready to go:
does_next_wave_exists()


To illustrate the process and for test purpose, there is a subfolder, test, in the enemy_wave folder that provides example of use and unit testing case.
An enemy_wave_test scene has been created to show a complete wave logic implementation: the script in the level root is fully documented.


Lastly, the level 1 of the game has been updated with enemy wave logic: a simple 2 waves logic (as example… need more waves and enemies).
Now, enemies are instantiated according to the logic of the wave manager (there is a script in the root level node to manage that).
Added a button to call the waves.


Todo:

  1. Replace the current (temporary) call enemies’ button with the good one.
  2. Handle the enemy deletion (queue_free) when enemies reach player base (or when killed)
  3. Place PathFollow2D in the enemy scene.

…umented) in the subfolder enemy_wave:

1. enemy_wave_manager -> handles waves lifecycle.
2. enemy_wave -> handle the single wave, each of which is made up of groups of enemies.
3. enemy_group -> handle a single group of enemies inside a wave
Most important is the enemy_waves_manager: has all the method and signal to manage all the wave logic gameplay (you don’t need to use enemy_wave and enemy_group, except to design the level wave using only the editor…no script).
This system is generic and can be used in every level.
_____________________
To create custom waves in your level, follow these 5 steps:
1. Place an enemy_wave_manager in your scene.
2. Place any number of enemy_wave (as many as you need; each of them represents a wave) as childs of enemy_wave_manager.
3. Set (optionally) in the editor, for each enemy_wave, the description (description text of the wave) and the delay time between the spawn of groups of enemies (in seconds).
4. Place any number of enemy_group (as many as you need; each of them represents a group of enemies of the same type) as childs of an enemy_wave of your choice.
5. Select enemy_group of your choice in the editor and set type and grade of the enemies in the group. Set the number of the units in the group. You can set the time (in seconds) between the spawn on a single enemy and the next.
That’s all.
_____________________
enemy_waves_manager has a main method to start the next wave: start_next_wave()
Call this, to start the next wave in the list (the first wave if that is the first call).
enemy_waves_manager use 4 signals to inform you about wave lifecycle:
1. spawn_enemy(enemy_type, enemy_grade) -> Emitted when an enemy from a wave need to be spawn (provides type and grade for the enemy).
2. last_enemy_in_actual_wave_spawned() -> Emitted when the last enemy of the actual wave is spawned: this means that the actual wave is completed spawned (there are no enemy in queue for this wave).
3. last_wave() -> Emitted when last wave in the wave list is spawned.
4. last_enemy_spawned() -> Emitted when the last enemy of the last wave in the wave list is spawned. There are no more enemies to spawn after this (for this level).

Lastly, enemy_waves_manager provides you 2 method to know wave description: get_actual_wave_description()
get_next_wave_description()
And one method to know if there is a wave ready to go:
does_next_wave_exists()
_____________________
To illustrate the process and for test purpose, there is a subfolder, test, in the enemy_wave folder that provides example of use and unit testing case.
An enemy_wave_test scene has been created to show a complete wave logic implementation: the script in the level root is fully documented.
 _____________________
Lastly, the level 1 of the game has been updated with enemy wave logic: a simple 2 waves logic (as example… need more waves and enemies).
Now, enemies are instantiated according to the logic of the wave manager (there is a script in the root level node to manage that).
Added a button to call the waves.
_____________________
Todo:
1. Replace the current (temporary) call enemies’ button with the good one.
2. Handle the enemy deletion (queue_free) when enemies reach player base (or when killed)
3. Place PathFollow2D in the enemy scene.
@davcri davcri merged commit 564711b into crystal-bit:master Oct 22, 2020
@davcri
Copy link
Member

davcri commented Oct 22, 2020

HI @vittorio-del-bianco we discussed everything in live and the PR was really amazing! It's a lot of code, it works well, it's documented and there is also a test scene to showcase everything. Thanks again!

@vittorio-del-bianco
Copy link
Contributor Author

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement enemy waves logic
2 participants