Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

Commit 3c137e0

Browse files
committed
Finished for playtesting
1 parent 62c15bc commit 3c137e0

7 files changed

Lines changed: 169 additions & 81 deletions

File tree

scenes/levels/ExampleScene.tscn

Lines changed: 31 additions & 15 deletions
Large diffs are not rendered by default.

scripts/Ally.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public partial class Ally : CharacterBody2D
4848
private PointLight2D _torch = null!;
4949
private AiNode _well = null!;
5050

51-
//Enum with states for ally in darkness, in bigger or smaller circle for map damage system
51+
//enum with states for ally in darkness, in bigger or smaller circle for map damage system
5252
public enum AllyState
5353
{
5454
Darkness,

scripts/Interaction/CodeInput.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
using System;
2+
using System.Runtime.CompilerServices;
3+
14
using Godot;
25
public partial class CodeInput : Node2D
36
{
47
private LineEdit _codeinputfield = null!;
58
private AnimationPlayer _fadeToWhite = null!;
69
private Node2D _victoryScreen = null!;
10+
public static Boolean CodeCorrect = false;
711
public override void _Ready()
812
{
913
_codeinputfield = GetTree().Root.GetNode<LineEdit>("Node2D/RuneHolder/CodeInputField");
@@ -24,14 +28,20 @@ private void OnInputSubmitted(string text)
2428
{
2529
if (text.Contains("1234"))
2630
{
27-
GD.Print("Game Won");
28-
_fadeToWhite.Play("fade_to_white");
31+
CodeCorrect = true;
2932
}
3033
}
3134

3235
private void OpenTextField()
3336
{
37+
if(!CodeCorrect) {
3438
_codeinputfield.Visible = true;
3539
_codeinputfield.GrabFocus();
40+
}
41+
}
42+
43+
public void CloseTextField()
44+
{
45+
_codeinputfield.Visible = false;
3646
}
3747
}

scripts/Interaction/Interactable.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public partial class Interactable : Node2D
2222
private AnimationPlayer _animTree = null!;
2323
private AnimationPlayer _animEntrance = null!;
2424
private AnimationPlayer _animDoorOpener = null!;
25+
private Sprite2D _keySprite = null!;
2526

2627
public override void _Ready()
2728
{
@@ -31,6 +32,7 @@ public override void _Ready()
3132
_animTree = GetTree().Root.GetNode<AnimationPlayer>("Node2D/Node2D/AnimationPlayer");
3233
_animEntrance = GetTree().Root.GetNode<AnimationPlayer>("Node2D/CaveEntranceTerminal/AnimationPlayer");
3334
_animDoorOpener = GetTree().Root.GetNode<AnimationPlayer>("Node2D/DoorOpener/AnimationPlayer");
35+
_keySprite = GetTree().Root.GetNode<Sprite2D>("Node2D/RuneHolder/Key");
3436
_scar = GetTree().Root.GetNode<AiNode>("Node2D/Scar");
3537
if (GetParent().Equals(_scar))
3638
{
@@ -60,6 +62,18 @@ public async Task Trigger(Node caller)
6062
ally.Chat.SendSystemMessage(SystemMessageForAlly, new Ally());
6163
}
6264

65+
//Open door
66+
if (GetParent<AiNode>().Name.Equals("LockedDoor") && caller.Name.ToString().Contains("Ally"))
67+
{
68+
Ally ally = (caller as Ally)!;
69+
if (!ally.SsInventory.ContainsMaterial(Game.Scripts.Items.Material.Key)) {
70+
Ally? confirmedAlly = caller as Ally;
71+
Chat confirmedAllyChat = confirmedAlly!.Chat;
72+
confirmedAllyChat.SendSystemMessage("The door is locked, you cannot enter.", new Ally());
73+
return;
74+
}
75+
}
76+
6377
//Fill bucket with water
6478
if (GetParent<AiNode>().Name.Equals("Well") && caller.Name.ToString().Contains("Ally"))
6579
{
@@ -154,7 +168,11 @@ public async Task Trigger(Node caller)
154168
Ally? james = caller as Ally;
155169
Chat jonesChat = james!.Chat;
156170
jonesChat.SendSystemMessage("You've picked up the empty bucket. Maybe fill it with something.", new Ally());
171+
}
157172

173+
if (GetParent<AiNode>().Name.Equals("Key") && caller.Name.ToString().Equals("Ally"))
174+
{
175+
_keySprite.Visible = false;
158176
}
159177

160178
EmitSignal(SignalName.Interact);

scripts/Interaction/ShowWhileInRadius.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ public partial class ShowWhileInRadius : Node2D
3434
Boolean _notebookspawned = false;
3535
AiNode _notebookCode = null!;
3636
Sprite2D _notebookSprite = null!;
37+
Sprite2D _keySprite = null!;
38+
CodeInput _codeInput = null!;
39+
private CollisionShape2D _smallHouseBarrier= null!;
40+
41+
private bool _keyExist = false;
3742

3843
// Load the scene you want to instance. ONLY FOR CHEST INSIDE BIG HOUSE
3944
private PackedScene _sceneToInstance = null!;
@@ -44,6 +49,9 @@ public override void _Ready()
4449
_core = GetTree().GetNodesInGroup("Core").Cast<Core>().SingleOrDefault();
4550
_notebookSprite = GetTree().Root.GetNode<Sprite2D>("Node2D/NotebookWithCode/Notebook_sprite");
4651
_entitiesList = GetTree().GetNodesInGroup("Entities");
52+
_keySprite = GetTree().Root.GetNode<Sprite2D>("Node2D/RuneHolder/Key");
53+
_codeInput = GetTree().Root.GetNode<CodeInput>("Node2D/RuneHolder/CodeInput");
54+
_smallHouseBarrier = GetTree().Root.GetNode<CollisionShape2D>("Node2D/StaticBody2D/CollisionShape2D");
4755
float dist = float.MaxValue;
4856
_notebookSprite.Visible = false;
4957
foreach (Ally ally in _entitiesList)
@@ -160,6 +168,7 @@ public override void _PhysicsProcess(double delta)
160168
//GD.Print("Ally has FestiveStaff: ", allyinv.SsInventory.ContainsMaterial(Game.Scripts.Items.Material.FestiveStaff));
161169
if (parentNode.Name == "Rune" && allyinv.GlobalPosition.DistanceTo(parentNode.GlobalPosition) < 250 && allyinv.SsInventory.ContainsMaterial(Game.Scripts.Items.Material.FestiveStaff) && !_ghostspawned)
162170
{
171+
163172
GD.Print("Ghost spawned");
164173
PackedScene scene = (PackedScene)ResourceLoader.Load("res://scenes/prefabs/ai_node.tscn");
165174
AiNode instance = scene.Instantiate<AiNode>();
@@ -188,6 +197,32 @@ public override void _PhysicsProcess(double delta)
188197
_notebookCode.ObjectDescription = "A Notebook that contains the code for the runeholder";
189198
_notebookCode.CustomOverrideMessage = "Tell the commander that the code for the rune holder is 1234";
190199
}
200+
/*
201+
if (parentNode.Name == "Rune" && CodeInput.CodeCorrect && !_keyExist)
202+
{
203+
_keyExist = true;
204+
_codeInput.CloseTextField();
205+
GD.Print("Code correct");
206+
_keySprite.Visible = true;
207+
PackedScene scene = (PackedScene)ResourceLoader.Load("res://scenes/prefabs/ai_node.tscn");
208+
AiNode instance = scene.Instantiate<AiNode>();
209+
instance.ObjectName = "Key";
210+
instance.ObjectDescription = "Maybe usefull to enter some house.";
211+
Interactable keyInteractable = instance.GetNode<Interactable>("Interactible");
212+
Removeable removeable = instance.GetNode<Removeable>("Removeable");
213+
ItemAdder itemAdder = instance.GetNode<ItemAdder>("ItemAdder");
214+
itemAdder.ItemToAdd = Game.Scripts.Items.Material.Key;
215+
itemAdder.Amount = 1;
216+
itemAdder.ItemToAddName = "Key";
217+
_keySprite.AddChild(instance);
218+
GD.Print("Key spawned");
219+
}
220+
*/
221+
if(CodeInput.CodeCorrect) {
222+
_smallHouseBarrier.SetDeferred("disabled", true);
223+
}
224+
225+
191226
}
192227
}
193228
}

scripts/Items/InventoryUiSlot.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ public void Update(Itemstack item)
101101
_icon.Visible = true;
102102
_icon.Texture = GD.Load<Texture2D>("res://assets/items/chip_card.png");
103103
break;
104+
105+
case Game.Scripts.Items.Material.Key:
106+
_icon.Visible = true;
107+
_icon.Texture = GD.Load<Texture2D>("res://Key.png");
108+
break;
104109
}
105110
_count.Text = item.Amount <= 1 ? "" : item.Amount.ToString();
106111
}

scripts/PathFindingMovement.cs

Lines changed: 67 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ public partial class PathFindingMovement : Node
1010
[Signal] public delegate void ReachedTargetEventHandler();
1111

1212
[Export] private int _minTargetDistance = 40;
13-
[Export] private int _targetDistanceVariation = 50; // Not currently used, consider removing or implementing variation
13+
[Export] private int _targetDistanceVariation = 50;
1414
[Export] private int _speed = 250;
15-
[Export] int _minimumSpeed = 50;
15+
[Export] int _minimumSpeed = 150;
1616
private int _origMinimumSpeed;
1717

1818
[Export] bool _debug = false;
@@ -22,8 +22,8 @@ public partial class PathFindingMovement : Node
2222
[Export] Sprite2D _sprite = null!;
2323

2424
public Vector2 TargetPosition { get; set; }
25-
private object? _lastCollider = null; // Speichert den letzten Kollisionspartner
26-
private bool _recentlyBumped = false; // Verhindert Dauersound
25+
private object _lastCollider = null;
26+
private bool _recentlyBumped = false;
2727
private bool _reachedTarget;
2828
private int _currentTargetDistance;
2929
private AudioStreamPlayer? _bumpSound = null!;
@@ -44,9 +44,10 @@ public override void _Ready()
4444
{
4545
_origMinimumSpeed = _minimumSpeed;
4646
_currentTargetDistance = _minTargetDistance;
47-
this.CallDeferred("ActorSetup"); // Still good to defer setup
47+
this.CallDeferred("ActorSetup");
4848
_bumpSound = GetTree().Root.GetNode<AudioStreamPlayer>("Node2D/AudioManager/bump_sound");
4949
_buttonControl = GetTree().Root.GetNode<ButtonControl>("Node2D/UI");
50+
5051
}
5152

5253
public async void ActorSetup()
@@ -60,79 +61,82 @@ public void GoTo(Vector2 loc)
6061
TargetPosition = loc;
6162
}
6263

63-
public override void _PhysicsProcess(double delta)
64-
{
65-
_speed = 250;
66-
_agent.SetTargetPosition(TargetPosition);
67-
68-
float distanceToTarget = _character.GlobalPosition.DistanceTo(_agent.TargetPosition);
69-
70-
if (distanceToTarget > _currentTargetDistance)
64+
public override void _PhysicsProcess(double delta)
7165
{
72-
_reachedTarget = false;
66+
_speed = 250;
7367

74-
Vector2 currentLocation = _character.GlobalPosition;
75-
Vector2 nextLocation = _agent.GetNextPathPosition();
68+
_agent.SetTargetPosition(TargetPosition);
7669

77-
// Motivation und Speed-Berechnung
78-
Motivation motivation = GetParent().GetNode<Motivation>("Motivation");
79-
double motivationFactor = (double)motivation.Amount / 10;
80-
int modifiedSpeed = (int)(_minimumSpeed + (_speed - _minimumSpeed) * motivationFactor);
81-
82-
// Bewegung berechnen
83-
Vector2 newVel = (nextLocation - currentLocation).Normalized() * modifiedSpeed;
84-
85-
// Richtung für die Animation setzen
86-
CurrentDirection = nextLocation.X < currentLocation.X ? WalkingState.Left : WalkingState.Right;
87-
88-
if (newVel.X != 0 && distanceToTarget > 50)
70+
if (_debug)
8971
{
90-
_sprite.FlipH = newVel.X > 0;
72+
float distance = _character.GlobalPosition.DistanceTo(_agent.TargetPosition);
73+
//GD.Print($"Distance: {distance}, Target Position: {_agent.TargetPosition}");
9174
}
9275

93-
// **Langsamer werden bei Zielnähe (weiches Bremsen)**
94-
if (distanceToTarget < 50)
76+
float distanceToTarget = _character.GlobalPosition.DistanceTo(_agent.TargetPosition);
77+
78+
if (distanceToTarget > _currentTargetDistance)
9579
{
96-
float slowdownFactor = Mathf.Clamp(distanceToTarget / 50, 0.1f, 1f);
97-
newVel *= slowdownFactor;
98-
}
80+
_reachedTarget = false;
81+
Vector2 currentLocation = _character.GlobalPosition, nextLocation = _agent.GetNextPathPosition();
82+
83+
/* Motivation motivation = GetParent().GetNode<Motivation>("Motivation");
84+
double motivationFactor = (double)motivation.Amount / 10;*/
85+
int modifiedSpeed = (int)(_minimumSpeed + (_speed - _minimumSpeed) * 2);
86+
Ally ally = GetParent().GetParent().GetChild<Ally>(0);
87+
Chat chat = ally.FindChild("Speech").GetParent() as Chat ?? throw new InvalidOperationException();
88+
_minimumSpeed = (chat!.GeminiService.IsBusy() || ally!.GetResponseQueue().Count > 0 || !ally!.IsTextBoxReady) ? 0 : _origMinimumSpeed; // dont move while responding or if more than one response is being processed.
89+
Vector2 newVel = (nextLocation - currentLocation).Normalized() * modifiedSpeed;
90+
if (nextLocation.X < currentLocation.X)
91+
{
92+
CurrentDirection = WalkingState.Left;
93+
}
94+
else
95+
{
96+
CurrentDirection = WalkingState.Right;
97+
}
9998

100-
_character.Velocity = newVel;
99+
if (newVel.X != 0 && distanceToTarget > 50)
100+
{
101+
_sprite.FlipH = newVel.X > 0;
102+
}
101103

102-
// Kollisionsabfrage bleibt bestehen
103-
KinematicCollision2D collision = _character.MoveAndCollide(newVel * (float)delta);
104-
if (collision != null && collision.GetCollider() != _lastCollider)
105-
{
106-
if ((_character.Name == "Ally" && _buttonControl.CurrentCamera == 1) ||
107-
(_character.Name == "Ally2" && _buttonControl.CurrentCamera == 2))
104+
_character.Velocity = newVel;
105+
KinematicCollision2D collision = _character.MoveAndCollide(newVel * (float)delta);
106+
if (collision != null)
108107
{
109-
_lastCollider = collision.GetCollider();
110-
_bumpSound!.Play();
111-
_recentlyBumped = true;
108+
if (collision.GetCollider() != _lastCollider)
109+
{
110+
if (_character.Name == "Ally" && _buttonControl.CurrentCamera == 1 || _character.Name == "Ally2" && _buttonControl.CurrentCamera == 2)
111+
{
112+
_lastCollider = collision.GetCollider();
113+
_bumpSound!.Play();
114+
_recentlyBumped = true;
115+
}
116+
}
117+
}
118+
else
119+
{
120+
_lastCollider = null;
121+
_recentlyBumped = false;
112122
}
113-
}
114-
else
115-
{
116-
_lastCollider = null;
117-
_recentlyBumped = false;
118-
}
119-
}
120-
else if (!_reachedTarget)
121-
{
122-
// **Weiches Stoppen statt Teleport**
123-
124123

125-
if (distanceToTarget < 45f) // Bei < 3 Pixel Restdistanz stoppen
124+
_character.Velocity = newVel;
125+
}
126+
else if (!_reachedTarget) // only emit and set _reachedTarget once, when the condition is first met
126127
{
127-
_character.Velocity = Vector2.Zero;
128-
129-
// Idle-Animation aktivieren
130-
CurrentDirection = (CurrentDirection == WalkingState.Left) ? WalkingState.IdleLeft : WalkingState.IdleRight;
128+
if (CurrentDirection == PathFindingMovement.WalkingState.Left)
129+
{
130+
CurrentDirection = WalkingState.IdleLeft;
131+
}
132+
else
133+
{
134+
CurrentDirection = WalkingState.IdleRight;
135+
}
131136

132-
_currentTargetDistance = _minTargetDistance;
137+
_currentTargetDistance = _minTargetDistance; // reset for the next target
133138
EmitSignal(SignalName.ReachedTarget);
134139
_reachedTarget = true;
135140
}
136141
}
137-
}
138-
}
142+
}

0 commit comments

Comments
 (0)