class_name MazeMarker extends Area2D # A maze's Start or End: a glowing pad on the floor with a label over it. # Stand it on the middle of an air tile whose floor is below. The End one # sends `reached` when the player touches it. signal reached const PAD_SIZE = Vector2(28, 4) const PAD_DROP = 12.0 # How far below our position the pad's top is (16 is the floor). const GLOW_HEIGHT = 20.0 const PULSE_SPEED = 3.0 # Radians per second. const LABEL_RISE = 18.0 # How far above our position the label sits. const LABEL_FONT_SIZE = 8 const TOUCH_SIZE = Vector2(20, 20) @export var label := "START" @export var color := Color(0.3, 1.0, 0.45) @export var isGoal := false var _time := 0.0 func _ready() -> void: z_index = 1 # In front of the tiles. monitoring = isGoal var shape := RectangleShape2D.new() shape.size = TOUCH_SIZE var collision := CollisionShape2D.new() collision.shape = shape add_child(collision) body_entered.connect(_on_body_entered) func _process(delta: float) -> void: _time += delta queue_redraw() func _draw() -> void: var pulse := 0.5 + 0.5 * sin(_time * PULSE_SPEED) # A glow rising off the pad, fading upwards. var glowSteps := int(GLOW_HEIGHT) for step in glowSteps: var glow := color glow.a = (1.0 - float(step) / glowSteps) * (0.15 + 0.15 * pulse) draw_rect(Rect2(-PAD_SIZE.x / 2.0, PAD_DROP - step - 1, PAD_SIZE.x, 1), glow) draw_rect(Rect2(Vector2(-PAD_SIZE.x / 2.0, PAD_DROP), PAD_SIZE), color.lightened(0.3 * pulse)) var font := ThemeDB.fallback_font var textWidth := font.get_string_size(label, HORIZONTAL_ALIGNMENT_LEFT, -1, LABEL_FONT_SIZE).x draw_string(font, Vector2(-textWidth / 2.0, -LABEL_RISE), label, HORIZONTAL_ALIGNMENT_LEFT, -1, LABEL_FONT_SIZE, color.lightened(0.2 * pulse)) func _on_body_entered(body: Node2D) -> void: if isGoal and body is CharacterBody2D: reached.emit()