Throw item

This commit is contained in:
2024-09-22 14:40:53 -07:00
parent 490f0d17d2
commit 84ee313ce5
9 changed files with 30 additions and 34 deletions

View File

@@ -13,6 +13,8 @@ public interface IGame : IProvide<IGameRepo>, IProvide<IGameEventDepot>, IProvid
public IPlayer Player { get; } public IPlayer Player { get; }
public void DropItem(IInventoryItem item); public void DropItem(IInventoryItem item);
public void ThrowItem(IInventoryItem item);
} }
[Meta(typeof(IAutoNode))] [Meta(typeof(IAutoNode))]
@@ -143,6 +145,15 @@ public partial class Game : Node3D, IGame
dropped.Drop(); dropped.Drop();
} }
public void ThrowItem(IInventoryItem item)
{
var thrownScene = GD.Load<PackedScene>("res://src/items/thrown/ThrownItem.tscn");
var thrown = thrownScene.Instantiate<ThrownItem>();
thrown.ThrownItemStats = item.Info;
AddChild(thrown);
thrown.Throw();
}
private void OnEnemyDefeated(Vector3 vector, EnemyStatResource resource) private void OnEnemyDefeated(Vector3 vector, EnemyStatResource resource)
{ {
var restorativeScene = GD.Load<PackedScene>("res://src/items/restorative/Restorative.tscn"); var restorativeScene = GD.Load<PackedScene>("res://src/items/restorative/Restorative.tscn");

View File

@@ -237,6 +237,9 @@ public partial class InventoryMenu : Control, IInventoryMenu
{ {
foreach (var item in ItemSlots) foreach (var item in ItemSlots)
ItemsPage.RemoveChildEx(item); ItemsPage.RemoveChildEx(item);
ItemDescriptionTitle.Text = string.Empty;
ItemEffectLabel.Text = string.Empty;
} }
private void PopulatePlayerInfo() private void PopulatePlayerInfo()
@@ -408,23 +411,22 @@ public partial class InventoryMenu : Control, IInventoryMenu
{ {
var currentItem = ItemSlots[_currentIndex].Item; var currentItem = ItemSlots[_currentIndex].Item;
if (currentItem is IThrowableItem throwable) Game.ThrowItem(currentItem);
{ GameRepo.PlayerData.Inventory.Remove(currentItem);
throwable.Throw();
if (_currentIndex >= ItemSlots.Length - 1) if (_currentIndex >= ItemSlots.Length - 1)
_currentIndex--; _currentIndex--;
if (_currentIndex <= 0) if (_currentIndex <= 0)
_currentIndex = 0; _currentIndex = 0;
EmitSignal(SignalName.ClosedMenu); EmitSignal(SignalName.ClosedMenu);
}
} }
private async void DropButtonPressed() private async void DropButtonPressed()
{ {
var currentItem = ItemSlots[_currentIndex].Item; var currentItem = ItemSlots[_currentIndex].Item;
Game.DropItem(currentItem); Game.DropItem(currentItem);
GameRepo.PlayerData.Inventory.Remove(currentItem);
if (_currentIndex >= ItemSlots.Length - 1) if (_currentIndex >= ItemSlots.Length - 1)
_currentIndex--; _currentIndex--;

View File

@@ -1,5 +1,4 @@
using Chickensoft.GodotNodeInterfaces; using Chickensoft.GodotNodeInterfaces;
using Godot;
using System; using System;
namespace GameJamDungeon namespace GameJamDungeon
@@ -15,9 +14,4 @@ namespace GameJamDungeon
{ {
public void Use(); public void Use();
} }
public interface IThrowableItem : IInventoryItem
{
public void Throw();
}
} }

View File

@@ -5,7 +5,7 @@ using Godot;
using System; using System;
[Meta(typeof(IAutoNode))] [Meta(typeof(IAutoNode))]
public partial class Accessory : Node3D, IEquipableItem, IThrowableItem public partial class Accessory : Node3D, IEquipableItem
{ {
public override void _Notification(int what) => this.Notify(what); public override void _Notification(int what) => this.Notify(what);

View File

@@ -5,7 +5,7 @@ using Godot;
using System; using System;
[Meta(typeof(IAutoNode))] [Meta(typeof(IAutoNode))]
public partial class Armor : Node3D, IEquipableItem, IThrowableItem public partial class Armor : Node3D, IEquipableItem
{ {
public override void _Notification(int what) => this.Notify(what); public override void _Notification(int what) => this.Notify(what);

View File

@@ -5,7 +5,7 @@ using Godot;
using System; using System;
[Meta(typeof(IAutoNode))] [Meta(typeof(IAutoNode))]
public partial class ConsumableItem : Node3D, IUsableItem, IThrowableItem public partial class ConsumableItem : Node3D, IUsableItem
{ {
public override void _Notification(int what) => this.Notify(what); public override void _Notification(int what) => this.Notify(what);

View File

@@ -5,7 +5,7 @@ using Godot;
using System; using System;
[Meta(typeof(IAutoNode))] [Meta(typeof(IAutoNode))]
public partial class ThrowableItem : Node3D, IThrowableItem public partial class ThrowableItem : Node3D, IInventoryItem
{ {
public override void _Notification(int what) => this.Notify(what); public override void _Notification(int what) => this.Notify(what);
@@ -32,16 +32,6 @@ public partial class ThrowableItem : Node3D, IThrowableItem
Pickup.BodyEntered += OnEntered; Pickup.BodyEntered += OnEntered;
} }
public void Throw()
{
var throwableScene = GD.Load<PackedScene>("res://src/items/thrown/ThrownItem.tscn");
var throwable = throwableScene.Instantiate<ThrownItem>();
throwable.ThrownItemStats = ThrowableItemInfo;
Game.AddChild(throwable);
throwable.Throw();
GameRepo.PlayerData.Inventory.Remove(this);
}
public void OnEntered(Node3D body) public void OnEntered(Node3D body)
{ {
var isAdded = GameRepo.PlayerData.Inventory.TryAdd(this); var isAdded = GameRepo.PlayerData.Inventory.TryAdd(this);

View File

@@ -17,7 +17,7 @@ public partial class ThrownItem : RigidBody3D
public void OnResolved() public void OnResolved()
{ {
BodyEntered += ThrownItem_BodyEntered; BodyEntered += ThrownItem_BodyEntered;
GlobalPosition = Game.Player.GlobalPosition + Vector3.Up; GlobalPosition = Game.Player.GlobalPosition + new Vector3(0, 1.5f, 0);
Sprite.Texture = ThrownItemStats.Texture; Sprite.Texture = ThrownItemStats.Texture;
AddCollisionExceptionWith((Node)Game.Player); AddCollisionExceptionWith((Node)Game.Player);
} }

View File

@@ -4,19 +4,18 @@
[ext_resource type="Texture2D" uid="uid://mi70lolgtf3n" path="res://src/items/throwable/textures/GEOMANCER-DICE.png" id="2_alcjn"] [ext_resource type="Texture2D" uid="uid://mi70lolgtf3n" path="res://src/items/throwable/textures/GEOMANCER-DICE.png" id="2_alcjn"]
[sub_resource type="BoxShape3D" id="BoxShape3D_s4ym5"] [sub_resource type="BoxShape3D" id="BoxShape3D_s4ym5"]
size = Vector3(0.288967, 0.302734, 0.28064) size = Vector3(1.43084, 1.23022, 1.52861)
[node name="Hitbox" type="RigidBody3D"] [node name="Hitbox" type="RigidBody3D"]
collision_layer = 17 collision_layer = 17
collision_mask = 16 collision_mask = 16
mass = 0.001 gravity_scale = 0.25
gravity_scale = 0.0
contact_monitor = true contact_monitor = true
max_contacts_reported = 1 max_contacts_reported = 1
script = ExtResource("1_wlplc") script = ExtResource("1_wlplc")
[node name="CollisionShape3D" type="CollisionShape3D" parent="."] [node name="CollisionShape3D" type="CollisionShape3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.00739601, 0.0986328, 0.137878) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.0274667, 0.116821, 0.118644)
shape = SubResource("BoxShape3D_s4ym5") shape = SubResource("BoxShape3D_s4ym5")
[node name="Sprite" type="Sprite3D" parent="."] [node name="Sprite" type="Sprite3D" parent="."]