Enhancing a Simple Game with the Framework

In my fourteenth video of the “Building a Game Development Framework” series, I continue developing the Shoot ‘Em Up game, introducing more complex enemy behaviors, advanced movement scripting, and visual color effects.

To improve the game feel, I add an immediate audio-visual feedback when an obstacle is destroyed:

  • Explosion Sound: A new sound effect is triggered the moment an obstacle is “hit.”
  • State Management: The hit() method sets the obstacle’s state to “destroyed,” plays the sound, and swaps its visual representation to a red box while it executes its scripted “easing out” death animation, where it slows down and disappears.

I create a new organizational class, the Enemy Manager, to oversee the spawning of both obstacles and the enemy ship.

  • Dynamic Spawning: The manager waits 10 seconds before spawning the first enemy ship from the top of the screen.
  • Randomized Patrols: To make the enemy ship more unpredictable, I build a Random Destination Action. This action uses “Suppliers” (a Java functional interface) to generate new random (X, Y) targets every time the ship reaches its previous goal.
  • Infinite Loops: By chaining the random movement with a GoToAction from the ScriptMovement, the enemy ship permanently patrols the top of the screen, weaving between random left and right positions.

I introduce a sophisticated Color Effect System to visually indicate damage without needing new sprite art:

  • Color Cycling: The ColorCycleEffect gradually transitions an actor’s color from its base color (e.g., Blue) to a “hit” color (Red) and back again over a set duration.
  • Linear Interpolation (Lerp): The system calculates the percentage of time elapsed and adjusts the RGB values incrementally. This creates a smooth “flash” effect rather than a jarring color swap.
  • Framework Integration: The BaseAnimation and Motion classes were updated to support these effects, ensuring that any actor—whether a single-frame sprite or a multi-directional animation—can utilize the Effects. The Effects can be translucency to color changes.

A BaseShip abstract class is created to centralize the logic for both the player and the enemy:

  • Hit Protection: A “hit” flag ensures that if a ship is hit multiple times rapidly, the color flash effect doesn’t constantly restart; it must finish its cycle before flashing again.
  • Max Hits (HP): Each ship now has a MaxHits variable. The player is given 10 HP, while the enemy ship has 5 HP. When HP reaches zero, the Actor is removed from the screen.

I refined the collision checks to ensure that game objects only interact with what they are supposed to:

  • Laser Logic: Lasers now check if they’ve hit an EnemyShip. If so, they trigger the ship’s hit() method and remove themselves.
  • Obstacle Logic: Obstacles check if they’ve collided with the player’s ship to deal damage, but they ignore the enemy ship so that the enemies don’t accidentally destroy their own falling obstacles or get destroyed by them.

By the end of this session, the game has a sophisticated AI enemy that patrols the screen, takes damage with a visual flash, and eventually dies after a set number of hits.

The Gdx2DGameFramework can be found here on github.