Health meter
This commit is contained in:
parent
edadd138b0
commit
0f5e075a54
|
@ -4,6 +4,7 @@ class_name PlayerStats
|
||||||
var max_health = 4
|
var max_health = 4
|
||||||
var health = max_health setget set_health
|
var health = max_health setget set_health
|
||||||
|
|
||||||
|
signal player_health_changed(value)
|
||||||
signal player_died
|
signal player_died
|
||||||
|
|
||||||
func set_health(value):
|
func set_health(value):
|
||||||
|
@ -11,6 +12,7 @@ func set_health(value):
|
||||||
Events.emit_signal("add_screenshake", 0.5, 0.5)
|
Events.emit_signal("add_screenshake", 0.5, 0.5)
|
||||||
|
|
||||||
health = clamp(value, 0, max_health)
|
health = clamp(value, 0, max_health)
|
||||||
|
emit_signal("player_health_changed", health)
|
||||||
|
|
||||||
if health == 0:
|
if health == 0:
|
||||||
emit_signal("player_died")
|
emit_signal("player_died")
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
extends Control
|
||||||
|
|
||||||
|
var PlayerStats = ResourceLoader.PlayerStats
|
||||||
|
|
||||||
|
onready var full = $Full
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
PlayerStats.connect("player_health_changed", self, "_on_player_health_changed")
|
||||||
|
|
||||||
|
|
||||||
|
func _on_player_health_changed(value):
|
||||||
|
full.rect_size.x = value * 5 + 1
|
|
@ -0,0 +1,27 @@
|
||||||
|
[gd_scene load_steps=4 format=2]
|
||||||
|
|
||||||
|
[ext_resource path="res://Assets/UI/HealthMeterEmpty.png" type="Texture" id=1]
|
||||||
|
[ext_resource path="res://Assets/UI/HealthMeter.png" type="Texture" id=2]
|
||||||
|
[ext_resource path="res://Scenes/UI/HealthMeter.gd" type="Script" id=3]
|
||||||
|
|
||||||
|
[node name="HealthMeter" type="Control"]
|
||||||
|
margin_right = 21.0
|
||||||
|
margin_bottom = 12.0
|
||||||
|
script = ExtResource( 3 )
|
||||||
|
__meta__ = {
|
||||||
|
"_edit_use_anchors_": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[node name="Empty" type="TextureRect" parent="."]
|
||||||
|
margin_right = 21.0
|
||||||
|
margin_bottom = 12.0
|
||||||
|
texture = ExtResource( 1 )
|
||||||
|
expand = true
|
||||||
|
stretch_mode = 2
|
||||||
|
|
||||||
|
[node name="Full" type="TextureRect" parent="."]
|
||||||
|
margin_right = 21.0
|
||||||
|
margin_bottom = 12.0
|
||||||
|
texture = ExtResource( 2 )
|
||||||
|
expand = true
|
||||||
|
stretch_mode = 2
|
|
@ -1,15 +1,11 @@
|
||||||
[gd_scene load_steps=2 format=2]
|
[gd_scene load_steps=2 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://Assets/UI/HealthMeterEmpty.png" type="Texture" id=1]
|
[ext_resource path="res://Scenes/UI/HealthMeter.tscn" type="PackedScene" id=1]
|
||||||
|
|
||||||
[node name="UI" type="CanvasLayer"]
|
[node name="UI" type="CanvasLayer"]
|
||||||
|
|
||||||
[node name="TextureRect" type="TextureRect" parent="."]
|
[node name="HealthMeter" parent="." instance=ExtResource( 1 )]
|
||||||
margin_left = 32.0
|
margin_left = 4.0
|
||||||
margin_top = 24.0
|
margin_top = 4.0
|
||||||
margin_right = 72.0
|
margin_right = 25.0
|
||||||
margin_bottom = 64.0
|
margin_bottom = 16.0
|
||||||
texture = ExtResource( 1 )
|
|
||||||
__meta__ = {
|
|
||||||
"_edit_use_anchors_": false
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue