Реализация окончания дня по приходу в каюту.

This commit is contained in:
Евгений Титаренко 2024-08-25 14:16:11 +03:00
parent de683399fa
commit 4222af1896
8 changed files with 111 additions and 81 deletions

View file

@ -9,7 +9,7 @@ script = ExtResource("1_xeo83")
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
sprite_frames = ExtResource("2_r10xf")
frame_progress = 0.100142
frame_progress = 0.140426
[node name="Interactable" parent="." instance=ExtResource("2_hcfxj")]
SpriteOffset = Vector2(0, -35)

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=25 format=3 uid="uid://c1abgp6quvo3o"]
[gd_scene load_steps=23 format=3 uid="uid://c1abgp6quvo3o"]
[ext_resource type="Texture2D" uid="uid://b5baxx5o21qy1" path="res://resources/sprites/Sub/Sub.png" id="1_a6v5r"]
[ext_resource type="Script" path="res://scripts/Day.cs" id="1_cko08"]
@ -262,6 +262,7 @@ SpriteOffset = Vector2(0, -30)
AreaRadius = 20.0
IsEnabled = false
[connection signal="DialogEnded" from="NPCs/Ivan" to="." method="EnableChangeDay"]
[connection signal="DialogEnded" from="NPCs/Ivan" to="." method="EnableEndDay"]
[connection signal="OnInteract" from="EndDay" to="." method="ChangeDay"]
[connection signal="PlayerLeft" from="EndDay" to="." method="RemoveEndDay"]
[connection signal="PlayerNearBy" from="EndDay" to="." method="AssignEndDay"]

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=24 format=3 uid="uid://bpnc0noa6do5m"]
[gd_scene load_steps=25 format=3 uid="uid://bpnc0noa6do5m"]
[ext_resource type="Script" path="res://scripts/Day.cs" id="1_6vltc"]
[ext_resource type="Texture2D" uid="uid://b5baxx5o21qy1" path="res://resources/sprites/Sub/Sub.png" id="1_j1x6m"]
@ -11,6 +11,7 @@
[ext_resource type="SpriteFrames" uid="uid://wu7pmuvjw5qm" path="res://resources/sprites/npcs/Empty.tres" id="8_1sqr2"]
[ext_resource type="PackedScene" uid="uid://dfdsnwub212o6" path="res://prefabs/Player.tscn" id="9_7dj1v"]
[ext_resource type="AudioStream" uid="uid://bask8dw8kd56j" path="res://resources/music/Day2.wav" id="10_x821k"]
[ext_resource type="PackedScene" uid="uid://x6pqolxtgwvy" path="res://prefabs/Interactable.tscn" id="12_f7yho"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_h0540"]
size = Vector2(640, 24)
@ -261,3 +262,8 @@ offset_top = 115.0
offset_right = 1214.0
offset_bottom = 355.0
color = Color(0, 0, 0, 0)
[node name="EndDay" parent="." instance=ExtResource("12_f7yho")]
position = Vector2(985, 245)
SpriteOffset = Vector2(0, -30)
AreaRadius = 20.0

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=24 format=3 uid="uid://dydhxm41f4kqu"]
[gd_scene load_steps=25 format=3 uid="uid://dydhxm41f4kqu"]
[ext_resource type="Script" path="res://scripts/Day.cs" id="1_6ouk8"]
[ext_resource type="Texture2D" uid="uid://b5baxx5o21qy1" path="res://resources/sprites/Sub/Sub.png" id="1_m7xoy"]
@ -11,6 +11,7 @@
[ext_resource type="SpriteFrames" uid="uid://wu7pmuvjw5qm" path="res://resources/sprites/npcs/Empty.tres" id="8_k42bg"]
[ext_resource type="PackedScene" uid="uid://dfdsnwub212o6" path="res://prefabs/Player.tscn" id="9_pvv3u"]
[ext_resource type="AudioStream" uid="uid://c0mheqx5d738m" path="res://resources/music/Day3.wav" id="10_ouee8"]
[ext_resource type="PackedScene" uid="uid://x6pqolxtgwvy" path="res://prefabs/Interactable.tscn" id="12_yeat3"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_h0540"]
size = Vector2(640, 24)
@ -261,3 +262,8 @@ offset_top = 115.0
offset_right = 1214.0
offset_bottom = 355.0
color = Color(0, 0, 0, 0)
[node name="EndDay" parent="." instance=ExtResource("12_yeat3")]
position = Vector2(985, 245)
SpriteOffset = Vector2(0, -30)
AreaRadius = 20.0

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=24 format=3 uid="uid://cxvsyen213g1o"]
[gd_scene load_steps=25 format=3 uid="uid://cxvsyen213g1o"]
[ext_resource type="Script" path="res://scripts/Day.cs" id="1_gb313"]
[ext_resource type="Texture2D" uid="uid://b5baxx5o21qy1" path="res://resources/sprites/Sub/Sub.png" id="1_ngvqc"]
@ -11,6 +11,7 @@
[ext_resource type="SpriteFrames" uid="uid://wu7pmuvjw5qm" path="res://resources/sprites/npcs/Empty.tres" id="8_je535"]
[ext_resource type="PackedScene" uid="uid://dfdsnwub212o6" path="res://prefabs/Player.tscn" id="9_qlkfx"]
[ext_resource type="AudioStream" uid="uid://dyj3161xr78j8" path="res://resources/music/Day4.wav" id="10_vlywc"]
[ext_resource type="PackedScene" uid="uid://x6pqolxtgwvy" path="res://prefabs/Interactable.tscn" id="12_dvtmm"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_h0540"]
size = Vector2(640, 24)
@ -261,3 +262,8 @@ offset_top = 115.0
offset_right = 1214.0
offset_bottom = 355.0
color = Color(0, 0, 0, 0)
[node name="EndDay" parent="." instance=ExtResource("12_dvtmm")]
position = Vector2(985, 245)
SpriteOffset = Vector2(0, -30)
AreaRadius = 20.0

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=24 format=3 uid="uid://10ew1xa1pxm2"]
[gd_scene load_steps=25 format=3 uid="uid://10ew1xa1pxm2"]
[ext_resource type="Script" path="res://scripts/Day.cs" id="1_ii8yu"]
[ext_resource type="Texture2D" uid="uid://b5baxx5o21qy1" path="res://resources/sprites/Sub/Sub.png" id="1_p4jcj"]
@ -11,6 +11,7 @@
[ext_resource type="SpriteFrames" uid="uid://wu7pmuvjw5qm" path="res://resources/sprites/npcs/Empty.tres" id="8_8y5k0"]
[ext_resource type="PackedScene" uid="uid://dfdsnwub212o6" path="res://prefabs/Player.tscn" id="9_mxxxl"]
[ext_resource type="AudioStream" uid="uid://3poadcg4f8mj" path="res://resources/music/Day5.wav" id="10_bwdem"]
[ext_resource type="PackedScene" uid="uid://x6pqolxtgwvy" path="res://prefabs/Interactable.tscn" id="12_bvb3u"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_h0540"]
size = Vector2(640, 24)
@ -256,3 +257,8 @@ offset_top = 115.0
offset_right = 1214.0
offset_bottom = 355.0
color = Color(0, 0, 0, 0)
[node name="EndDay" parent="." instance=ExtResource("12_bvb3u")]
position = Vector2(985, 245)
SpriteOffset = Vector2(0, -30)
AreaRadius = 20.0

View file

@ -31,15 +31,16 @@ public partial class Day : Node2D
_colorRect.Color = new Color(0, 0, 0, 1f);
_music.VolumeDb = -40;
_player.CurrentState = Player.State.Wait;
_endDay.Disable();
}
public void AssignEndDay()
public void AssignEndDay(Player player)
{
_player.InteractableObjects.Add(_endDay);
player.InteractableObjects.Add(_endDay);
}
public void RemoveEndDay()
public void RemoveEndDay(Player player)
{
_player.InteractableObjects.Remove(_endDay);
player.InteractableObjects.Remove(_endDay);
}
public void ChangeDay()
@ -49,7 +50,7 @@ public partial class Day : Node2D
public void EnableEndDay()
{
_endDay.IsEnabled = true;
_endDay.Enable();
}
// Called every frame. 'delta' is the elapsed time since the previous frame.

View file

@ -4,83 +4,87 @@ using System;
[Tool]
public partial class Interactable : Node2D
{
private const double Tolerance = 1e-6;
private const double Tolerance = 1e-6;
[Signal]
public delegate void PlayerNearByEventHandler(Player player);
[Signal]
public delegate void PlayerNearByEventHandler(Player player);
[Signal]
public delegate void PlayerLeftEventHandler(Player player);
[Signal]
public delegate void PlayerLeftEventHandler(Player player);
[Signal]
public delegate void OnInteractEventHandler();
[Signal]
public delegate void OnInteractEventHandler();
[Export] public Vector2 SpriteOffset;
[Export] public float AreaRadius;
[Export] public bool IsEnabled;
private AnimatedSprite2D _sprite;
[Export] public Vector2 SpriteOffset;
[Export] public float AreaRadius;
private CollisionShape2D _areaMesh;
private AnimatedSprite2D _sprite;
private CircleShape2D _collisionCircle;
private CollisionShape2D _areaMesh;
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
_sprite = (AnimatedSprite2D)FindChild("AnimatedSprite2D");
_areaMesh = (CollisionShape2D)FindChild("CollisionShape2D");
_sprite.Position = SpriteOffset;
_collisionCircle = (CircleShape2D)_areaMesh.Shape;
_collisionCircle.Radius = AreaRadius;
if (Engine.IsEditorHint())
{
_sprite.Visible = true;
}
else
{
_sprite.Visible = false;
}
}
private CircleShape2D _collisionCircle;
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
if (Engine.IsEditorHint())
{
if (_sprite.Position != SpriteOffset) _sprite.Position = SpriteOffset;
if (Math.Abs(_collisionCircle.Radius - AreaRadius) > Tolerance) _collisionCircle.Radius = AreaRadius;
}
private bool _isEnabled = true;
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
_sprite = (AnimatedSprite2D)FindChild("AnimatedSprite2D");
_areaMesh = (CollisionShape2D)FindChild("CollisionShape2D");
_sprite.Position = SpriteOffset;
_collisionCircle = (CircleShape2D)_areaMesh.Shape;
_collisionCircle.Radius = AreaRadius;
if (Engine.IsEditorHint())
{
_sprite.Visible = true;
}
else
{
_sprite.Visible = false;
}
}
if (IsEnabled)
{
_sprite.Visible = true;
}
else
{
_sprite.Visible = false;
}
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
if (Engine.IsEditorHint())
{
if (_sprite.Position != SpriteOffset) _sprite.Position = SpriteOffset;
if (Math.Abs(_collisionCircle.Radius - AreaRadius) > Tolerance) _collisionCircle.Radius = AreaRadius;
}
}
public void Interact()
{
EmitSignal(SignalName.OnInteract);
}
private void _on_area_2d_body_entered(Node2D body)
{
if (IsEnabled && body is Player player)
{
_sprite.Visible = true;
EmitSignal(SignalName.PlayerNearBy, player);
}
}
public void Interact()
{
EmitSignal(SignalName.OnInteract);
}
private void _on_area_2d_body_exited(Node2D body)
{
if (IsEnabled && body is Player player)
{
_sprite.Visible = false;
EmitSignal(SignalName.PlayerLeft, player);
}
}
}
public void Enable()
{
_isEnabled = true;
_sprite.Visible = true;
}
public void Disable()
{
_isEnabled = false;
_sprite.Visible = false;
}
private void _on_area_2d_body_entered(Node2D body)
{
if (_isEnabled && body is Player player)
{
_sprite.Visible = true;
EmitSignal(SignalName.PlayerNearBy, player);
}
}
private void _on_area_2d_body_exited(Node2D body)
{
if (_isEnabled && body is Player player)
{
_sprite.Visible = false;
EmitSignal(SignalName.PlayerLeft, player);
}
}
}