Fixed merge errors

This commit is contained in:
Jojackman1
2026-01-19 10:41:03 -07:00
parent 9e0eed66c3
commit 985a975577
50 changed files with 1622 additions and 81 deletions

View File

@@ -0,0 +1,116 @@
using Godot;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public partial class CameraMovement : Camera2D
{
// Node Refrence
Node2D Target;
Node2D Player;
// Player Info
Vector2 PreviousPlayerPosition;
// Camera Properties
float CameraVerticalOffset = -20;
float CameraHorizontalOffset = 20;
float CameraMovementSpeed = 4;
// Tweening
float CameraTweenRate;
float MaxCameraTweenRate = 150f;
float MinCameraTweenRate = 0.5f;
//float MaxCameraDistance = 15f;
// Mode
public string CameraMode; // "FOLLOW" (Follows player), "FIXED" (Stay at fixed position)
public Vector2 FixedPosition;
public override void _Ready()
{
// Find Nodes
Target = this.GetParent().GetNode<Node2D>("CameraTarget");
// Set initial camera position
CameraMode = (string)GetParent().GetMeta("CameraMode");
Position = Target.Position;
FixedPosition = new Vector2(0,0);
PreviousPlayerPosition = new Vector2(0,0);
}
public override void _Process(double delta)
{
// Update Mode
CameraMode = (string)GetParent().GetMeta("CameraMode");
// Change Target position depending on current mode
switch (CameraMode)
{
case "FOLLOW":
// Set the player variable if it equals null
var RootChildren = GetTree().Root.GetChildren();
if (Player == null)
{
if (RootChildren[2].HasNode("Player"))
Player = RootChildren[2].GetNode<Node2D>("Player");
}
else // If player exists
{
// Calculate the player's change in position
float DeltaPosition = Player.Position[0] - PreviousPlayerPosition.X;
// Place target in the direction the player is moving for enhanced visibility
if (DeltaPosition > 0) // Right side of player
{
Target.Position = new Vector2(Player.Position[0] + CameraHorizontalOffset, Player.Position[1] + CameraVerticalOffset);
}
if (DeltaPosition < 0) // Left side of player
{
Target.Position = new Vector2(Player.Position[0] - CameraHorizontalOffset, Player.Position[1] + CameraVerticalOffset);
}
if (DeltaPosition == 0) // Center on player when not moving
{
Target.Position = new Vector2(Player.Position[0], Player.Position[1] + CameraVerticalOffset);
}
PreviousPlayerPosition = Player.Position;
}
break;
case "FIXED":
// Change position of Camera Target if it is not at the desired fixed position
if (Target.Position != FixedPosition)
{
Target.Position = FixedPosition;
}
Player = null;
break;
default: // Does nothing just required
break;
}
// Tween camera to Camera Target's position
CameraTweenRate = (float)Math.Pow(Position.DistanceTo(Target.Position), 2) / 10f;
// Ensure the Tween Rate stays between the Max and Min values
if (CameraTweenRate > MaxCameraTweenRate)
{
CameraTweenRate = MaxCameraTweenRate;
}
if (CameraTweenRate < MinCameraTweenRate)
{
CameraTweenRate = MinCameraTweenRate;
}
// Move Camera
Vector2 MovementDirection = (Target.Position - Position).Normalized();
Position += MovementDirection * CameraMovementSpeed * CameraTweenRate * (float)delta;
}
public void TeleportCamera(Vector2 TargetPosition)
{
GetParent().GetNode<Node2D>("CameraTarget").Position = TargetPosition;
Position = TargetPosition;
FixedPosition = TargetPosition;
}
}

View File

@@ -0,0 +1 @@
uid://co5myvo1u4qn7

View File

@@ -1,49 +0,0 @@
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();
}
}
}

View File

@@ -3,7 +3,7 @@ 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."
// arg contains the speaker and the sentance for example "Sign|This is a test."
public partial class Dialogue : Node2D
{

View File

@@ -0,0 +1 @@
uid://b7a4ty2lbfxan

View File

@@ -0,0 +1,35 @@
using Godot;
using System;
public partial class LevelDialogueInitiator : Node2D
{
string[] Dialogue; // Each element in the array is the name of the speaker and the dialogue seperated by a | (ex "Sign|This is a test message.")
float MaxInteractDistance = 30;
public override void _Ready()
{
// Get dialogue from the metadata
Dialogue = (string[])GetMeta("Dialogue");
}
public override void _Process(double delta)
{
if (GetParent().GetParent().HasNode("Player"))
{
if (Position.DistanceTo(GetParent().GetParent().GetNode<Node2D>("Player").Position) <= MaxInteractDistance)
GetNode<AnimatedSprite2D>("InteractionIndicator").Visible = true;
else
GetNode<AnimatedSprite2D>("InteractionIndicator").Visible = false;
}
if (Input.IsActionJustPressed("interact") && GetTree().Root.GetNode("Camera").GetNode("Camera2D").HasNode("Dialogue") == false && Position.DistanceTo(GetParent().GetParent().GetNode<Node2D>("Player").Position) <= MaxInteractDistance)
{
// Instantiate scene
var scene = GD.Load<PackedScene>($"res://Assets/Scenes/Dialogue.tscn");
var inst = scene.Instantiate();
GetTree().Root.GetNode("Camera").GetNode("Camera2D").AddChild(inst);
// Send Data
GetTree().Root.GetNode("Camera").GetNode("Camera2D").GetNode<Dialogue>("Dialogue").SetupDialogue(Dialogue);
}
}
}

View File

@@ -0,0 +1 @@
uid://cl8sq2b2lp4a5

View File

@@ -1,8 +1,6 @@
using Godot;
using System;
// Designed by Jojackman1
public partial class LevelManager : Node
{
Node2D StartNode;
@@ -12,6 +10,8 @@ public partial class LevelManager : Node
public override void _Ready()
{
GetTree().Root.GetNode<CommonData>("CommonData").CurrentHealth = GetTree().Root.GetNode<CommonData>("CommonData").MaxHealth;
StartNode = GetParent().GetNode<Node2D>("StartNode");
EndNode = GetParent().GetNode<Node2D>("EndNode");
Player = GetParent().GetNode<Node2D>("Player");
@@ -30,7 +30,7 @@ public partial class LevelManager : Node
if (EndType == "nothing")
{
// Death
if ()
if (GetTree().Root.GetNode<CommonData>("CommonData").CurrentHealth <= 0)
{
EndManager("Death");
EndType = "Death";
@@ -48,9 +48,25 @@ public partial class LevelManager : Node
{
switch (EndType)
{
case "Death": // Player Dies
case "Death": // Player Died
//Player.QueueFree();
// Go back to main menu (Replace with proper ending screen and then send back to main menu)
GetNode<ChangeMenuInitiator>("ChangeMenuInitiator").ChangeMenu("FAST", "MainMenu", GetParent());
break;
case "Success": // Successfully make it to the end of the levels
case "Success": // Success
// Remove the player to stop checking
//Player.QueueFree();
// Add level completed to the hash set
GetTree().Root.GetNode<CommonData>("CommonData").LevelsCompleted.Add(GetParent().Name);
// Play exit animation
GetParent().GetNode("ScreenAnimations").GetNode("LevelCompleteAssets").GetNode<AnimationPlayer>("LevelComplete").CurrentAnimation = "default";
GetParent().GetNode("ScreenAnimations").GetNode<Node2D>("LevelCompleteAssets").Reparent(GetTree().Root.GetNode("Camera").GetNode("Camera2D"));
GetTree().Root.GetNode("Camera").GetNode("Camera2D").GetNode<Node2D>("LevelCompleteAssets").GlobalPosition = GetTree().Root.GetNode("Camera").GetNode<Node2D>("Camera2D").GlobalPosition;
GetTree().Root.GetNode("Camera").GetNode("Camera2D").GetNode<Node2D>("LevelCompleteAssets").Visible = true;
// Go to exit cutscene after exit animation is complete
var LevelName = (string)GetParent().Name;
var LevelNumber = LevelName.Split("Level");
GetNode<ChangeMenuInitiator>("ChangeMenuInitiator").ChangeMenu("SLOW", $"Cutscenes/ExitCutscene{LevelNumber[0]}", GetParent());
break;
default:
break;

View File

@@ -0,0 +1 @@
uid://i8yvg41jip3n