June 2018
Beginner to intermediate
298 pages
7h 38m
English
Eventually, the player is going to encounter danger, so you should add a damage system. The player will start with three hearts and lose one each time they are damaged.
Add the following to the top of the script:
signal life_changedsignal deadvar life
The life_changed signal will be emitted whenever the value of life changes, notifying the display to update. dead will be emitted when life reaches 0. Add these two lines to the start() function:
life = 3 emit_signal('life_changed', life)
There are two possible ways for the player to be hurt: running into a spike object in the environment, or being hit by an enemy. In either event, the following function can be called:
func hurt(): if state != HURT: change_state(HURT)
This is ...
Read now
Unlock full access