diff --git a/prefabs/Player.tscn b/prefabs/Player.tscn index 5a2288c..b36e3f0 100644 --- a/prefabs/Player.tscn +++ b/prefabs/Player.tscn @@ -167,6 +167,14 @@ theme_override_styles/panel = SubResource("StyleBoxFlat_6l2d2") layout_mode = 2 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")] RandomPitch = true PitchStart = 0.75 diff --git a/scenes/Day1.tscn b/scenes/Day1.tscn index db160c5..f9d479c 100644 --- a/scenes/Day1.tscn +++ b/scenes/Day1.tscn @@ -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="Script" path="res://scripts/Day.cs" id="1_cko08"] @@ -255,10 +255,4 @@ stream = SubResource("AudioStreamPlaylist_7838k") autoplay = true bus = &"Music" -[node name="ColorRect" type="ColorRect" parent="."] -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) +[connection signal="DialogEnded" from="NPCs/Ivan" to="." method="ChangeDay"] diff --git a/scripts/Day.cs b/scripts/Day.cs index 5f8ff22..dc7dfc5 100644 --- a/scripts/Day.cs +++ b/scripts/Day.cs @@ -17,20 +17,26 @@ public partial class Day : Node2D private Player _player; private ColorRect _colorRect; private AudioStreamPlayer _music; - + private double _transitionTimeout = 0; // Called when the node enters the scene tree for the first time. public override void _Ready() { _player = (Player)FindChild("Player"); - _colorRect = (ColorRect)FindChild("ColorRect"); + _colorRect = _player.CRect; _music = (AudioStreamPlayer)FindChild("Music"); _colorRect.Color = new Color(0, 0, 0, 1f); _music.VolumeDb = -40; _player.CurrentState = Player.State.Wait; } - + + + public void ChangeDay() + { + _state = State.TransitionOut; + } + // Called every frame. 'delta' is the elapsed time since the previous frame. public override void _Process(double delta) { @@ -60,7 +66,7 @@ public partial class Day : Node2D } else { - GetNode("/root/SceneManager").SwitchScene("Day1"); + GetNode("/root/SceneManager").SwitchScene(NextScene); } } } diff --git a/scripts/Player.cs b/scripts/Player.cs index 1ee4bb8..8feaa43 100644 --- a/scripts/Player.cs +++ b/scripts/Player.cs @@ -101,6 +101,8 @@ public partial class Player : CharacterBody2D private PackedScene _dialogBox = GD.Load("res://prefabs/Dialog.tscn"); + public ColorRect CRect { get; private set; } + public override void _Ready() { _sprite = (AnimatedSprite2D)FindChild("AnimatedSprite2D"); @@ -111,6 +113,7 @@ public partial class Player : CharacterBody2D _camera = (Camera2D)FindChild("Camera2D"); _footsteps = (AudioCollection)FindChild("Footsteps"); _doorSounds = (AudioCollection)FindChild("DoorSounds"); + CRect = (ColorRect)FindChild("ColorRect"); } public override void _PhysicsProcess(double delta) @@ -119,19 +122,7 @@ public partial class Player : CharacterBody2D { case State.Normal: - if (_camera.Offset != _cameraDefaultPosition) - { - if (_currentCameraTransitionTime < CameraTransitionTime) - { - _camera.Offset = _cameraChatLogPosition.Lerp(_cameraDefaultPosition, - (float)(_currentCameraTransitionTime * 1 / CameraTransitionTime)); - _currentCameraTransitionTime += delta; - } - else - { - _currentCameraTransitionTime = 0; - } - } + HideChatLog(delta); Vector2 velocity = Velocity; @@ -179,12 +170,30 @@ public partial class Player : CharacterBody2D ShowChatLog(delta); break; case State.Wait: + _camera.Offset = _cameraDefaultPosition; break; default: 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) { if (_camera.Offset != _cameraChatLogPosition)