September 4, 2024

How to Add an Enemy Attack and Player Reset on Rosebud AI

Create a game without coding skills!
CREATE A GAME NOW

This tutorial was put together by our community member shawnBuilds for Rosebud AI, the AI-powered game creation platform. Check out shawn’s games here, and join our Discord to find more tutorials and connect with other creators!

Hey there! Today we're going to create a simple top-down shooter game where enemies can hurt the player, and the player can die when their health runs out.

We'll work with Rosie to help us set up a health system, collision detection, and a user-friendly developer tools interface.

You can try out the starting project below to see what we're working with:

Setup Project Link

Right now, our game has:

  • A white circle as the player, which you can move around with WASD keys
  • Red circles as enemies that follow the player around
  • No health system or collision detection yet

Let's change that!

Step #1: Player Health System

First, we'll give our player some health and create a developer tools system with a UI to help us test and debug.Ask Rosie to:

  1. Update the player to have health (3 health), and the ability to take damage and die.
  2. Create a developer tools system that includes:
    • A text display showing the player's current health
    • A button labeled "Damage Player" that, when clicked, makes the player take 1 damage
  3. Make sure the developer tools can function whether the player is alive or dead.

Here is the result:

  • The player's health displayed in the developer tools UI.
  • A "Damage Player" button in the developer tools UI.
  • Clicking the button reduces the player's health by 1.
  • The player disappears when health reaches 0.
  • The developer tools continue to work even when the player is "dead".

Best Practice:

  • Developer tools allow us to test the health system even before we've implemented enemies, making it easier to develop and debug in stages.

Step #2: Player Reset

Now let's add a way to bring our player back to life using our developer tools.Ask Rosie to:

  1. Add a reset function to the player that restores their initial position and full health.
  2. Update the developer tools to include:
    • A button labeled "Reset Player" that triggers the player reset function

Here is the result:

  • A new "Reset Player" button in the developer tools UI.
  • Clicking this button resets the player to their starting position with full health (3).
  • This works even if the player was previously "dead".

Best Practice:

  • We added a way to restart the player after death. This way, you can keep playing without restarting the whole game.

Step #3: Enemy-Player Collision and Attack

Finally, let's make those enemies dangerous and expand our developer tools to give us more control and information.Ask Rosie to:

  1. Implement collision between enemies and the player:
    • Player takes 1 damage on collision
    • Colliding enemy is removed
  2. Expand the developer tools to include:
    • A button labeled "Spawn Enemy" that creates a new enemy when clicked
    • A text display showing the number of active enemies
    • A text display showing the total collisions that have occurred

Here is the result:

  • Enemies (red circles) damage the player on contact and disappear.
  • The developer tools UI now includes:
    • A "Spawn Enemy" button to create new enemies on demand
    • Text displays showing active enemy count and total collisions
  • All developer tools work even if the player is "dead" or all enemies are gone.

Best Practice:

  • One-hit enemy removal simplifies the initial development requirements but leaves room for expanding the combat system, like creating multi-hit enemies.

Finished Project

Here's a finished project link so you can see how it all comes together: Finished Project Link

Great job! You've created a game with enemies, player health, and a handy set of developer tools with a user-friendly UI. This setup gives you a solid foundation to build upon and easily test your game mechanics. With your new debugging superpowers, the possibilities are endless. Happy game making!

Ready to turn your ideas into games?
GET STARTED NOW