From 71502b065386cda36d0391fcb22f33019bb9cdf1 Mon Sep 17 00:00:00 2001 From: Evgenij Titarenko Date: Sun, 25 Aug 2024 12:59:17 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D1=85=D0=BE=D0=B4?= =?UTF-8?q?=D1=8B=20=D0=BC=D0=B5=D0=B6=D0=B4=D1=83=20=D0=B4=D0=BD=D1=8F?= =?UTF-8?q?=D0=BC=D0=B8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scenes/Day1.tscn | 13 ++++++++- scenes/Day2.tscn | 13 ++++++++- scenes/Day3.tscn | 13 ++++++++- scenes/Day4.tscn | 13 ++++++++- scenes/Day5.tscn | 13 ++++++++- scripts/Day.cs | 67 +++++++++++++++++++++++++++++++++++++++++++++++ scripts/Player.cs | 2 +- 7 files changed, 128 insertions(+), 6 deletions(-) create mode 100644 scripts/Day.cs diff --git a/scenes/Day1.tscn b/scenes/Day1.tscn index 1634800..db160c5 100644 --- a/scenes/Day1.tscn +++ b/scenes/Day1.tscn @@ -1,6 +1,7 @@ -[gd_scene load_steps=23 format=3 uid="uid://c1abgp6quvo3o"] +[gd_scene load_steps=24 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"] [ext_resource type="PackedScene" uid="uid://coogmsw6rsdun" path="res://prefabs/Door.tscn" id="2_qedp5"] [ext_resource type="PackedScene" uid="uid://c5ndo6b0unkst" path="res://prefabs/NPC.tscn" id="3_t4e54"] [ext_resource type="SpriteFrames" uid="uid://dsgqo48qikwsn" path="res://resources/sprites/npcs/cock.tres" id="4_ephn1"] @@ -50,6 +51,8 @@ stream_count = 1 stream_0 = ExtResource("9_43nb0") [node name="Test" type="Node2D"] +script = ExtResource("1_cko08") +NextScene = "Day2" [node name="Sprite2D" type="Sprite2D" parent="."] texture = ExtResource("1_a6v5r") @@ -251,3 +254,11 @@ Speed = 100.0 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) diff --git a/scenes/Day2.tscn b/scenes/Day2.tscn index 9d225ee..1133060 100644 --- a/scenes/Day2.tscn +++ b/scenes/Day2.tscn @@ -1,5 +1,6 @@ -[gd_scene load_steps=23 format=3 uid="uid://bpnc0noa6do5m"] +[gd_scene load_steps=24 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"] [ext_resource type="PackedScene" uid="uid://coogmsw6rsdun" path="res://prefabs/Door.tscn" id="2_mm217"] [ext_resource type="PackedScene" uid="uid://c5ndo6b0unkst" path="res://prefabs/NPC.tscn" id="3_w8l5u"] @@ -50,6 +51,8 @@ stream_count = 1 stream_0 = ExtResource("10_x821k") [node name="Test" type="Node2D"] +script = ExtResource("1_6vltc") +NextScene = "Day3" [node name="Sprite2D" type="Sprite2D" parent="."] texture = ExtResource("1_j1x6m") @@ -250,3 +253,11 @@ Speed = 100.0 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) diff --git a/scenes/Day3.tscn b/scenes/Day3.tscn index 86bf3df..bb1d599 100644 --- a/scenes/Day3.tscn +++ b/scenes/Day3.tscn @@ -1,5 +1,6 @@ -[gd_scene load_steps=23 format=3 uid="uid://dydhxm41f4kqu"] +[gd_scene load_steps=24 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"] [ext_resource type="PackedScene" uid="uid://coogmsw6rsdun" path="res://prefabs/Door.tscn" id="2_72qyp"] [ext_resource type="PackedScene" uid="uid://c5ndo6b0unkst" path="res://prefabs/NPC.tscn" id="3_s2s8w"] @@ -50,6 +51,8 @@ stream_count = 1 stream_0 = ExtResource("10_ouee8") [node name="Test" type="Node2D"] +script = ExtResource("1_6ouk8") +NextScene = "Day4" [node name="Sprite2D" type="Sprite2D" parent="."] texture = ExtResource("1_m7xoy") @@ -250,3 +253,11 @@ Speed = 100.0 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) diff --git a/scenes/Day4.tscn b/scenes/Day4.tscn index 4ce76f9..7c9e95d 100644 --- a/scenes/Day4.tscn +++ b/scenes/Day4.tscn @@ -1,5 +1,6 @@ -[gd_scene load_steps=23 format=3 uid="uid://cxvsyen213g1o"] +[gd_scene load_steps=24 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"] [ext_resource type="PackedScene" uid="uid://coogmsw6rsdun" path="res://prefabs/Door.tscn" id="2_kyojn"] [ext_resource type="PackedScene" uid="uid://c5ndo6b0unkst" path="res://prefabs/NPC.tscn" id="3_vhb2r"] @@ -50,6 +51,8 @@ stream_count = 1 stream_0 = ExtResource("10_vlywc") [node name="Test" type="Node2D"] +script = ExtResource("1_gb313") +NextScene = "Day5" [node name="Sprite2D" type="Sprite2D" parent="."] texture = ExtResource("1_ngvqc") @@ -250,3 +253,11 @@ Speed = 100.0 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) diff --git a/scenes/Day5.tscn b/scenes/Day5.tscn index ccea34b..db5436c 100644 --- a/scenes/Day5.tscn +++ b/scenes/Day5.tscn @@ -1,5 +1,6 @@ -[gd_scene load_steps=23 format=3 uid="uid://10ew1xa1pxm2"] +[gd_scene load_steps=24 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"] [ext_resource type="PackedScene" uid="uid://coogmsw6rsdun" path="res://prefabs/Door.tscn" id="2_o6uwl"] [ext_resource type="PackedScene" uid="uid://c5ndo6b0unkst" path="res://prefabs/NPC.tscn" id="3_4c2bg"] @@ -50,6 +51,8 @@ stream_count = 1 stream_0 = ExtResource("10_bwdem") [node name="Test" type="Node2D"] +script = ExtResource("1_ii8yu") +NextScene = "Menu" [node name="Sprite2D" type="Sprite2D" parent="."] texture = ExtResource("1_p4jcj") @@ -245,3 +248,11 @@ Speed = 100.0 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) diff --git a/scripts/Day.cs b/scripts/Day.cs new file mode 100644 index 0000000..5f8ff22 --- /dev/null +++ b/scripts/Day.cs @@ -0,0 +1,67 @@ +using Godot; +using System; + +public partial class Day : Node2D +{ + [Export] public string NextScene; + + private enum State + { + Default, + TransitionIn, + TransitionOut + } + + private State _state = State.TransitionIn; + + 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"); + _music = (AudioStreamPlayer)FindChild("Music"); + _colorRect.Color = new Color(0, 0, 0, 1f); + _music.VolumeDb = -40; + _player.CurrentState = Player.State.Wait; + } + + // Called every frame. 'delta' is the elapsed time since the previous frame. + public override void _Process(double delta) + { + if (_state == State.TransitionIn) + { + if (_transitionTimeout <= 2) + { + _transitionTimeout += delta; + _music.VolumeDb = Mathf.Lerp(-40, 0, (float)_transitionTimeout/2); + _colorRect.Color = new Color(0, 0, 0, Mathf.Lerp(1, 0, (float)_transitionTimeout/2)); + } + else + { + _state = State.Default; + _player.CurrentState = Player.State.Normal; + _transitionTimeout = 0; + } + } + if (_state == State.TransitionOut) + { + _player.CurrentState = Player.State.Wait; + if (_transitionTimeout <= 2) + { + _transitionTimeout += delta; + _music.VolumeDb = Mathf.Lerp(0, -40, (float)_transitionTimeout/2); + _colorRect.Color = new Color(0, 0, 0, Mathf.Lerp(0, 1, (float)_transitionTimeout/2)); + } + else + { + GetNode("/root/SceneManager").SwitchScene("Day1"); + } + } + } +} diff --git a/scripts/Player.cs b/scripts/Player.cs index cc1fb83..1ee4bb8 100644 --- a/scripts/Player.cs +++ b/scripts/Player.cs @@ -22,7 +22,7 @@ public partial class Player : CharacterBody2D public State CurrentState { get => _state; - private set + set { _sprite.Play("default"); switch (value)