Files
sijcdusmode/scripts/walker.gd
T
sijcdu 1b3d61793d Enemies no longer attack; add a fixed bullet-ring emitter and make lasers permanent obstacles
walker.gd lost its firing code entirely: monsters now only patrol and hurt on contact, so the only way past is footwork or the key throw + W warp. New bullet_ring prefab fires a set number of bullets evenly spread over a fixed arc on a timer, with directions derived only from its own exports, so every volley is identical and the pattern can be memorised; the level places one at cell (12,12) aimed upward with the 12 bullets spread over 180 degrees. laser.gd gained always_on, defaulting to true, so the five copied lasers are now static hazards that are always lit and damage anything overlapping them rather than blinking on and off. Bullets now stop when they spawn inside terrain.
2026-10-07 22:23:18 +08:00

61 lines
1.7 KiB
GDScript

extends CharacterBody2D
## 小怪:只在平台上左右巡逻,**不发射任何东西**,也**打不死**。
## 作用纯粹是挡路 + 碰到扣血,逼玩家走位。
## 弹幕交给专门的「弹幕源」节点负责。
@export_category("巡逻")
@export var speed: float = 28.0
## 巡逻方向:-1 向左,1 向右
@export var start_direction: int = -1
## 掉头后的冷却时间:防止贴着墙时每帧都掉头、结果原地抖动
@export var turn_cooldown: float = 0.25
## 速度设成 0 就变成待在原地不动的障碍
@export var damage: int = 1
var direction: int = -1
var _turn_timer: float = 0.0
@onready var sprite: Sprite2D = $Sprite
@onready var floor_probe: RayCast2D = $FloorProbe
@onready var touch_area: Area2D = $TouchArea
func _ready() -> void:
add_to_group("enemy")
direction = -1 if start_direction < 0 else 1
_apply_direction()
touch_area.body_entered.connect(_on_touch)
func _physics_process(delta: float) -> void:
if _turn_timer > 0.0:
_turn_timer -= delta
if not is_on_floor():
velocity += get_gravity() * delta
velocity.x = float(direction) * speed
# 撞到墙 或 前方脚下没有地板 -> 掉头(带冷却,掉头后先走一段再说)
if _turn_timer <= 0.0:
if is_on_wall() or (is_on_floor() and not floor_probe.is_colliding()):
direction = -direction
_turn_timer = turn_cooldown
_apply_direction()
move_and_slide()
func _apply_direction() -> void:
if sprite != null:
sprite.flip_h = direction > 0
if floor_probe != null:
floor_probe.position.x = float(direction) * 6.0
func _on_touch(body: Node2D) -> void:
# 打不死:踩上去也一样只是扣血
if body.has_method("hurt"):
body.hurt(damage)