Система перехода между сценами. И главное меню. Типа.

This commit is contained in:
Евгений Титаренко 2024-08-25 12:27:06 +03:00
parent 8e4304ebc6
commit f45ebbceb6
7 changed files with 172 additions and 1 deletions

14
prefabs/SceneManager.tscn Normal file
View file

@ -0,0 +1,14 @@
[gd_scene load_steps=2 format=3 uid="uid://cs8w774ovpf5w"]
[ext_resource type="Script" path="res://scripts/SceneManager.cs" id="1_3bhed"]
[node name="SceneManager" type="Node"]
script = ExtResource("1_3bhed")
Scenes = {
"Day1": "res://scenes/Day1.tscn",
"Day2": "res://scenes/Day2.tscn",
"Day3": "res://scenes/Day3.tscn",
"Day4": "res://scenes/Day4.tscn",
"Day5": "res://scenes/Day5.tscn",
"Menu": "res://scenes/Startup.tscn"
}

View file

@ -11,10 +11,14 @@ config_version=5
[application]
config/name="chill-jam-10"
run/main_scene="res://scenes/Day1.tscn"
run/main_scene="res://scenes/Startup.tscn"
config/features=PackedStringArray("4.3", "C#", "GL Compatibility")
config/icon="res://icon.svg"
[autoload]
SceneManager="*res://prefabs/SceneManager.tscn"
[display]
window/size/viewport_width=640

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://82rj0mblksli"
path="res://.godot/imported/menu.png-4263fd2237a014a2a4ff0c92ae64c757.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://resources/sprites/ui/menu.png"
dest_files=["res://.godot/imported/menu.png-4263fd2237a014a2a4ff0c92ae64c757.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

47
scenes/Startup.tscn Normal file
View file

@ -0,0 +1,47 @@
[gd_scene load_steps=6 format=3 uid="uid://b6nskaaaroy2j"]
[ext_resource type="Script" path="res://scripts/Startup.cs" id="1_1ndxq"]
[ext_resource type="Texture2D" uid="uid://82rj0mblksli" path="res://resources/sprites/ui/menu.png" id="1_nye7c"]
[ext_resource type="FontFile" uid="uid://dwn20pw40jpxm" path="res://fonts/ZxSpectrum7-nROZ0.ttf" id="2_et3ev"]
[ext_resource type="AudioStream" uid="uid://be35iuapayv0u" path="res://resources/music/Day1.wav" id="3_m8gkt"]
[sub_resource type="AudioStreamPlaylist" id="AudioStreamPlaylist_5mfcs"]
stream_count = 1
stream_0 = ExtResource("3_m8gkt")
[node name="Startup" type="Node2D"]
script = ExtResource("1_1ndxq")
[node name="Camera2D" type="Camera2D" parent="."]
zoom = Vector2(2, 2)
[node name="Sprite2D" type="Sprite2D" parent="."]
texture = ExtResource("1_nye7c")
[node name="Label" type="Label" parent="."]
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -128.0
offset_top = 97.0
offset_right = 128.0
offset_bottom = 120.0
grow_horizontal = 2
grow_vertical = 2
theme_override_fonts/font = ExtResource("2_et3ev")
theme_override_font_sizes/font_size = 20
text = "Press E to start"
[node name="ColorRect" type="ColorRect" parent="."]
offset_left = -160.0
offset_top = -120.0
offset_right = 160.0
offset_bottom = 120.0
color = Color(0, 0, 0, 0)
[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."]
stream = SubResource("AudioStreamPlaylist_5mfcs")
autoplay = true
bus = &"Music"

22
scripts/SceneManager.cs Normal file
View file

@ -0,0 +1,22 @@
using Godot;
using System;
using System.Linq;
using Godot.Collections;
public partial class SceneManager : Node
{
[Export] public Dictionary<string, string> Scenes;
public string CurrentScene;
public void SwitchScene(string sceneName)
{
GetTree().ChangeSceneToFile(Scenes[sceneName]);
}
public override void _Ready()
{
var scenePath = (string)ProjectSettings.GetSetting("application/run/main_scene");
CurrentScene = Scenes.First(pair => pair.Value == scenePath).Key;
}
}

50
scripts/Startup.cs Normal file
View file

@ -0,0 +1,50 @@
using Godot;
using System;
public partial class Startup : Node2D
{
private enum State
{
Default,
Transition
}
private State _state = State.Default;
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()
{
_colorRect = (ColorRect)FindChild("ColorRect");
_music = (AudioStreamPlayer)FindChild("AudioStreamPlayer");
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _PhysicsProcess(double delta)
{
if (_state == State.Transition)
{
_transitionTimeout += delta;
// _colorRect.Color = _colorRect.Color.Lerp(new Color(0, 0, 0, 255), (float)_transitionTimeout/2);
_colorRect.Color = new Color(0, 0, 0, Mathf.Lerp(0, 1, (float)_transitionTimeout/2));
_music.VolumeDb = Mathf.Lerp(0, -41, (float)_transitionTimeout/2);
if (_music.VolumeDb < -40)
{
GetNode<SceneManager>("/root/SceneManager").SwitchScene("Day1");
}
}
}
public override void _Input(InputEvent @event)
{
if (@event.IsActionPressed("Interact"))
{
_state = State.Transition;
}
}
}