🎮

Enhancing Camera and Enemy Systems

Feb 11, 2025

Waveshooter Tutorial Series - Tutorial 10

Overview

  • Objective: Improve camera shake and refactor the enemy system.
  • Acknowledgment: Good job reaching tutorial number 10!

Camera Shake Improvements

  • Previous camera shake method did not look good enough.
  • Changes to Camera 2D Script:
    • Adjust zoom in intensity from 0.015 to a better value.
    • Remove snap-back position to (320, 180).
    • Implement Lerp for smooth transition back to base position:
      • Code Snippet: if the screen is not shaking: global position = lerp(global position, Vector2(320, 180), 0.3)
  • Result: Improved visual appeal of camera shake.

Enemy System Refactor

  • Goals: Create a more efficient enemy system with fewer duplications in code.

  • Scene Inheritance Concept:

    • Use enemy core as a base script for all enemies.
    • Common functionalities (HP, knockback, etc.) will be inherited.
    • Avoid code duplication to simplify updates and changes.
  • Implementation Steps:

    1. Create an enemy core script inheriting from Sprite.
    2. Transfer common variables (speed, HP, etc.) from the enemy script to enemy core.
    3. Update enemy script to extend enemy core.
  • Custom functions for movement:

    • Create a basic movement towards player function allowing flexibility for different enemy behaviors.

Variable Management

  • Introduced exported variables to allow easy editing in the editor:
    • HP, speed, knockback, screen shake can now be adjusted easily.
    • Example of exported variable: export(int) var HP = 3

Adding New Enemies

  • Use scene inheritance to create variations of enemies easily:
    • Inherit from the base enemy scene (enemy.tscn).
    • Modify properties without changing base code.
    • Use unique scripts for distinct behaviors (e.g., enemy dash).

Random Enemy Spawning

  • Use an export array to hold different enemy packed scenes.
  • Randomize enemy selection using a new variable for enemy number.
  • Code Snippet for random selection: enemy_number = randi() % enemies.size()

Final Notes

  • Refactor improves flexibility and ease of adding content.
  • Future work includes addressing blood particle colors and fading effects.
  • Encourage students to explore and expand upon these concepts in their projects.