diff --git a/Resources/Sprites/Camera.tres b/Resources/Sprites/Camera.tres index 99c0e1f9..b102b336 100644 --- a/Resources/Sprites/Camera.tres +++ b/Resources/Sprites/Camera.tres @@ -1,4 +1,4 @@ -[gd_resource type="SpriteFrames" load_steps=35 format=3 uid="uid://yfxog8pww6ih"] +[gd_resource type="SpriteFrames" load_steps=39 format=3 uid="uid://yfxog8pww6ih"] [ext_resource type="Texture2D" uid="uid://cpuffmksk41n4" path="res://Sprites/Actors/Camera.png" id="1_p68hc"] @@ -26,10 +26,26 @@ region = Rect2(48, 0, 16, 16) atlas = ExtResource("1_p68hc") region = Rect2(64, 0, 16, 16) -[sub_resource type="AtlasTexture" id="AtlasTexture_6e5gf"] +[sub_resource type="AtlasTexture" id="AtlasTexture_kkke6"] +atlas = ExtResource("1_p68hc") +region = Rect2(64, 0, 16, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_ut6x5"] +atlas = ExtResource("1_p68hc") +region = Rect2(48, 0, 16, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_iyaqf"] atlas = ExtResource("1_p68hc") region = Rect2(32, 0, 16, 16) +[sub_resource type="AtlasTexture" id="AtlasTexture_nvf8m"] +atlas = ExtResource("1_p68hc") +region = Rect2(16, 0, 16, 16) + +[sub_resource type="AtlasTexture" id="AtlasTexture_ugygk"] +atlas = ExtResource("1_p68hc") +region = Rect2(0, 0, 16, 16) + [sub_resource type="AtlasTexture" id="AtlasTexture_dxl8p"] atlas = ExtResource("1_p68hc") region = Rect2(0, 0, 16, 16) @@ -166,7 +182,19 @@ animations = [{ }, { "frames": [{ "duration": 1.0, -"texture": SubResource("AtlasTexture_6e5gf") +"texture": SubResource("AtlasTexture_kkke6") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_ut6x5") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_iyaqf") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_nvf8m") +}, { +"duration": 1.0, +"texture": SubResource("AtlasTexture_ugygk") }], "loop": true, "name": &"default", diff --git a/Scenes/Actors/Camera.tscn b/Scenes/Actors/Camera.tscn index ee32ab61..bea1bc4f 100644 --- a/Scenes/Actors/Camera.tscn +++ b/Scenes/Actors/Camera.tscn @@ -22,8 +22,6 @@ _playerDetection = NodePath("PlayerDetection") [node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."] sprite_frames = ExtResource("2_omkb8") -animation = &"full_scan" -frame_progress = 0.779565 [node name="CollisionShape2D" type="CollisionShape2D" parent="."] shape = SubResource("CircleShape2D_nkpag") @@ -34,6 +32,7 @@ collision_mask = 2 script = ExtResource("3_ax0x5") SweepSpeed = 10.0 Debug = true +SpritePath = NodePath("../AnimatedSprite2D") [node name="CollisionShape2D" type="CollisionShape2D" parent="PlayerDetection"] shape = SubResource("CircleShape2D_gs7jc") diff --git a/Scenes/test.tscn b/Scenes/test.tscn index 5a5824df..9158df6a 100644 --- a/Scenes/test.tscn +++ b/Scenes/test.tscn @@ -122,6 +122,9 @@ Target = NodePath("../HorizontalDoor") [node name="Camera" parent="Factory Tilemaps" instance=ExtResource("16_clqjt")] position = Vector2(-649, -168) +[node name="PlayerDetection" parent="Factory Tilemaps/Camera" index="2"] +SweepAngle = 40.0 + [node name="AlarmBox" parent="Factory Tilemaps" instance=ExtResource("17_dppcs")] position = Vector2(-713, -153) @@ -184,3 +187,5 @@ script = ExtResource("25_rpwvt") [node name="Camera" parent="." instance=ExtResource("16_clqjt")] position = Vector2(-1096, -23) + +[editable path="Factory Tilemaps/Camera"] diff --git a/Scripts/Actors/Camera.cs b/Scripts/Actors/Camera.cs index 7deb8bea..6472833d 100644 --- a/Scripts/Actors/Camera.cs +++ b/Scripts/Actors/Camera.cs @@ -4,7 +4,6 @@ using Cirno.Scripts; public partial class Camera : Enemy { - private AnimatedSprite2D _sprite; private AlarmManager _alarmManager; @@ -21,7 +20,8 @@ public partial class Camera : Enemy _sprite = GetNode("AnimatedSprite2D"); - _sprite.Play("full_scan"); + _sprite.Play("default"); + _sprite.SpeedScale = 0; } protected override void Shoot() diff --git a/Scripts/Components/CameraPlayerDetection.cs b/Scripts/Components/CameraPlayerDetection.cs index 28f23662..6ddc82a3 100644 --- a/Scripts/Components/CameraPlayerDetection.cs +++ b/Scripts/Components/CameraPlayerDetection.cs @@ -10,15 +10,20 @@ public partial class CameraPlayerDetection : PlayerDetection [Export] public float SweepAngle = 90f; // In degrees [Export] public float SweepSpeed = 1f; // Speed of sweeping [Export] public bool Debug = false; // Enable debug lines + [Export] public NodePath SpritePath; private float _currentAngle; private float _sweepDirection = 1f; private float _raycastLength; + + private AnimatedSprite2D _animatedSprite; public override void _Ready() { base._Ready(); + _animatedSprite = GetNode(SpritePath); + var collisionShape = GetNode("CollisionShape2D"); if (collisionShape.Shape is CircleShape2D circle) { @@ -30,6 +35,8 @@ public partial class CameraPlayerDetection : PlayerDetection { base._PhysicsProcess(delta); SweepCamera((float)delta); + + UpdateSpriteDirection(); } private void SweepCamera(float delta) @@ -58,6 +65,19 @@ public partial class CameraPlayerDetection : PlayerDetection _debugLineEndPoint = endPoint; } + private void UpdateSpriteDirection() + { + if (_animatedSprite == null) return; + + var frames = _animatedSprite.SpriteFrames.GetFrameCount("default"); + + // Map angle (-SweepAngle/2 to +SweepAngle/2) to frame (0 to 5) + float normalizedAngle = (_currentAngle + (SweepAngle / 2)) / SweepAngle; + int frame = Mathf.Clamp((int)(normalizedAngle * frames), 0, frames); + + _animatedSprite.Frame = frame; + } + private Vector2 _debugLineEndPoint; public override void _Draw()