Compare commits

..

9 Commits

15 changed files with 110 additions and 13 deletions

View File

@ -1,4 +1,5 @@
using Godot; using Godot;
using IEnumerableNode = System.Collections.Generic.IEnumerable<Godot.Node>;
namespace SupaLidlGame.Extensions; namespace SupaLidlGame.Extensions;
@ -55,4 +56,13 @@ public static class NodeExtensions
return node.GetNode<UI.UIController>("/root/BaseUI/" + return node.GetNode<UI.UIController>("/root/BaseUI/" +
"SubViewportContainer/UIViewport/CanvasLayer/MainUILayer/Main"); "SubViewportContainer/UIViewport/CanvasLayer/MainUILayer/Main");
} }
public static IEnumerableNode GetChildrenEnumerable(this Node node)
{
int childCount = node.GetChildCount();
for (int i = 0; i < childCount; i++)
{
yield return node.GetChild(i);
}
}
} }

View File

@ -239,6 +239,21 @@ public partial class Inventory : Node2D, IItemCollection<ItemMetadata>
public bool Remove(ItemMetadata item) public bool Remove(ItemMetadata item)
{ {
int indexInInventory = Items.IndexOf(item);
if (indexInInventory < 0)
{
return false;
}
// remove instances of item from hotbar
int indexInHotbar = HotbarToItemIndexMap.IndexOf(indexInInventory);
if (indexInHotbar >= 0)
{
HotbarToItemIndexMap[indexInHotbar] = -1;
Hotbar[indexInHotbar].QueueFree();
}
Items[indexInInventory] = null;
return Items.Remove(item); return Items.Remove(item);
} }

View File

@ -65,4 +65,15 @@ public abstract partial class Item : Node2D
{ {
} }
public virtual void Remove()
{
if (IsUsing)
{
Deuse();
}
Unequip(CharacterOwner);
QueueFree();
}
} }

View File

@ -412,7 +412,6 @@ libraries = {
} }
[node name="Hitbox" parent="." instance=ExtResource("9_qimey")] [node name="Hitbox" parent="." instance=ExtResource("9_qimey")]
priority = 5
IsDisabled = true IsDisabled = true
[node name="CollisionShape2D" parent="Hitbox" index="0"] [node name="CollisionShape2D" parent="Hitbox" index="0"]

View File

@ -65,9 +65,9 @@ tracks/0/path = NodePath("Anchor:position")
tracks/0/interp = 1 tracks/0/interp = 1
tracks/0/loop_wrap = true tracks/0/loop_wrap = true
tracks/0/keys = { tracks/0/keys = {
"times": PackedFloat32Array(0, 0.5), "times": PackedFloat32Array(0, 0.2),
"transitions": PackedFloat32Array(1, 1), "transitions": PackedFloat32Array(1, 1),
"update": 1, "update": 0,
"values": [Vector2(-4, 0), Vector2(0, 0)] "values": [Vector2(-4, 0), Vector2(0, 0)]
} }
tracks/1/type = "audio" tracks/1/type = "audio"
@ -92,10 +92,10 @@ tracks/2/path = NodePath("Anchor:rotation")
tracks/2/interp = 1 tracks/2/interp = 1
tracks/2/loop_wrap = true tracks/2/loop_wrap = true
tracks/2/keys = { tracks/2/keys = {
"times": PackedFloat32Array(0, 1, 1.5), "times": PackedFloat32Array(0, 0.1, 1, 1.5),
"transitions": PackedFloat32Array(1, 1, 1), "transitions": PackedFloat32Array(1, 1, 1, 1),
"update": 0, "update": 0,
"values": [6.28319, 6.28319, 0.0] "values": [6.19592, 6.28319, 6.28319, 0.0]
} }
tracks/3/type = "audio" tracks/3/type = "audio"
tracks/3/imported = false tracks/3/imported = false

View File

@ -417,7 +417,6 @@ libraries = {
} }
[node name="Hitbox" parent="." instance=ExtResource("3_up3ob")] [node name="Hitbox" parent="." instance=ExtResource("3_up3ob")]
priority = 5
IsDisabled = true IsDisabled = true
[node name="CollisionShape2D" parent="Hitbox" index="0"] [node name="CollisionShape2D" parent="Hitbox" index="0"]

View File

@ -3,7 +3,7 @@ using SupaLidlGame.Utils;
namespace SupaLidlGame.State.Global; namespace SupaLidlGame.State.Global;
public partial class GlobalState : Node public partial class GlobalState : Node, ISave
{ {
[Export] [Export]
public Progression Progression { get; set; } public Progression Progression { get; set; }
@ -14,6 +14,10 @@ public partial class GlobalState : Node
[Export] [Export]
public Stats Stats { get; set; } public Stats Stats { get; set; }
private ulong _saveTimeElapsed = 0;
public ulong TimeElapsed => _saveTimeElapsed + Godot.Time.GetTicksMsec();
public static GlobalState Instance { get; private set; } public static GlobalState Instance { get; private set; }
[Export] [Export]
@ -76,6 +80,7 @@ public partial class GlobalState : Node
Progression = save.Progression; Progression = save.Progression;
MapState = save.MapState; MapState = save.MapState;
Stats = save.Stats; Stats = save.Stats;
_saveTimeElapsed = save.TimeElapsed; // use as offset
var inventory = World.Instance.CurrentPlayer.Inventory; var inventory = World.Instance.CurrentPlayer.Inventory;
inventory.Items = Stats.Items; inventory.Items = Stats.Items;
@ -96,6 +101,7 @@ public partial class GlobalState : Node
save.Progression = Progression; save.Progression = Progression;
save.MapState = MapState; save.MapState = MapState;
save.Stats = Stats; save.Stats = Stats;
save.TimeElapsed = TimeElapsed; // update time elapsed when saving
var inventory = World.Instance.CurrentPlayer.Inventory; var inventory = World.Instance.CurrentPlayer.Inventory;
Stats.Items = inventory.Items; Stats.Items = inventory.Items;

View File

@ -56,7 +56,8 @@ public partial class RangedChargeState : WeaponState
return IdleState; return IdleState;
} }
FireState.VelocityModifier = (float)(1 - progress); FireState.VelocityModifier = (float)(1 - progress) *
FireState.InitialVelocityModifier;
return FireState; return FireState;
} }
} }

View File

@ -17,10 +17,18 @@ public partial class RangedFireState : WeaponState
[Export] [Export]
public string AnimationKey { get; set; } public string AnimationKey { get; set; }
public float VelocityModifier { get; set; } public float VelocityModifier { get; set; } = 1;
[Export]
public float InitialVelocityModifier { get; set; } = 1;
private double _timeLeft = 0; private double _timeLeft = 0;
public override void _Ready()
{
VelocityModifier = InitialVelocityModifier;
}
public override IState<WeaponState> Enter(IState<WeaponState> prev) public override IState<WeaponState> Enter(IState<WeaponState> prev)
{ {
//_timeLeft //_timeLeft

View File

@ -1,4 +1,4 @@
<Project Sdk="Godot.NET.Sdk/4.3.0-beta.1"> <Project Sdk="Godot.NET.Sdk/4.3.0">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net7.0</TargetFramework> <TargetFramework>net7.0</TargetFramework>
<EnableDynamicLoading>true</EnableDynamicLoading> <EnableDynamicLoading>true</EnableDynamicLoading>

14
Utils/ISave.cs 100644
View File

@ -0,0 +1,14 @@
using Godot;
namespace SupaLidlGame.Utils;
public interface ISave
{
public State.Global.Progression Progression { get; set; }
public State.Global.MapState MapState { get; set; }
public State.Global.Stats Stats { get; set; }
public ulong TimeElapsed { get; }
}

View File

@ -40,6 +40,7 @@ public partial class PlayerStats : CharacterStats
_xpDecayTimer = new Timer(); _xpDecayTimer = new Timer();
_xpDecayTimer.Timeout += () => _shouldDecayXP = true; _xpDecayTimer.Timeout += () => _shouldDecayXP = true;
_xpDecayTimer.OneShot = true;
_xpDecayTimer.Stop(); _xpDecayTimer.Stop();
AddChild(_xpDecayTimer); AddChild(_xpDecayTimer);

View File

@ -2,7 +2,7 @@ using Godot;
namespace SupaLidlGame.Utils; namespace SupaLidlGame.Utils;
public partial class Save : Resource public partial class Save : Resource, ISave
{ {
[Export] [Export]
public State.Global.Progression Progression { get; set; } public State.Global.Progression Progression { get; set; }
@ -13,10 +13,14 @@ public partial class Save : Resource
[Export] [Export]
public State.Global.Stats Stats { get; set; } public State.Global.Stats Stats { get; set; }
[Export]
public ulong TimeElapsed { get; set; }
public Save() public Save()
{ {
Progression = new(); Progression = new();
MapState = new(); MapState = new();
Stats = new(); Stats = new();
TimeElapsed = 0;
} }
} }

View File

@ -68,6 +68,8 @@ public partial class World : Node
private string _currentMapResourcePath; private string _currentMapResourcePath;
internal DebugCommands Debug { get; }
//private Entities.Campfire _lastCampfire = null; //private Entities.Campfire _lastCampfire = null;
private const string PLAYER_PATH = "res://Characters/Player.tscn"; private const string PLAYER_PATH = "res://Characters/Player.tscn";
@ -84,6 +86,13 @@ public partial class World : Node
{ {
throw new System.Exception("Another World instance is running."); throw new System.Exception("Another World instance is running.");
} }
Debug = new(this);
}
~World()
{
Debug.Free();
} }
public override void _Ready() public override void _Ready()
@ -336,3 +345,21 @@ public partial class World : Node
public Node FindEntity(string name) => CurrentMap.Entities.GetNode(name); public Node FindEntity(string name) => CurrentMap.Entities.GetNode(name);
} }
internal partial class DebugCommands : Godot.GodotObject
{
private World _world;
internal DebugCommands(World world)
{
_world = world;
}
internal Items.ItemMetadata GiveItem(string item)
{
var itemMetadata = ResourceLoader
.Load<Items.ItemMetadata>($"res://Items/{item}.tres");
_world.CurrentPlayer.Inventory.Add(itemMetadata);
return itemMetadata;
}
}

View File

@ -228,6 +228,8 @@ locale/translations_pot_files=PackedStringArray("res://Assets/Dialogue/doc.dialo
2d_physics/layer_5="World Clip" 2d_physics/layer_5="World Clip"
2d_physics/layer_6="Interaction Receiver" 2d_physics/layer_6="Interaction Receiver"
2d_physics/layer_7="Interaction Trigger" 2d_physics/layer_7="Interaction Trigger"
2d_physics/layer_9="Hitbox"
2d_physics/layer_10="Hurtbox"
[navigation] [navigation]