Переходы между днями

This commit is contained in:
Евгений Титаренко 2024-08-25 13:17:20 +03:00
parent 71502b0653
commit 26db1ea66d
4 changed files with 42 additions and 25 deletions

View file

@ -167,6 +167,14 @@ theme_override_styles/panel = SubResource("StyleBoxFlat_6l2d2")
layout_mode = 2 layout_mode = 2
text = "E - Next" text = "E - Next"
[node name="ColorRect" type="ColorRect" parent="Camera2D"]
z_index = 11
offset_left = -160.0
offset_top = -140.0
offset_right = 160.0
offset_bottom = 100.0
color = Color(0, 0, 0, 0)
[node name="Footsteps" parent="." instance=ExtResource("5_wnylg")] [node name="Footsteps" parent="." instance=ExtResource("5_wnylg")]
RandomPitch = true RandomPitch = true
PitchStart = 0.75 PitchStart = 0.75

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=24 format=3 uid="uid://c1abgp6quvo3o"] [gd_scene load_steps=19 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="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"] [ext_resource type="Script" path="res://scripts/Day.cs" id="1_cko08"]
@ -255,10 +255,4 @@ stream = SubResource("AudioStreamPlaylist_7838k")
autoplay = true autoplay = true
bus = &"Music" bus = &"Music"
[node name="ColorRect" type="ColorRect" parent="."] [connection signal="DialogEnded" from="NPCs/Ivan" to="." method="ChangeDay"]
z_index = 11
offset_left = 894.0
offset_top = 115.0
offset_right = 1214.0
offset_bottom = 355.0
color = Color(0, 0, 0, 0)

View file

@ -24,13 +24,19 @@ public partial class Day : Node2D
public override void _Ready() public override void _Ready()
{ {
_player = (Player)FindChild("Player"); _player = (Player)FindChild("Player");
_colorRect = (ColorRect)FindChild("ColorRect"); _colorRect = _player.CRect;
_music = (AudioStreamPlayer)FindChild("Music"); _music = (AudioStreamPlayer)FindChild("Music");
_colorRect.Color = new Color(0, 0, 0, 1f); _colorRect.Color = new Color(0, 0, 0, 1f);
_music.VolumeDb = -40; _music.VolumeDb = -40;
_player.CurrentState = Player.State.Wait; _player.CurrentState = Player.State.Wait;
} }
public void ChangeDay()
{
_state = State.TransitionOut;
}
// Called every frame. 'delta' is the elapsed time since the previous frame. // Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta) public override void _Process(double delta)
{ {
@ -60,7 +66,7 @@ public partial class Day : Node2D
} }
else else
{ {
GetNode<SceneManager>("/root/SceneManager").SwitchScene("Day1"); GetNode<SceneManager>("/root/SceneManager").SwitchScene(NextScene);
} }
} }
} }

View file

@ -101,6 +101,8 @@ public partial class Player : CharacterBody2D
private PackedScene _dialogBox = GD.Load<PackedScene>("res://prefabs/Dialog.tscn"); private PackedScene _dialogBox = GD.Load<PackedScene>("res://prefabs/Dialog.tscn");
public ColorRect CRect { get; private set; }
public override void _Ready() public override void _Ready()
{ {
_sprite = (AnimatedSprite2D)FindChild("AnimatedSprite2D"); _sprite = (AnimatedSprite2D)FindChild("AnimatedSprite2D");
@ -111,6 +113,7 @@ public partial class Player : CharacterBody2D
_camera = (Camera2D)FindChild("Camera2D"); _camera = (Camera2D)FindChild("Camera2D");
_footsteps = (AudioCollection)FindChild("Footsteps"); _footsteps = (AudioCollection)FindChild("Footsteps");
_doorSounds = (AudioCollection)FindChild("DoorSounds"); _doorSounds = (AudioCollection)FindChild("DoorSounds");
CRect = (ColorRect)FindChild("ColorRect");
} }
public override void _PhysicsProcess(double delta) public override void _PhysicsProcess(double delta)
@ -119,19 +122,7 @@ public partial class Player : CharacterBody2D
{ {
case State.Normal: case State.Normal:
if (_camera.Offset != _cameraDefaultPosition) HideChatLog(delta);
{
if (_currentCameraTransitionTime < CameraTransitionTime)
{
_camera.Offset = _cameraChatLogPosition.Lerp(_cameraDefaultPosition,
(float)(_currentCameraTransitionTime * 1 / CameraTransitionTime));
_currentCameraTransitionTime += delta;
}
else
{
_currentCameraTransitionTime = 0;
}
}
Vector2 velocity = Velocity; Vector2 velocity = Velocity;
@ -179,12 +170,30 @@ public partial class Player : CharacterBody2D
ShowChatLog(delta); ShowChatLog(delta);
break; break;
case State.Wait: case State.Wait:
_camera.Offset = _cameraDefaultPosition;
break; break;
default: default:
throw new ArgumentOutOfRangeException(); throw new ArgumentOutOfRangeException();
} }
} }
private void HideChatLog(double delta)
{
if (_camera.Offset != _cameraDefaultPosition)
{
if (_currentCameraTransitionTime < CameraTransitionTime)
{
_camera.Offset = _cameraChatLogPosition.Lerp(_cameraDefaultPosition,
(float)(_currentCameraTransitionTime * 1 / CameraTransitionTime));
_currentCameraTransitionTime += delta;
}
else
{
_currentCameraTransitionTime = 0;
}
}
}
private void ShowChatLog(double delta) private void ShowChatLog(double delta)
{ {
if (_camera.Offset != _cameraChatLogPosition) if (_camera.Offset != _cameraChatLogPosition)