Skip to Main Content
Godot Engine Game Development Projects
book

Godot Engine Game Development Projects

by Chris Bradfield
June 2018
Beginner to intermediate content levelBeginner to intermediate
298 pages
7h 38m
English
Packt Publishing
Content preview from Godot Engine Game Development Projects

Player shield

In this section, you'll add a shield to the player and a display element to the HUD showing the current shield level.

First, add the following to the top of the Player.gd script:

signal shield_changedexport (int) var max_shieldexport (float) var shield_regenvar shield = 0 setget set_shield

The shield variable will work similarly to lives, emitting a signal to the HUD whenever it changes. Save the script and set max_shield to 100 and shield_regen to 5 in the Inspector.

Next, add the following function, which handles changing the shield's value:

func set_shield(value):    if value > max_shield:        value = max_shield    shield = value    emit_signal("shield_changed", shield/max_shield)    if shield <= 0:        self.lives -= 1

Also, since some things, ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Game Development with Blender and Godot

Game Development with Blender and Godot

Kumsal Obuz
Unity Game Development Cookbook

Unity Game Development Cookbook

Paris Buttfield-Addison, Jon Manning, Tim Nugent

Publisher Resources

ISBN: 9781788831505Supplemental Content