pruned scripts
This commit is contained in:
87
Assets/Scripts/CommonScripts/CommonData.cs
Normal file
87
Assets/Scripts/CommonScripts/CommonData.cs
Normal file
@@ -0,0 +1,87 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public partial class CommonData : Node
|
||||
{
|
||||
public bool Muted = true;
|
||||
|
||||
// Level information
|
||||
public string CurrentLevel;
|
||||
|
||||
// Level high scores
|
||||
public int Level1HighScore = 0;
|
||||
public int Level2HighScore = 0;
|
||||
public int Level3HighScore = 0;
|
||||
public int Level4HighScore = 0;
|
||||
public int Level5HighScore = 0;
|
||||
public int Level6HighScore = 0;
|
||||
public int Level7HighScore = 0;
|
||||
public int Level8HighScore = 0;
|
||||
public int Level9HighScore = 0;
|
||||
public int Level10HighScore = 0;
|
||||
public int Level11HighScore = 0;
|
||||
|
||||
|
||||
// Levels Completed
|
||||
public HashSet<string> LevelsCompleted = new HashSet<string>();
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
// Connect to the audio player
|
||||
GetNode<AudioStreamPlayer>("AudioStreamPlayer").Finished += LoopAudio;
|
||||
GetNode<AudioStreamPlayer>("AudioStreamPlayer").VolumeDb = -80; // temporary
|
||||
|
||||
// Start game by loading the camera
|
||||
var scene = GD.Load<PackedScene>("res://Assets/Scenes/Persistant/Camera.tscn");
|
||||
var inst = scene.Instantiate();
|
||||
GetTree().Root.CallDeferred(Node.MethodName.AddChild, inst);
|
||||
|
||||
// Start game by loading the main menu
|
||||
scene = GD.Load<PackedScene>("res://Assets/Scenes/MenusAndLevels/MainMenu.tscn");
|
||||
inst = scene.Instantiate();
|
||||
GetTree().Root.CallDeferred(Node.MethodName.AddChild, inst);
|
||||
PlayMusic("MainMenu");
|
||||
|
||||
// Load in saved data
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (Input.IsActionJustPressed("quit_game"))
|
||||
{
|
||||
GetTree().Quit();
|
||||
}
|
||||
if (Input.IsActionJustPressed("mute"))
|
||||
{
|
||||
if (Muted)
|
||||
{
|
||||
Muted = false;
|
||||
GetNode<AudioStreamPlayer>("AudioStreamPlayer").VolumeDb = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
Muted = true;
|
||||
GetNode<AudioStreamPlayer>("AudioStreamPlayer").VolumeDb = -80;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// BG Audio Management
|
||||
public void StopMusic()
|
||||
{
|
||||
// Stop whatever audio is playing
|
||||
GetNode<AudioStreamPlayer>("AudioStreamPlayer").Stop();
|
||||
}
|
||||
public void PlayMusic(string AudioName)
|
||||
{
|
||||
// Load target audio and play the audio
|
||||
GetNode<AudioStreamPlayer>("AudioStreamPlayer").Stream = (Godot.AudioStream)GD.Load($"res://Assets/Audio/Music/{AudioName}.mp3");
|
||||
GetNode<AudioStreamPlayer>("AudioStreamPlayer").Play();
|
||||
}
|
||||
void LoopAudio()
|
||||
{
|
||||
// Find when the stream finishes playing to play it again
|
||||
GetNode<AudioStreamPlayer>("AudioStreamPlayer").Play();
|
||||
}
|
||||
}
|
||||
21
Assets/Scripts/CommonScripts/TipManager.cs
Normal file
21
Assets/Scripts/CommonScripts/TipManager.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public partial class TipManager : RichTextLabel
|
||||
{
|
||||
|
||||
string[] TipList =
|
||||
{
|
||||
"Example Tip 1",
|
||||
"Example Tip 2",
|
||||
"Example Tip 3"
|
||||
};
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
// Get random tip and change the text to that
|
||||
GD.Randomize();
|
||||
Text = TipList[GD.Randi() % TipList.Length];
|
||||
}
|
||||
}
|
||||
10
Assets/Scripts/CommonScripts/UI.cs
Normal file
10
Assets/Scripts/CommonScripts/UI.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class UI : Node2D
|
||||
{
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
GlobalPosition = GetTree().Root.GetNode("Camera").GetNode<Node2D>("Camera2D").GlobalPosition;
|
||||
}
|
||||
}
|
||||
49
Assets/Scripts/LevelScripts/ChangeMenuInitiator.cs
Normal file
49
Assets/Scripts/LevelScripts/ChangeMenuInitiator.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class ChangeMenuInitiator : Node2D
|
||||
{
|
||||
|
||||
public void ChangeMenu(string type, string destination)
|
||||
{
|
||||
if (type == "SLOW")
|
||||
{
|
||||
// Load the menu change manager
|
||||
var scene = GD.Load<PackedScene>("res://Assets/Scenes/MenusAndLevels/MenuChangeManager.tscn");
|
||||
var inst = (Node2D)scene.Instantiate();
|
||||
GetTree().Root.GetNode("Camera").AddChild(inst);
|
||||
|
||||
inst.Position = GetTree().Root.GetNode("Camera").GetNode<Node2D>("Camera2D").Position;
|
||||
|
||||
// Pass args to menu change manager
|
||||
inst.GetNode<MenuChangeManager>("MenuChangeManager").TargetMenu = destination;
|
||||
inst.GetNode<MenuChangeManager>("MenuChangeManager").TransitionDelay = TransitionDelay;
|
||||
|
||||
// Wait for intro animation to finish before freeing the scene
|
||||
inst.GetNode<AnimationPlayer>("AnimationPlayer").AnimationFinished += DeleteMenu;
|
||||
}
|
||||
if (type == "FAST")
|
||||
{
|
||||
var scene = GD.Load<PackedScene>($"res://Assets/Scenes/MenusAndLevels/{destination}.tscn");
|
||||
var inst = (Node2D)scene.Instantiate();
|
||||
GetTree().Root.AddChild(inst);
|
||||
|
||||
//reset camera
|
||||
GetTree().Root.GetNode("Camera").GetNode<CameraMovement>("Camera2D").TeleportCamera(Vector2.Zero);
|
||||
GetTree().Root.GetNode("Camera").GetNode<CameraMovement>("Camera2D").FixedPosition = GetTree().Root.GetNode("Camera").GetNode<Node2D>("Camera2D").Position;
|
||||
GetTree().Root.GetNode("Camera").SetMeta("CameraMode", "FIXED");
|
||||
|
||||
DeleteMenu("LoadIn");
|
||||
}
|
||||
|
||||
}
|
||||
void DeleteMenu(StringName arg)
|
||||
{
|
||||
if (arg == "LoadIn")
|
||||
{
|
||||
// Delete current scene (MAKE SURE THE PARENT OF THE PARENT OF THIS SCRIPT IS THE SCENE YOU CAME FROM)
|
||||
GetParent().GetParent().QueueFree();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
91
Assets/Scripts/LevelScripts/Dialogue.cs
Normal file
91
Assets/Scripts/LevelScripts/Dialogue.cs
Normal file
@@ -0,0 +1,91 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
// Instantiate this scene and send all data to SetupDailogue()
|
||||
// arg contains the speaker, speaker icon, and the sentance for example "Sign|GruntCalm|This is a test."
|
||||
|
||||
public partial class Dialogue : Node2D
|
||||
{
|
||||
string SpeakerName = null;
|
||||
string SpeakerImage = null;
|
||||
string Sentance = null;
|
||||
Queue<string> Data = new Queue<string>();
|
||||
|
||||
float ScrollTimer = 0.05f; // Sec
|
||||
float ScrollTimerReset = 0.05f;
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (Input.IsActionJustPressed("interact")) // Advance dialogue
|
||||
{
|
||||
AdvanceDialogue();
|
||||
}
|
||||
|
||||
// Scroll text
|
||||
ScrollTimer -= (float)delta;
|
||||
if (Sentance != null && ScrollTimer <= 0)
|
||||
{
|
||||
ScrollTimer = ScrollTimerReset;
|
||||
GetNode<RichTextLabel>("Dialogue").VisibleCharacters += 1;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetupDialogue(string[] arg)
|
||||
{
|
||||
GetNode<RichTextLabel>("Dialogue").VisibleCharacters = 0;
|
||||
|
||||
// Set up data
|
||||
foreach (string value in arg)
|
||||
{
|
||||
Data.Enqueue(value);
|
||||
}
|
||||
|
||||
// Set up visuals & first dialogue option
|
||||
if (Data.Count > 0)
|
||||
{
|
||||
// Get data
|
||||
string[] OperatingData = Data.Dequeue().Split("|");
|
||||
SpeakerName = OperatingData[0];
|
||||
SpeakerImage = OperatingData[1];
|
||||
Sentance = OperatingData[2];
|
||||
//Display data
|
||||
GetNode<Sprite2D>("Icon").Texture = (Godot.Texture2D)GD.Load($"res://Assets/Sprites/DialogueIcons/{SpeakerImage}.png");
|
||||
GetNode<RichTextLabel>("SpeakerName").Text = SpeakerName;
|
||||
GetNode<RichTextLabel>("Dialogue").Text = Sentance;
|
||||
}
|
||||
else // If there is nothing left delete the scene
|
||||
{
|
||||
QueueFree();
|
||||
}
|
||||
}
|
||||
|
||||
public void AdvanceDialogue()
|
||||
{
|
||||
// Determine wether to skip to the end or display the next sentance
|
||||
if (GetNode<RichTextLabel>("Dialogue").GetTotalCharacterCount() > GetNode<RichTextLabel>("Dialogue").VisibleCharacters)
|
||||
{
|
||||
GetNode<RichTextLabel>("Dialogue").VisibleCharacters = GetNode<RichTextLabel>("Dialogue").GetTotalCharacterCount();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Data.Count > 0)
|
||||
{
|
||||
GetNode<RichTextLabel>("Dialogue").VisibleCharacters = 0;
|
||||
// Get data
|
||||
string[] OperatingData = Data.Dequeue().Split("|");
|
||||
SpeakerName = OperatingData[0];
|
||||
SpeakerImage = OperatingData[1];
|
||||
Sentance = OperatingData[2];
|
||||
//Display data
|
||||
GetNode<Sprite2D>("Icon").Texture = (Godot.Texture2D)GD.Load($"res://Assets/Sprites/DialogueIcons/{SpeakerImage}.png");
|
||||
GetNode<RichTextLabel>("SpeakerName").Text = SpeakerName;
|
||||
GetNode<RichTextLabel>("Dialogue").Text = Sentance;
|
||||
}
|
||||
else // If there is nothing left delete the scene
|
||||
{
|
||||
QueueFree();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
59
Assets/Scripts/LevelScripts/LevelManager.cs
Normal file
59
Assets/Scripts/LevelScripts/LevelManager.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
// Designed by Jojackman1
|
||||
|
||||
public partial class LevelManager : Node
|
||||
{
|
||||
Node2D StartNode;
|
||||
Node2D EndNode;
|
||||
Node2D Player;
|
||||
string EndType = "nothing";
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
StartNode = GetParent().GetNode<Node2D>("StartNode");
|
||||
EndNode = GetParent().GetNode<Node2D>("EndNode");
|
||||
Player = GetParent().GetNode<Node2D>("Player");
|
||||
|
||||
// Play into animation
|
||||
GetParent().GetNode("ScreenAnimations").GetNode("LevelStartAssets").GetNode<AnimationPlayer>("LevelStart").CurrentAnimation = "default";
|
||||
GetParent().GetNode("ScreenAnimations").GetNode<Node2D>("LevelStartAssets").Reparent(GetTree().Root.GetNode("Camera").GetNode("Camera2D"));
|
||||
GetTree().Root.GetNode("Camera").GetNode("Camera2D").GetNode<Node2D>("LevelStartAssets").GlobalPosition = GetTree().Root.GetNode("Camera").GetNode<Node2D>("Camera2D").GlobalPosition;
|
||||
GetTree().Root.GetNode("Camera").GetNode("Camera2D").GetNode<Node2D>("LevelStartAssets").Visible = true;
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
|
||||
// Manage conditions to end the level
|
||||
if (EndType == "nothing")
|
||||
{
|
||||
// Death
|
||||
if ()
|
||||
{
|
||||
EndManager("Death");
|
||||
EndType = "Death";
|
||||
}
|
||||
// Success
|
||||
if (GetParent().HasNode("Player") && Player.GlobalPosition.DistanceTo(EndNode.GlobalPosition) <= 16)
|
||||
{
|
||||
EndManager("Success");
|
||||
EndType = "Success";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void EndManager(string EndType)
|
||||
{
|
||||
switch (EndType)
|
||||
{
|
||||
case "Death": // Player Dies
|
||||
break;
|
||||
case "Success": // Successfully make it to the end of the levels
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user