Skip to content

Commit

Permalink
feat: rename Detector to DetectorArea
Browse files Browse the repository at this point in the history
  • Loading branch information
olivierperez committed Sep 2, 2024
1 parent 98cb946 commit b72f196
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 25 deletions.
18 changes: 9 additions & 9 deletions actors/Guard.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class_name Guard
@export var facing_direction: Direction = Direction.BOTTOM
@export var sharedFollowPath: bool = false

@onready var detector = %Detector
@onready var detector_area = %DetectorArea
@onready var animated_sprite_2d = $AnimatedSprite2D
@onready var visible_area = %VisibleArea

Expand Down Expand Up @@ -63,33 +63,33 @@ func _ajust_moving_orientation():
if isHorizontalyMoved:
if moving_direction.x < 0:
animated_sprite_2d.play("run_to_the_left")
detector.rotation_degrees = 90
detector_area.rotation_degrees = 90
elif moving_direction.x > 0:
animated_sprite_2d.play("run_to_the_right")
detector.rotation_degrees = -90
detector_area.rotation_degrees = -90
else:
if moving_direction.y < 0:
animated_sprite_2d.play("run_to_the_top")
detector.rotation_degrees = 180
detector_area.rotation_degrees = 180
elif moving_direction.y > 0:
animated_sprite_2d.play("run_to_the_bottom")
detector.rotation_degrees = 0
detector_area.rotation_degrees = 0


func _ajust_facing_orientation(direction: Direction):
match direction:
Direction.TOP:
animated_sprite_2d.play("facing_top")
detector.rotation_degrees = 180
detector_area.rotation_degrees = 180
Direction.RIGHT:
animated_sprite_2d.play("facing_right")
detector.rotation_degrees = -90
detector_area.rotation_degrees = -90
Direction.BOTTOM:
animated_sprite_2d.play("facing_bottom")
detector.rotation_degrees = 0
detector_area.rotation_degrees = 0
Direction.LEFT:
animated_sprite_2d.play("facing_left")
detector.rotation_degrees = 90
detector_area.rotation_degrees = 90


func _vector_to_direction(vector: Vector2) -> Direction:
Expand Down
10 changes: 5 additions & 5 deletions actors/Guard.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[ext_resource type="Script" path="res://actors/Guard.gd" id="1_dvj3w"]
[ext_resource type="Texture2D" uid="uid://kvneeqa6brvg" path="res://assets/characters/guard/universal-lpc-sprite_male_01_full.png" id="2_8enka"]
[ext_resource type="PackedScene" uid="uid://ch0t0hu00p6er" path="res://mechanism/Detector.tscn" id="3_onp32"]
[ext_resource type="PackedScene" uid="uid://ch0t0hu00p6er" path="res://mechanism/DetectorArea.tscn" id="3_wcu88"]

[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_frres"]
radius = 34.98
Expand Down Expand Up @@ -392,17 +392,17 @@ sprite_frames = SubResource("SpriteFrames_ttuab")
animation = &"facing_bottom"
frame_progress = 0.477112

[node name="Detector" parent="." instance=ExtResource("3_onp32")]
[node name="DetectorArea" parent="." instance=ExtResource("3_wcu88")]
unique_name_in_owner = true

[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="Detector"]
[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="DetectorArea"]
polygon = PackedVector2Array(-50, 2.08165e-12, 50, 2.08165e-12, 130, 180, -130, 180)

[node name="VisibleArea" type="Polygon2D" parent="Detector/CollisionPolygon2D"]
[node name="VisibleArea" type="Polygon2D" parent="DetectorArea/CollisionPolygon2D"]
unique_name_in_owner = true
color = Color(1, 0.407843, 0.407843, 0.196078)
polygon = PackedVector2Array(-50, 2.08165e-12, 50, 2.08165e-12, 130, 180, -130, 180)

[connection signal="input_event" from="ClickableArea" to="." method="_on_actionnable_input_event"]
[connection signal="mouse_exited" from="ClickableArea" to="." method="_on_area_mouse_exited"]
[connection signal="player_detected" from="Detector" to="." method="_on_player_detected"]
[connection signal="player_detected" from="DetectorArea" to="." method="_on_player_detected"]
File renamed without changes.
6 changes: 3 additions & 3 deletions mechanism/Detector.tscn → mechanism/DetectorArea.tscn
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[gd_scene load_steps=2 format=3 uid="uid://ch0t0hu00p6er"]

[ext_resource type="Script" path="res://mechanism/Detector.gd" id="1_lyhly"]
[ext_resource type="Script" path="res://mechanism/DetectorArea.gd" id="1_21u6r"]

[node name="Detector" type="Area2D"]
[node name="DetectorArea" type="Area2D"]
collision_layer = 0
collision_mask = 17
script = ExtResource("1_lyhly")
script = ExtResource("1_21u6r")

[connection signal="body_entered" from="." to="." method="_on_body_entered_detector"]
[connection signal="body_exited" from="." to="." method="_on_body_exited_detector"]
6 changes: 3 additions & 3 deletions objects/Camera.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ extends Node2D

class_name Camera

@onready var detector = %Detector
@onready var detector_area = %DetectorArea
@onready var animated_sprite = %AnimatedSprite
@onready var detection_shape = %DetectionShape
@onready var audio_off = %AudioOff
Expand Down Expand Up @@ -54,7 +54,7 @@ func activateCamera():
animated_sprite.play("on")
audio_on.play()
detection_shape.disabled = false
detector.visible = true
detector_area.visible = true


func deactivateCamera():
Expand All @@ -64,7 +64,7 @@ func deactivateCamera():
animated_sprite.play("off")
audio_off.play()
detection_shape.disabled = true
detector.visible = false
detector_area.visible = false
await get_tree().create_timer(deactivation_camera_timer).timeout
activateCamera()

Expand Down
10 changes: 5 additions & 5 deletions objects/Camera.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
[ext_resource type="Script" path="res://objects/Camera.gd" id="1_2cpas"]
[ext_resource type="Texture2D" uid="uid://dhgxstfex3l5p" path="res://assets/camera/camera-on.png" id="1_jbi7c"]
[ext_resource type="Texture2D" uid="uid://dalurg7lemyuc" path="res://assets/camera/camera-off.png" id="2_2mssq"]
[ext_resource type="PackedScene" uid="uid://ch0t0hu00p6er" path="res://mechanism/DetectorArea.tscn" id="2_n6ij3"]
[ext_resource type="AudioStream" uid="uid://cfkt5daaaa602" path="res://assets/audio/sfx/camera-off.mp3" id="4_fuae1"]
[ext_resource type="AudioStream" uid="uid://boo5037p0nd4f" path="res://assets/audio/sfx/camera-on.mp3" id="5_66gbt"]
[ext_resource type="PackedScene" uid="uid://ch0t0hu00p6er" path="res://mechanism/Detector.tscn" id="6_lu8gv"]

[sub_resource type="CircleShape2D" id="CircleShape2D_4cot1"]

Expand Down Expand Up @@ -40,15 +40,15 @@ unique_name_in_owner = true
scale = Vector2(4, 4)
shape = SubResource("CircleShape2D_4cot1")

[node name="Detector" parent="." instance=ExtResource("6_lu8gv")]
[node name="DetectorArea" parent="." instance=ExtResource("2_n6ij3")]
unique_name_in_owner = true

[node name="DetectionShape" type="CollisionPolygon2D" parent="Detector"]
[node name="DetectionShape" type="CollisionPolygon2D" parent="DetectorArea"]
unique_name_in_owner = true
show_behind_parent = true
polygon = PackedVector2Array(0, 0, 300, 2.08165e-12, 285.317, 92.705, 242.705, 176.336, 176.336, 242.705, 92.705, 285.317, 2.08165e-12, 300)

[node name="Polygon2D" type="Polygon2D" parent="Detector/DetectionShape"]
[node name="Polygon2D" type="Polygon2D" parent="DetectorArea/DetectionShape"]
color = Color(1, 0.407843, 0.407843, 0.196078)
texture = SubResource("CanvasTexture_o81d5")
polygon = PackedVector2Array(0, 0, 300, 2.08165e-12, 285.317, 92.705, 242.705, 176.336, 176.336, 242.705, 92.705, 285.317, 2.08165e-12, 300)
Expand All @@ -71,4 +71,4 @@ volume_db = 10.0

[connection signal="input_event" from="ActionnableArea" to="." method="_on_actionnable_input_event"]
[connection signal="mouse_exited" from="ActionnableArea" to="." method="_on_area_mouse_exited"]
[connection signal="player_detected" from="Detector" to="." method="_on_player_detected"]
[connection signal="player_detected" from="DetectorArea" to="." method="_on_player_detected"]

0 comments on commit b72f196

Please sign in to comment.