3c6f31b503
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
52 lines
1.3 KiB
GDScript
52 lines
1.3 KiB
GDScript
class_name EnemyShip
|
|
extends EnemyBase
|
|
## 驱逐舰:随海面航行(比地面稍快),舰桥瞄准玩家射击。
|
|
|
|
const TEX := preload("res://assets/svg/ship.svg")
|
|
const MUZZLE := Vector2(0.0, 0.0)
|
|
|
|
var difficulty := 1.0
|
|
var scroll_speed := 160.0
|
|
var fire_interval := 2.4
|
|
var bullet_speed := 230.0
|
|
|
|
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
|
|
scroll_speed = 150.0 + 20.0 * p_difficulty
|
|
fire_interval = maxf(1.6, 2.4 / p_difficulty)
|
|
bullet_speed = 230.0 * p_difficulty
|
|
|
|
|
|
func _ready() -> void:
|
|
# 层 32:海面单位——玩家子弹可命中,但玩家机体不与其碰撞(飞越上空)
|
|
collision_layer = 32
|
|
collision_mask = 0
|
|
hp = 8
|
|
score_value = 800
|
|
hit_radius = 46.0
|
|
var sprite := Sprite2D.new()
|
|
sprite.texture = TEX
|
|
add_child(sprite)
|
|
var shape := CollisionShape2D.new()
|
|
var rect := RectangleShape2D.new()
|
|
rect.size = Vector2(38.0, 112.0)
|
|
shape.shape = rect
|
|
add_child(shape)
|
|
_fire_timer = randf_range(1.0, 2.2)
|
|
|
|
|
|
func _process(delta: float) -> void:
|
|
position.y += scroll_speed * delta
|
|
if position.y > 1100.0:
|
|
queue_free()
|
|
return
|
|
if position.y > 60.0 and position.y < 760.0:
|
|
_fire_timer -= delta
|
|
if _fire_timer <= 0.0:
|
|
_fire_timer = fire_interval
|
|
_fire_bullet(_aim_direction() * bullet_speed, MUZZLE)
|