Files
sijcdu 19ab10de5f Add hazard spikes on the tree tops (grey spikes from the tileset atlas)
The two new spikes were painted as tiles in TerrainBase, but tileset collision can only make a solid wall, not a damaging hazard. Replaced them with a real spikes_grey prefab that uses the same atlas tile (8,3) plus hazard.gd, and erases the placeholder tile on ready. Also includes the level edits made in the editor (top-left terrain rework).
2026-10-07 20:52:44 +08:00

30 lines
984 B
GDScript

extends Area2D
## 尖刺:碰到就把角色打回出生点、扣一颗心。
## 碰撞掩码已经限制成只检测玩家那一层,所以进到这里的一定是玩家。
@export var damage: int = 1
## 开场时把自己脚下那块占位地砖擦掉
## (关卡里有些尖刺是直接画在地砖上的,换成真正的尖刺对象后要把它擦掉,避免重叠)
@export var erase_placeholder_tile: bool = false
func _ready() -> void:
body_entered.connect(_on_body_entered)
if erase_placeholder_tile:
_erase_placeholder_tile()
func _on_body_entered(body: Node2D) -> void:
if body.has_method("hurt"):
body.hurt(damage)
func _erase_placeholder_tile() -> void:
var root: Node = owner if owner != null else get_parent()
if root == null:
return
for layer in root.find_children("*", "TileMapLayer", true, false):
var cell: Vector2i = layer.local_to_map(layer.to_local(global_position))
if layer.get_cell_source_id(cell) != -1:
layer.erase_cell(cell)