3c6f31b503
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
59 lines
1.6 KiB
GDScript
59 lines
1.6 KiB
GDScript
class_name EnemyFortress
|
|
extends EnemyBase
|
|
## 地面固定堡垒:随地面同速下滚,炮塔持续追踪玩家并瞄准射击。
|
|
|
|
const TEX := preload("res://assets/svg/fortress.svg")
|
|
const TURRET_TEX := preload("res://assets/svg/fortress_turret.svg")
|
|
const SCROLL_SPEED := 120.0
|
|
const MUZZLE_LEN := 26.0
|
|
|
|
var difficulty := 1.0
|
|
var fire_interval := 2.6
|
|
var bullet_speed := 220.0
|
|
|
|
var _turret: Sprite2D
|
|
var _fire_timer := 0.0
|
|
|
|
|
|
func setup(p_x: float, p_y: float, p_difficulty := 1.0) -> void:
|
|
position = Vector2(p_x, p_y)
|
|
difficulty = p_difficulty
|
|
fire_interval = maxf(1.5, 2.6 / p_difficulty)
|
|
bullet_speed = 220.0 * p_difficulty
|
|
|
|
|
|
func _ready() -> void:
|
|
# 层 32:地面单位——玩家子弹可命中,但玩家机体不与其碰撞(飞越上空)
|
|
collision_layer = 32
|
|
collision_mask = 0
|
|
hp = 4
|
|
score_value = 300
|
|
hit_radius = 26.0
|
|
var base := Sprite2D.new()
|
|
base.texture = TEX
|
|
add_child(base)
|
|
_turret = Sprite2D.new()
|
|
_turret.texture = TURRET_TEX
|
|
add_child(_turret)
|
|
var shape := CollisionShape2D.new()
|
|
var circle := CircleShape2D.new()
|
|
circle.radius = 24.0
|
|
shape.shape = circle
|
|
add_child(shape)
|
|
_fire_timer = randf_range(0.8, 1.8)
|
|
|
|
|
|
func _process(delta: float) -> void:
|
|
position.y += SCROLL_SPEED * delta
|
|
if position.y > 1020.0:
|
|
queue_free()
|
|
return
|
|
var dir := _aim_direction()
|
|
# 炮塔美术默认朝下(+Y):rotate 对齐瞄准方向
|
|
_turret.rotation = dir.angle() - PI / 2.0
|
|
if position.y > 60.0 and position.y < 720.0:
|
|
_fire_timer -= delta
|
|
if _fire_timer <= 0.0:
|
|
_fire_timer = fire_interval
|
|
_fire_bullet(dir * bullet_speed, dir * MUZZLE_LEN)
|