mirror of
https://github.com/Rundll86/Dog-Lynx-And-HCN.git
synced 2026-05-28 06:51:54 +08:00
6b7801e1ce
- 在ObstacleBase和EntityBase中添加getHealthPercent方法用于获取生命值百分比 - 修改bulletHit方法支持伤害覆盖参数 - 为BigLaser武器添加5个升华选项,包括临界斩杀效果 - 实现damageOverride方法根据目标生命值动态调整伤害 - 修复store数值可能为负数的问题
67 lines
1.6 KiB
GDScript
67 lines
1.6 KiB
GDScript
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 getHealthPercent():
|
|
return health / healthMax
|
|
|
|
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
|