Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ class_name Guard extends CharacterBody2D
## Enemy type that patrols along a path and raises an alert if the player is detected.

## Emitted when the player is detected.
signal player_detected(player: Player)
## [br][br]
## As the name suggests, this is typically a [Player], but may be some
## other [PhysicsBody2D] (or even a [TileMapLayer]) that is in the
## collision layer(s) detected by the guard's detection areas' [member
## Area2D.collision_mask].
signal player_detected(player: Node2D)

enum State {
## Going along the path.
Expand Down Expand Up @@ -85,7 +90,7 @@ var state: State = State.PATROLLING:
set = _set_state

# The player that's being detected.
var _player: Player
var _player: Node2D

## Area that represents the sight of the guard. If a player is in this area
## and there are no walls in between detected by [member sight_ray_cast], it
Expand Down Expand Up @@ -454,16 +459,12 @@ func _set_alert_other_sound_stream(new_value: AudioStream) -> void:


func _on_instant_detection_area_body_entered(body: Node2D) -> void:
if not body is Player:
return
state = State.ALERTED
player_detected.emit(body as Player)
player_detected.emit(body)


func _on_detection_area_body_entered(body: Node2D) -> void:
if not body is Player:
return
_player = body as Player
_player = body
if _is_sight_to_point_blocked(body.global_position):
return
if player_instantly_detected_on_sight:
Expand All @@ -474,8 +475,6 @@ func _on_detection_area_body_entered(body: Node2D) -> void:


func _on_detection_area_body_exited(body: Node2D) -> void:
if not body is Player:
return
_player = null
last_seen_position = body.global_position
if state == State.DETECTING:
Expand Down
5 changes: 3 additions & 2 deletions scenes/game_logic/stealth_game_logic.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ func _ready() -> void:
guard.player_detected.connect(self._on_player_detected)


func _on_player_detected(player: Player) -> void:
player.defeat()
func _on_player_detected(player: Node2D) -> void:
if player.has_method("defeat"):
player.defeat()