mirror of
https://github.com/Rundll86/Dog-Lynx-And-HCN.git
synced 2026-05-28 06:51:54 +08:00
Add sound effects and character scripts
- Imported new sound effects: "Low Boing", "Low Whoosh", and "Pew" with corresponding import files. - Created a new character script for "Hen" with basic AI and attack functionality. - Implemented an effect controller script for managing particle effects with one-shot functionality.
This commit is contained in:
@@ -4,7 +4,7 @@ class_name Chick
|
||||
var angle = 0
|
||||
func _ready():
|
||||
fields[FieldStore.Entity.MAX_HEALTH] = 1000
|
||||
fields[FieldStore.Entity.MOVEMENT_SPEED] = 0.25
|
||||
fields[FieldStore.Entity.MOVEMENT_SPEED] = 0.1
|
||||
super._ready()
|
||||
|
||||
func ai():
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
extends EntityBase
|
||||
class_name Hen
|
||||
|
||||
func _ready():
|
||||
fields[FieldStore.Entity.MAX_HEALTH] = 75
|
||||
fields[FieldStore.Entity.MOVEMENT_SPEED] = 0.25
|
||||
super._ready()
|
||||
|
||||
func ai():
|
||||
move(currentFocusedBoss.position - position)
|
||||
tryAttack(0)
|
||||
func attack(type):
|
||||
if type == 0:
|
||||
var weaponPos = findWeaponAnchor("normal")
|
||||
BulletBase.generate(preload("res://components/Bullets/HenBomb.tscn"), self, weaponPos, 0)
|
||||
@@ -22,4 +22,4 @@ func sprint():
|
||||
move(Vector2(
|
||||
Input.get_axis("m_left", "m_right"),
|
||||
Input.get_axis("m_up", "m_down")
|
||||
) * 8, true)
|
||||
) * sprintMultiplier, true)
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
extends Node2D
|
||||
class_name EffectController
|
||||
|
||||
@export var oneShot: bool = true
|
||||
|
||||
@onready var particles: GPUParticles2D = $"%particles"
|
||||
|
||||
func _ready():
|
||||
particles.emitting = false
|
||||
particles.one_shot = oneShot
|
||||
func shot():
|
||||
var cloned = particles.duplicate() as GPUParticles2D
|
||||
cloned.emitting = true
|
||||
add_child(cloned)
|
||||
if oneShot:
|
||||
await cloned.finished
|
||||
cloned.queue_free()
|
||||
@@ -10,15 +10,17 @@ var fields = {
|
||||
FieldStore.Entity.CRIT_DAMAGE: 1,
|
||||
FieldStore.Entity.PENERATE: 0,
|
||||
}
|
||||
var cooldownUnit: float = 100 # 100毫秒每次攻击
|
||||
|
||||
@export var cooldownUnit: float = 100 # 100毫秒每次攻击
|
||||
@export var isBoss: bool = false
|
||||
@export var displayName: String = "未知实体"
|
||||
@export var sprintMultiplier: float = 7
|
||||
|
||||
@onready var animatree: AnimationTree = $"%animatree"
|
||||
@onready var texture: AnimatedSprite2D = $"%texture"
|
||||
@onready var hurtbox: Area2D = $"%hurtbox"
|
||||
@onready var statebar: EntityStateBar = $"%statebar"
|
||||
@onready var sounds: Node2D = $"%sounds"
|
||||
|
||||
var health: float = 0
|
||||
|
||||
@@ -47,8 +49,10 @@ func _physics_process(_delta: float) -> void:
|
||||
move_and_slide()
|
||||
|
||||
# 通用方法
|
||||
func displace(direction: Vector2, isSprinting: bool = false):
|
||||
return (direction if isSprinting else direction.normalized()) * fields.get(FieldStore.Entity.MOVEMENT_SPEED) * 400 * 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"))
|
||||
velocity = displace(direction, isSprinting)
|
||||
var currentDirection = sign(direction.x)
|
||||
if currentDirection != 0:
|
||||
lastDirection = currentDirection
|
||||
@@ -56,7 +60,10 @@ 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:
|
||||
playSound("miss")
|
||||
damage = 0
|
||||
else:
|
||||
playSound("hurt")
|
||||
health -= damage
|
||||
DamageLabel.create(damage, crit, $"%damageAnchor".global_position + MathTool.randv2_range(GameRule.damageLabelSpawnOffset))
|
||||
if isBoss:
|
||||
@@ -75,9 +82,11 @@ func startCooldown():
|
||||
func tryAttack(type: int):
|
||||
var state = startCooldown()
|
||||
if state:
|
||||
playSound("attack")
|
||||
attack(type)
|
||||
return state
|
||||
func trySprint():
|
||||
playSound("sprint")
|
||||
sprint()
|
||||
sprinting = true
|
||||
func findWeaponAnchor(weaponName: String):
|
||||
@@ -90,6 +99,14 @@ func setBoss(boss: EntityBase):
|
||||
currentFocusedBoss = boss
|
||||
if isPlayer():
|
||||
UIState.bossbar.entity = boss
|
||||
func playSound(type: String):
|
||||
var body = sounds.get_node_or_null(type)
|
||||
if body is AudioStreamPlayer2D:
|
||||
var cloned = body.duplicate() as AudioStreamPlayer2D
|
||||
add_child(cloned)
|
||||
cloned.play()
|
||||
await cloned.finished
|
||||
cloned.queue_free()
|
||||
|
||||
# 关于分组
|
||||
func isPlayer():
|
||||
|
||||
Reference in New Issue
Block a user