diff --git a/components/Characters/Chick.tscn b/components/Characters/Chick.tscn index b2a2bbe..6dd954a 100644 --- a/components/Characters/Chick.tscn +++ b/components/Characters/Chick.tscn @@ -32,6 +32,7 @@ size = Vector2(19.5, 14) [node name="Chick" instance=ExtResource("1_goqmy")] script = ExtResource("2_r6bub") +displayName = "小鸡" [node name="texture" parent="." index="0"] position = Vector2(0, -37) diff --git a/components/UI/BossBar.tscn b/components/UI/BossBar.tscn index 333930c..1bb4532 100644 --- a/components/UI/BossBar.tscn +++ b/components/UI/BossBar.tscn @@ -1,8 +1,15 @@ -[gd_scene load_steps=3 format=3 uid="uid://ofpg5s3j7esv"] +[gd_scene load_steps=5 format=3 uid="uid://ofpg5s3j7esv"] -[ext_resource type="Script" path="res://scripts/Statemachine/EntityStateBar.gd" id="1_q4vrr"] +[ext_resource type="Script" path="res://scripts/Statemachine/BossBar.gd" id="1_hkj6o"] [ext_resource type="PackedScene" uid="uid://d1ulrvupa76ap" path="res://components/UI/ColorBar.tscn" id="1_uxey7"] +[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_ar00p"] +content_margin_left = 10.0 + +[sub_resource type="LabelSettings" id="LabelSettings_55nrw"] +font_size = 14 +font_color = Color(0, 0, 0, 1) + [node name="BossBar" type="Control"] layout_mode = 3 anchors_preset = 15 @@ -10,7 +17,7 @@ anchor_right = 1.0 anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 -script = ExtResource("1_q4vrr") +script = ExtResource("1_hkj6o") [node name="health" parent="." instance=ExtResource("1_uxey7")] unique_name_in_owner = true @@ -25,3 +32,32 @@ offset_right = 0.0 offset_bottom = -20.0 grow_horizontal = 2 grow_vertical = 0 + +[node name="panel" type="PanelContainer" parent="health"] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +theme_override_styles/panel = SubResource("StyleBoxEmpty_ar00p") + +[node name="label" type="HBoxContainer" parent="health/panel"] +layout_mode = 2 + +[node name="name" type="Label" parent="health/panel/label"] +unique_name_in_owner = true +layout_mode = 2 +text = "BossName" +label_settings = SubResource("LabelSettings_55nrw") + +[node name="value" type="Label" parent="health/panel/label"] +unique_name_in_owner = true +layout_mode = 2 +text = "percent" +label_settings = SubResource("LabelSettings_55nrw") + +[node name="percent" type="Label" parent="health/panel/label"] +layout_mode = 2 +text = "%" +label_settings = SubResource("LabelSettings_55nrw") diff --git a/scripts/Contents/Characters/Rooster.gd b/scripts/Contents/Characters/Rooster.gd index 3a05283..37dd123 100644 --- a/scripts/Contents/Characters/Rooster.gd +++ b/scripts/Contents/Characters/Rooster.gd @@ -12,7 +12,14 @@ func ai(): texture.play("idle") if Input.is_action_pressed("attack"): tryAttack(0) + if Input.is_action_just_pressed("sprint"): + trySprint() func attack(type): if type == 0: var weaponPos = findWeaponAnchor("normal") BulletBase.generate(preload("res://components/Bullets/PurpleCrystal.tscn"), self, weaponPos, (get_global_mouse_position() - weaponPos).angle()) +func sprint(): + move(Vector2( + Input.get_axis("m_left", "m_right"), + Input.get_axis("m_up", "m_down") + ) * 6, true) diff --git a/scripts/Statemachine/BossBar.gd b/scripts/Statemachine/BossBar.gd new file mode 100644 index 0000000..7783e31 --- /dev/null +++ b/scripts/Statemachine/BossBar.gd @@ -0,0 +1,11 @@ +extends EntityStateBar +class_name BossBar + +@onready var nameLabel: Label = $"%name" +@onready var valueLabel: Label = $"%value" + +func _process(delta): + super._process(delta) + if entity: + nameLabel.text = entity.displayName + valueLabel.text = "%.2f" % (entity.health / entity.fields[FieldStore.Entity.MAX_HEALTH] * 100) diff --git a/scripts/Statemachine/DamageLabel.gd b/scripts/Statemachine/DamageLabel.gd index 274137e..6ad40f3 100644 --- a/scripts/Statemachine/DamageLabel.gd +++ b/scripts/Statemachine/DamageLabel.gd @@ -3,10 +3,18 @@ class_name DamageLabel @export var damage: float = 0 @export var crit: bool = false + +@onready var label: Label = $"%label" +@onready var animator: AnimationPlayer = $"%animator" + func _ready(): - $"%label".text = str(round(damage)) + ("!!!" if crit else "") - $"%animator".play("show") - await $"%animator".animation_finished + if damage == 0: + label.text = "MISS" + else: + label.text = str(round(damage)) + ("!!!" if crit else "") + animator.play("show") + await animator.animation_finished + queue_free() static func create(spawnDamage: float, spawnCrit: bool, spawnPosition: Vector2, addToWorld: bool = true) -> DamageLabel: var instance = preload("res://components/UI/DamageLabel.tscn").instantiate() diff --git a/scripts/Statemachine/EntityBase.gd b/scripts/Statemachine/EntityBase.gd index 3e9b775..18b558c 100644 --- a/scripts/Statemachine/EntityBase.gd +++ b/scripts/Statemachine/EntityBase.gd @@ -13,6 +13,7 @@ var fields = { var cooldownUnit: float = 100 # 100毫秒每次攻击 @export var isBoss: bool = false +@export var displayName: String = "未知实体" @onready var animatree: AnimationTree = $"%animatree" @onready var texture: AnimatedSprite2D = $"%texture" @@ -33,19 +34,26 @@ func _process(_delta): health = clamp(health, 0, fields.get(FieldStore.Entity.MAX_HEALTH)) animatree.set("parameters/blend_position", lerpf(animatree.get("parameters/blend_position"), lastDirection, 0.1)) func _physics_process(_delta: float) -> void: - velocity = Vector2.ZERO - ai() + if sprinting: + velocity *= 0.9 + if velocity.length() <= 100: + sprinting = false + else: + velocity = Vector2.ZERO + ai() move_and_slide() # 通用方法 -func move(direction: Vector2): - velocity = direction.normalized() * fields.get(FieldStore.Entity.MOVEMENT_SPEED) * 200 * abs(animatree.get("parameters/blend_position")) +func move(direction: Vector2, isSprinting: bool = false): + velocity = (direction if isSprinting else direction.normalized()) * fields.get(FieldStore.Entity.MOVEMENT_SPEED) * 200 * abs(animatree.get("parameters/blend_position")) var currentDirection = sign(direction.x) if currentDirection != 0: lastDirection = currentDirection func takeDamage(bullet: BulletBase, crit: bool): var baseDamage: float = bullet.fields.get(FieldStore.Bullet.DAMAGE) * randf_range(1 - GameRule.damageOffset, 1 + GameRule.damageOffset) var damage = baseDamage + baseDamage * int(crit) * fields.get(FieldStore.Entity.CRIT_DAMAGE) + if sprinting: + damage = 0 health -= damage DamageLabel.create(damage, crit, $"%damageAnchor".global_position + MathTool.randv2_range(GameRule.damageLabelSpawnOffset)) if isBoss: @@ -64,6 +72,9 @@ func startCooldown(): func tryAttack(type: int): if startCooldown(): attack(type) +func trySprint(): + sprint() + sprinting = true func findWeaponAnchor(weaponName: String): var anchor = $"%weapons".get_node(weaponName) if anchor is Node2D: @@ -86,6 +97,8 @@ func attack(_type: int): pass func die(): queue_free() +func sprint(): + pass static func generate( entity: PackedScene,