game: add xp orbs

This commit is contained in:
2025-08-19 15:31:32 +02:00
parent 8fc3cf4838
commit 42fd207906
4 changed files with 22 additions and 0 deletions

View File

@@ -15,6 +15,7 @@ var max_health: float
var god_mode: bool = false
var is_dead: bool = false
var _xp_orb = preload("res://scenes/xp_orb.tscn")
func _ready() -> void:
move_speed = default_move_speed
@@ -57,11 +58,17 @@ func die():
if is_dead:
return
is_dead = true
drop_xp_orb()
target = null
velocity = Vector2.ZERO
animation_player.play("die")
animation_player.animation_finished.connect(_on_die_anim_finished)
func drop_xp_orb() -> void:
var orb: XPOrb = _xp_orb.instantiate()
orb.value = 5
orb.position = position
get_parent().add_child(orb)
func cheer_anim():
if not animation_player.is_playing():

4
scenes/xp_orb.gd Normal file
View File

@@ -0,0 +1,4 @@
class_name XPOrb
extends Node2D
@export var value: float

1
scenes/xp_orb.gd.uid Normal file
View File

@@ -0,0 +1 @@
uid://bx43us4qd2vpf

10
scenes/xp_orb.tscn Normal file
View File

@@ -0,0 +1,10 @@
[gd_scene load_steps=3 format=3 uid="uid://du4dqne3o0d5b"]
[ext_resource type="Script" uid="uid://bx43us4qd2vpf" path="res://scenes/xp_orb.gd" id="1_me6n8"]
[ext_resource type="Texture2D" uid="uid://crty0t7ryksqn" path="res://assets/sprites/xp_orb.png" id="1_pkphv"]
[node name="XPOrb" type="Node2D"]
script = ExtResource("1_me6n8")
[node name="Sprite2D" type="Sprite2D" parent="."]
texture = ExtResource("1_pkphv")