Chests and strafing speed

This commit is contained in:
Marco 2025-01-28 14:05:38 +01:00
commit b645e1724e
17 changed files with 286 additions and 21 deletions

18
Scripts/Chest.cs Normal file
View file

@ -0,0 +1,18 @@
namespace Cirno.Scripts;
public partial class Chest : Activable
{
private InventoryManager inventoryManager;
public override void _Ready()
{
inventoryManager = GetNode<InventoryManager>("/root/GameScene/InventoryManager");
}
public override void Activate()
{
inventoryManager.AddRedKeycard();
GetParent().QueueFree();
}
}

View file

@ -1,5 +1,6 @@
using Godot;
using System;
using Cirno.Scripts;
public partial class InventoryManager : Node2D
{
@ -15,6 +16,45 @@ public partial class InventoryManager : Node2D
{
}
public bool AddItem(ItemTypes type, int amount = 1)
{
switch (type)
{
case ItemTypes.KeycardRed:
RedKeycard = true;
GD.Print($"Red Keycard x{amount}");
break;
case ItemTypes.KeycardBlue:
GD.Print($"Blue Keycard x{amount}");
break;
case ItemTypes.KeycardGreen:
GD.Print($"Green Keycard x{amount}");
break;
case ItemTypes.Ammo:
GD.Print($"Ammo x{amount}");
break;
case ItemTypes.Medkit:
GD.Print($"Medkit x{amount}");
break;
case ItemTypes.CrabBomb:
GD.Print($"CrabBomb x{amount}");
break;
case ItemTypes.Bomb:
GD.Print($"Bomb x{amount}");
break;
case ItemTypes.Mine:
GD.Print($"Mine x{amount}");
break;
case ItemTypes.Battery:
GD.Print($"Battery x{amount}");
break;
default:
return false;
}
return true; // TODO: Return false if could not be added
}
public void AddRedKeycard()
{
RedKeycard = true;

14
Scripts/ItemTypes.cs Normal file
View file

@ -0,0 +1,14 @@
namespace Cirno.Scripts;
public enum ItemTypes
{
KeycardRed,
KeycardBlue,
KeycardGreen,
Ammo,
Medkit,
CrabBomb,
Bomb,
Mine,
Battery
}

View file

@ -1,19 +1,29 @@
using Godot;
using System;
using System.Collections.Generic;
using Cirno.Scripts;
using Cirno.Scripts.Resources;
using Godot.Collections;
public partial class Pickupper : Activable
{
private InventoryManager _inventoryManager;
private InventoryManager inventoryManager;
[Export] public Array<LootItem> LootTable = new Array<LootItem>();
public override void _Ready()
{
inventoryManager = GetNode<InventoryManager>("/root/GameScene/InventoryManager");
}
public override void Activate()
{
inventoryManager.AddRedKeycard();
GetParent().QueueFree();
}
}
public override void _Ready()
{
_inventoryManager = GetNode<InventoryManager>("/root/GameScene/InventoryManager");
}
public override void Activate()
{
foreach (var item in LootTable)
{
_inventoryManager.AddItem(item.Item, item.Amount);
}
//inventoryManager.AddRedKeycard();
GetParent().QueueFree(); // TODO: send a signal instead
}
}

View file

@ -7,6 +7,11 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
{
[Export]
public int Speed { get; set; } = 400;
[Export]
public int StrafeSpeed { get; set; } = 200;
public int MovementSpeed => _isStrafing ? StrafeSpeed : Speed;
[Export]
public float CrosshairDistance { get; set; } = 10f;
@ -237,7 +242,7 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
// {
// _facingDirection = _movementDirection;
// }
Velocity = _movementDirection * (float)(Speed * delta);
Velocity = _movementDirection * (float)( MovementSpeed * delta);
MoveAndSlide();
@ -246,7 +251,7 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
//FindInteractable();
}
private void _on_interaction_controller_area_entered(Area2D area)
{
// Replace with function body.

View file

@ -0,0 +1,10 @@
using Godot;
namespace Cirno.Scripts.Resources;
[GlobalClass]
public partial class LootItem : Resource
{
[Export] public ItemTypes Item;
[Export] public int Amount;
}