mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 09:35:34 +00:00
Camera sprite sweep
This commit is contained in:
parent
290acba7be
commit
88fd702cea
5 changed files with 59 additions and 7 deletions
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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"]
|
||||
|
|
|
|||
|
|
@ -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>("AnimatedSprite2D");
|
||||
|
||||
_sprite.Play("full_scan");
|
||||
_sprite.Play("default");
|
||||
_sprite.SpeedScale = 0;
|
||||
}
|
||||
|
||||
protected override void Shoot()
|
||||
|
|
|
|||
|
|
@ -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<AnimatedSprite2D>(SpritePath);
|
||||
|
||||
var collisionShape = GetNode<CollisionShape2D>("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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue