Working on item rescue
This commit is contained in:
22
src/item_rescue/ItemRescue.cs
Normal file
22
src/item_rescue/ItemRescue.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using Chickensoft.AutoInject;
|
||||
using Chickensoft.Introspection;
|
||||
using GameJamDungeon;
|
||||
using Godot;
|
||||
|
||||
[Meta(typeof(IAutoNode))]
|
||||
public partial class ItemRescue : Area3D
|
||||
{
|
||||
public override void _Notification(int what) => this.Notify(what);
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
BodyEntered += OnItemRescueEntered;
|
||||
}
|
||||
|
||||
public void OnItemRescueEntered(Node3D item)
|
||||
{
|
||||
GD.Print("Item rescue entered");
|
||||
if (item is IDroppedItem droppedItem)
|
||||
droppedItem.RescueItem();
|
||||
}
|
||||
}
|
||||
20
src/item_rescue/ItemRescue.tscn
Normal file
20
src/item_rescue/ItemRescue.tscn
Normal file
@@ -0,0 +1,20 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://duis2vhf5ojy3"]
|
||||
|
||||
[ext_resource type="Script" path="res://src/item_rescue/ItemRescue.cs" id="1_j1jha"]
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_ykgmd"]
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_j1jha"]
|
||||
transparency = 1
|
||||
albedo_color = Color(0.486275, 1, 0.443137, 0.309804)
|
||||
|
||||
[node name="Item Rescue" type="Area3D"]
|
||||
collision_layer = 0
|
||||
collision_mask = 1024
|
||||
script = ExtResource("1_j1jha")
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
shape = SubResource("BoxShape3D_ykgmd")
|
||||
|
||||
[node name="SenseSphere" type="CSGSphere3D" parent="."]
|
||||
material = SubResource("StandardMaterial3D_j1jha")
|
||||
14
src/item_rescue/RescuedItemDatabase.cs
Normal file
14
src/item_rescue/RescuedItemDatabase.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace GameJamDungeon.src.item_rescue
|
||||
{
|
||||
public class RescuedItemDatabase
|
||||
{
|
||||
public List<IInventoryItem> Items;
|
||||
|
||||
public RescuedItemDatabase()
|
||||
{
|
||||
Items = new List<IInventoryItem>();
|
||||
}
|
||||
}
|
||||
}
|
||||
32
src/item_rescue/RescuedItems.cs
Normal file
32
src/item_rescue/RescuedItems.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using Chickensoft.AutoInject;
|
||||
using Chickensoft.Introspection;
|
||||
using GameJamDungeon;
|
||||
using Godot;
|
||||
|
||||
[Meta(typeof(IAutoNode))]
|
||||
public partial class RescuedItems : Marker3D
|
||||
{
|
||||
public override void _Notification(int what) => this.Notify(what);
|
||||
|
||||
[Dependency] public IGame Game => this.DependOn<IGame>();
|
||||
|
||||
public void SpawnRescuedItems()
|
||||
{
|
||||
foreach (var item in Game.RescuedItems.Items)
|
||||
{
|
||||
var droppedScene = GD.Load<PackedScene>("res://src/items/dropped/DroppedItem.tscn");
|
||||
var dropped = droppedScene.Instantiate<DroppedItem>();
|
||||
dropped.Item = item;
|
||||
dropped.GlobalPosition = GlobalPosition;
|
||||
AddChild(dropped);
|
||||
}
|
||||
|
||||
Game.RescuedItems.Items.Clear();
|
||||
}
|
||||
|
||||
public void OnSpawnItemsEntered(Node3D body)
|
||||
{
|
||||
GD.Print("Spawn items");
|
||||
SpawnRescuedItems();
|
||||
}
|
||||
}
|
||||
6
src/item_rescue/RescuedItems.tscn
Normal file
6
src/item_rescue/RescuedItems.tscn
Normal file
@@ -0,0 +1,6 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://tc5kdfoggrng"]
|
||||
|
||||
[ext_resource type="Script" path="res://src/item_rescue/RescuedItems.cs" id="1_m08l5"]
|
||||
|
||||
[node name="Rescued Items" type="Marker3D"]
|
||||
script = ExtResource("1_m08l5")
|
||||
Reference in New Issue
Block a user