Add player health and bar
This commit is contained in:
parent
41e55a464f
commit
16e6affb3c
12
player.gd
12
player.gd
|
@ -1,5 +1,9 @@
|
|||
extends CharacterBody2D
|
||||
|
||||
signal health_depleted
|
||||
|
||||
var health = 100.0
|
||||
|
||||
|
||||
func _physics_process(delta):
|
||||
var direction = Input.get_vector("move_left", "move_right", "move_up", "move_down")
|
||||
|
@ -12,3 +16,11 @@ func _physics_process(delta):
|
|||
%HappyBoo.play_walk_animation()
|
||||
else:
|
||||
%HappyBoo.play_idle_animation()
|
||||
|
||||
const DAMAGE_RATE = 5.0
|
||||
var overlapping_mobs = %HurtBox.get_overlapping_bodies()
|
||||
if overlapping_mobs.size() > 0:
|
||||
health -= DAMAGE_RATE * overlapping_mobs.size() * delta
|
||||
(%ProgressBar as ProgressBar).value = health
|
||||
if health <= 0.0:
|
||||
health_depleted.emit()
|
||||
|
|
39
player.tscn
39
player.tscn
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=5 format=3 uid="uid://ba1onw8ja6l24"]
|
||||
[gd_scene load_steps=8 format=3 uid="uid://ba1onw8ja6l24"]
|
||||
|
||||
[ext_resource type="Script" path="res://player.gd" id="1_htfuq"]
|
||||
[ext_resource type="PackedScene" uid="uid://pbmyh1qru7p" path="res://characters/happy_boo/happy_boo.tscn" id="1_yispp"]
|
||||
|
@ -7,6 +7,23 @@
|
|||
[sub_resource type="CircleShape2D" id="CircleShape2D_53acx"]
|
||||
radius = 31.0
|
||||
|
||||
[sub_resource type="CircleShape2D" id="CircleShape2D_mkwpp"]
|
||||
radius = 36.1386
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_5tf3q"]
|
||||
bg_color = Color(0.152941, 0.168627, 0.188235, 1)
|
||||
corner_radius_top_left = 8
|
||||
corner_radius_top_right = 8
|
||||
corner_radius_bottom_right = 8
|
||||
corner_radius_bottom_left = 8
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_npai3"]
|
||||
bg_color = Color(0.623529, 0.866667, 0.317647, 1)
|
||||
corner_radius_top_left = 8
|
||||
corner_radius_top_right = 8
|
||||
corner_radius_bottom_right = 8
|
||||
corner_radius_bottom_left = 8
|
||||
|
||||
[node name="Player" type="CharacterBody2D"]
|
||||
script = ExtResource("1_htfuq")
|
||||
|
||||
|
@ -20,3 +37,23 @@ shape = SubResource("CircleShape2D_53acx")
|
|||
|
||||
[node name="Gun" parent="." instance=ExtResource("3_2xdlw")]
|
||||
position = Vector2(0, -53)
|
||||
|
||||
[node name="HurtBox" type="Area2D" parent="."]
|
||||
unique_name_in_owner = true
|
||||
collision_layer = 0
|
||||
collision_mask = 2
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="HurtBox"]
|
||||
shape = SubResource("CircleShape2D_mkwpp")
|
||||
debug_color = Color(0.792157, 0.376471, 0.545098, 0.419608)
|
||||
|
||||
[node name="ProgressBar" type="ProgressBar" parent="."]
|
||||
unique_name_in_owner = true
|
||||
offset_left = -88.0
|
||||
offset_top = -137.0
|
||||
offset_right = 92.0
|
||||
offset_bottom = -110.0
|
||||
theme_override_styles/background = SubResource("StyleBoxFlat_5tf3q")
|
||||
theme_override_styles/fill = SubResource("StyleBoxFlat_npai3")
|
||||
value = 100.0
|
||||
show_percentage = false
|
||||
|
|
Loading…
Reference in New Issue