DEV Community

Cover image for Let’s Learn Godot 4 by Making an RPG — Part 15: Player Death & Game Over🤠
christine
christine

Posted on • Updated on

Let’s Learn Godot 4 by Making an RPG — Part 15: Player Death & Game Over🤠

Now that our player can be damaged by our enemies, we can go ahead and implement the functionality so that they can die, and if they have died, the game is over, and a game-over screen is displayed. Later on, we’ll build on this game-over system so that we get redirected toward the Main Menu screen.


WHAT YOU WILL LEARN IN THIS PART:
· Further practice with the AnimationPlayer node.
· Further practice with the CanvasLayer nodes.


In your Player scene, add a new Label and ColorRect to your UI node. Rename the ColorRect to “GameOver”. It should look like this:

Godot RPG

Change the GameOver node’s size to the size of your game window (x: 320, y: 180). Also, change its Color property to #d6c376.

Godot RPG

Select your Label node and change its text to “GAME OVER!!!”. Make sure that it is in uppercase, and change the anchor preset to be centered.

Godot RPG

Let’s assign a new Font to this label. Underneath Control > Theme Overrides > Fonts, Quick Load a new font and select the font to be “Schrödinger.tff”. Set the font size to 20.

Godot RPG

Now hide your GameOver node by clicking on the eye icon next to it.

Godot RPG

In your Animations panel at the bottom window, create a new animation by clicking on the Animation label. Call this animation “game_over”.

Godot RPG

Godot RPG

For this animation, we want our game over screen to slowly be revealed if our player dies. Therefore, we will change the ColorRect node’s (GameOver) modulate property. Add a new Property Track and connect it to your GameOver node.

Godot RPG

Select the modulate value property and add two keys — one at keyframe 0 and the other one at keyframe 1.

Godot RPG

Godot RPG

Select the first keyframe (0) and change the Alpha value in your Value property to 0. This is because we want the window to go from invisible to visible. You can play the animation to see the effect we’re going for.

Godot RPG

Now in your Player’s damage code underneath our death conditional, let’s play this animation.

    ### Player.gd

    # older code

    # ------------------- Damage & Death ------------------------------
    #does damage to our player
    func hit(damage):
        health -= damage    
        health_updated.emit(health, max_health)
        if health > 0:
            #damage
            animation_player.play("damage")
            health_updated.emit(health, max_health)
        else:
            #death
            set_process(false)
            animation_player.play("game_over")
Enter fullscreen mode Exit fullscreen mode

If you run your scene and your player gets shot enough times for its health value to fall below 0, your game over screen should show. We’ll make this screen pausable later on when we return it to our main screen.

Godot RPG

Now our player can “die” and the game notifies us that our game is over. We’ll build on this in the next few parts to improve on this system, but in the next part, we’re going to add our Level and XP functionalities which will increase our XP and Levels after completing quests or killing enemies. Remember to save your project, and I’ll see you in the next part.

Your final source code for this part should look like this.

Buy Me a Coffee at ko-fi.com

FULL TUTORIAL

Godot RPG

The tutorial series has 23 chapters. I’ll be releasing all of the chapters in sectional daily parts over the next couple of weeks.

If you like this series or want to skip the wait and access the offline, full version of the tutorial series, you can support me by buying the offline booklet for just $4 on Ko-fi!😊

You can find the updated list of the tutorial links for all 23 parts in this series here.

Top comments (14)

Collapse
 
mxglt profile image
Maxime Guilbert

Really cool as usual! :)
I really want to start a new project in Godot with your tutorial hehe

Collapse
 
christinec_dev profile image
christine

Thank you! What are you currently working on? 😊

Collapse
 
mxglt profile image
Maxime Guilbert

Not a video game haha
I'm following game dev tutorial because I'm curious and I would like to do something one day ^^

And you? Are you working on a game project?

Thread Thread
 
christinec_dev profile image
christine

I'm working on a side game project, but I honestly haven't had too much time for it since I'm finishing up another tutorial series! 😬

Thread Thread
 
mxglt profile image
Maxime Guilbert

It's always complicated to find time for side projects hehe

Does the new tutorial is on Godot?

Thread Thread
 
christinec_dev profile image
christine

Yes.😅 I plan on one day making written series on Unity and UE game projects too, but for now, I'm having too much fun with Godot.

Thread Thread
 
mxglt profile image
Maxime Guilbert

Nice! I'm impatient to read it!

Collapse
 
Sloan, the sloth mascot
Comment deleted
Collapse
 
Sloan, the sloth mascot
Comment deleted
 
Sloan, the sloth mascot
Comment deleted
 
Sloan, the sloth mascot
Comment deleted
 
Sloan, the sloth mascot
Comment deleted
Collapse
 
edenwheeler profile image
Eden Wheeler

It's really helpful. Thanks for sharing this amazing article. learn r for data science

Collapse
 
rachelfazio profile image
Rachel Fazio

Super cool!