Health and killing zones

This commit is contained in:
2024-10-28 10:25:07 +01:00
parent e242f59c0b
commit a15966a361
9 changed files with 42 additions and 47 deletions

View File

@ -1,13 +1,15 @@
extends CharacterBody2D
const SPEED = 400.0
const JUMP_VELOCITY = -400.0
var jumped = false
@onready var animation = get_node("AnimatedSprite2D")
@onready var healthBar: ProgressBar = $ProgressBar
var health = 100
func _ready() -> void:
animation.play("idle")
@ -47,3 +49,13 @@ func _physics_process(delta: float) -> void:
#print("DEAD")
move_and_slide()
func _on_enemy_hurt() -> void:
if health - 50 == 0:
get_tree().reload_current_scene()
else:
health -= 50
healthBar.value -= 50

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=28 format=3 uid="uid://cwhk7ysxws0s0"]
[gd_scene load_steps=30 format=3 uid="uid://cwhk7ysxws0s0"]
[ext_resource type="Script" path="res://scenes/Game/Player/player.gd" id="1_f437e"]
[ext_resource type="Texture2D" uid="uid://uobvqa86mtra" path="res://assets/Sunny Land Collection Files/Sunny Land Collection Files/Assets/Characters/Players/Squirrel/idle/spritesheet.png" id="2_r3s32"]
@ -173,6 +173,12 @@ animations = [{
radius = 8.0
height = 24.0
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_nv1uy"]
bg_color = Color(1, 0, 0, 1)
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_qoc3s"]
bg_color = Color(0, 1, 0, 1)
[node name="Player" type="CharacterBody2D"]
script = ExtResource("1_f437e")
@ -185,3 +191,13 @@ autoplay = "idle"
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2(1, -11)
shape = SubResource("CapsuleShape2D_gqjua")
[node name="ProgressBar" type="ProgressBar" parent="."]
offset_left = -14.0
offset_top = -33.0
offset_right = 12.0
offset_bottom = -27.0
theme_override_styles/background = SubResource("StyleBoxFlat_nv1uy")
theme_override_styles/fill = SubResource("StyleBoxFlat_qoc3s")
value = 100.0
show_percentage = false