Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Godot Engine Game Development Projects

You're reading from   Godot Engine Game Development Projects Build five cross-platform 2D and 3D games with Godot 3.0

Arrow left icon
Product type Paperback
Published in Jun 2018
Publisher Packt
ISBN-13 9781788831505
Length 298 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Chris Bradfield Chris Bradfield
Author Profile Icon Chris Bradfield
Chris Bradfield
Arrow right icon
View More author details
Toc

Game over

In this section, you'll make the player detect when it is hit by rocks, add an invulnerability feature, and end the game when the player runs out of lives.

Add an instance of the Explosion to the Player, as well as a Timer node (named InvulnerabilityTimer). In the Inspector, set the Wait Time of InvulnerabilityTimer to 2 and its One Shot to On. Add this to the top of Player.gd:

signal dead

This signal will notify the Main scene that the player has run out of lives and the game is over. Before that, however, you need to update the state machine to do a little more with each state:

func change_state(new_state):
match new_state:
INIT:
$CollisionShape2D.disabled = true
$Sprite.modulate.a = 0.5
ALIVE:
$CollisionShape2D.disabled = false
$Sprite.modulate.a = 1.0
INVULNERABLE:
$CollisionShape2D...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime