mirror of
https://github.com/Rundll86/Dog-Lynx-And-HCN.git
synced 2026-06-09 13:17:12 +08:00
feat(障碍物系统): 添加草墙障碍物及相关功能
实现草墙障碍物系统,包括以下主要变更: - 新增草墙障碍物资源、脚本和场景 - 添加障碍物状态显示UI - 扩展组件管理器支持障碍物类型 - 修改子弹系统以支持对障碍物的碰撞检测 - 调整实体碰撞层设置 - 为公鸡角色添加草墙武器 新增功能允许玩家放置可阻挡敌人的草墙障碍物,并显示其生命值状态
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
extends StaticBody2D
|
||||
class_name ObstacleBase
|
||||
|
||||
signal healthChanged(newHealth: float)
|
||||
|
||||
@export var healthMax: float = 100
|
||||
@export var penerateResistance: float = 0
|
||||
@export var blockPlayer: bool = false
|
||||
@export var blockEnemy: bool = false
|
||||
|
||||
@onready var statebar: ObstacleStateBar = $%statebar
|
||||
@onready var texture: AnimatedSprite2D = $%texture
|
||||
@onready var hitbox: CollisionShape2D = $%hitbox
|
||||
var health: float = 0
|
||||
var launcher: EntityBase = null
|
||||
|
||||
func _ready():
|
||||
health = healthMax
|
||||
if blockPlayer:
|
||||
collision_layer |= EntityBase.Layers.PLAYER
|
||||
collision_mask |= EntityBase.Layers.PLAYER
|
||||
if blockEnemy:
|
||||
collision_layer |= EntityBase.Layers.ENEMY
|
||||
collision_mask |= EntityBase.Layers.ENEMY
|
||||
healthChanged.connect(
|
||||
func(newHealth):
|
||||
statebar.healthBar.maxValue = healthMax
|
||||
statebar.healthBar.setCurrent(newHealth)
|
||||
)
|
||||
func _process(_delta):
|
||||
statebar.global_rotation = 0
|
||||
statebar.applyText()
|
||||
|
||||
func initHealth(maxHealth: float):
|
||||
healthMax = maxHealth
|
||||
health = healthMax
|
||||
statebar.forceSync()
|
||||
statebar.applyText()
|
||||
func takeDamage(damage: float):
|
||||
health -= damage
|
||||
healthChanged.emit(health)
|
||||
if health <= 0:
|
||||
tryDie()
|
||||
func tryDie():
|
||||
die()
|
||||
queue_free()
|
||||
|
||||
func die():
|
||||
pass
|
||||
|
||||
static func generate(
|
||||
obstacle: PackedScene,
|
||||
spawnPosition: Vector2,
|
||||
spawnRotation: float = 0,
|
||||
itsLauncher: EntityBase = null,
|
||||
addToWorld: bool = true
|
||||
) -> ObstacleBase:
|
||||
var instance: ObstacleBase = obstacle.instantiate()
|
||||
instance.position = spawnPosition
|
||||
instance.rotation = spawnRotation
|
||||
instance.launcher = itsLauncher
|
||||
if addToWorld:
|
||||
WorldManager.rootNode.spawn(instance)
|
||||
return instance
|
||||
Reference in New Issue
Block a user