Working on item rescue
This commit is contained in:
@@ -1,11 +1,17 @@
|
||||
using Chickensoft.AutoInject;
|
||||
using Chickensoft.GodotNodeInterfaces;
|
||||
using Chickensoft.Introspection;
|
||||
using Godot;
|
||||
|
||||
namespace GameJamDungeon
|
||||
{
|
||||
public interface IDroppedItem : IRigidBody3D
|
||||
{
|
||||
void RescueItem();
|
||||
}
|
||||
|
||||
[Meta(typeof(IAutoNode))]
|
||||
public partial class DroppedItem : RigidBody3D
|
||||
public partial class DroppedItem : RigidBody3D, IDroppedItem
|
||||
{
|
||||
public override void _Notification(int what) => this.Notify(what);
|
||||
|
||||
@@ -13,7 +19,7 @@ namespace GameJamDungeon
|
||||
|
||||
[Dependency] public IGame Game => this.DependOn<IGame>();
|
||||
|
||||
[Node] public Sprite3D Sprite { get; set; } = default!;
|
||||
[Node] public Sprite2D Sprite { get; set; } = default!;
|
||||
|
||||
public IInventoryItem Item { get; set; }
|
||||
|
||||
@@ -32,6 +38,42 @@ namespace GameJamDungeon
|
||||
RemoveCollisionExceptionWith((Node)Game.Player);
|
||||
}
|
||||
|
||||
public void RescueItem()
|
||||
{
|
||||
ContactMonitor = false;
|
||||
PlayRescueAnimation();
|
||||
Game.RescuedItems.Items.Add(Item);
|
||||
}
|
||||
|
||||
private void PlayRescueAnimation()
|
||||
{
|
||||
LoadShader("res://src/vfx/shaders/PixelMelt.gdshader");
|
||||
var tweener = GetTree().CreateTween();
|
||||
SetShaderValue(true);
|
||||
tweener.TweenMethod(Callable.From((float x) => SetShaderValue(x)), 0.0f, 0.3f, 2f);
|
||||
tweener.TweenCallback(Callable.From(QueueFree));
|
||||
}
|
||||
|
||||
private void LoadShader(string shaderPath)
|
||||
{
|
||||
var shader = GD.Load<Shader>(shaderPath);
|
||||
Sprite.Material = new ShaderMaterial();
|
||||
var shaderMaterial = (ShaderMaterial)Sprite.Material;
|
||||
shaderMaterial.Shader = shader;
|
||||
}
|
||||
|
||||
private void SetShaderValue(float shaderValue)
|
||||
{
|
||||
var shaderMaterial = (ShaderMaterial)Sprite.Material;
|
||||
shaderMaterial.SetShaderParameter("progress", shaderValue);
|
||||
}
|
||||
|
||||
private void SetShaderValue(bool shaderValue)
|
||||
{
|
||||
var shaderMaterial = (ShaderMaterial)Sprite.Material;
|
||||
shaderMaterial.SetShaderParameter("reverse", shaderValue);
|
||||
}
|
||||
|
||||
private void DroppedItem_BodyEntered(Node body)
|
||||
{
|
||||
if (body is IPlayer player)
|
||||
|
||||
@@ -1,12 +1,54 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://brq11lswpqxei"]
|
||||
[gd_scene load_steps=9 format=3 uid="uid://brq11lswpqxei"]
|
||||
|
||||
[ext_resource type="Script" path="res://src/items/dropped/DroppedItem.cs" id="1_67jk4"]
|
||||
[ext_resource type="Texture2D" uid="uid://mi70lolgtf3n" path="res://src/items/throwable/textures/GEOMANCER-DICE.png" id="2_cu1v3"]
|
||||
[ext_resource type="Material" uid="uid://x2bv1q51mcjq" path="res://src/enemy/PixelMelt.tres" id="2_eat5q"]
|
||||
|
||||
[sub_resource type="SphereShape3D" id="SphereShape3D_28r8g"]
|
||||
|
||||
[sub_resource type="Animation" id="Animation_x5q15"]
|
||||
resource_name = "ItemRescued"
|
||||
length = 2.0
|
||||
step = 0.0666667
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("Sprite3D:position")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0, 1.99543),
|
||||
"transitions": PackedFloat32Array(1, 1),
|
||||
"update": 0,
|
||||
"values": [Vector3(0.0207178, 0.192374, 0), Vector3(0.0207178, 1.26338, 0)]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_eat5q"]
|
||||
length = 0.001
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("Sprite3D:position")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 0,
|
||||
"values": [Vector3(0.0207178, 0.192374, 0)]
|
||||
}
|
||||
|
||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_eat5q"]
|
||||
_data = {
|
||||
&"ItemRescued": SubResource("Animation_x5q15"),
|
||||
&"RESET": SubResource("Animation_eat5q")
|
||||
}
|
||||
|
||||
[sub_resource type="ViewportTexture" id="ViewportTexture_x5q15"]
|
||||
viewport_path = NodePath("Sprite3D/SubViewport")
|
||||
|
||||
[node name="DroppedItem" type="RigidBody3D"]
|
||||
collision_layer = 0
|
||||
collision_layer = 1024
|
||||
collision_mask = 5
|
||||
axis_lock_angular_x = true
|
||||
axis_lock_angular_y = true
|
||||
@@ -19,8 +61,29 @@ script = ExtResource("1_67jk4")
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
shape = SubResource("SphereShape3D_28r8g")
|
||||
|
||||
[node name="Sprite" type="Sprite3D" parent="."]
|
||||
unique_name_in_owner = true
|
||||
pixel_size = 0.0005
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
|
||||
libraries = {
|
||||
&"": SubResource("AnimationLibrary_eat5q")
|
||||
}
|
||||
|
||||
[node name="Sprite3D" type="Sprite3D" parent="."]
|
||||
transform = Transform3D(0.41, 0, 0, 0, 0.41, 0, 0, 0, 0.41, 0.0207178, 0.192374, 0)
|
||||
billboard = 2
|
||||
shaded = true
|
||||
texture_filter = 0
|
||||
render_priority = 100
|
||||
texture = SubResource("ViewportTexture_x5q15")
|
||||
|
||||
[node name="SubViewport" type="SubViewport" parent="Sprite3D"]
|
||||
disable_3d = true
|
||||
transparent_bg = true
|
||||
handle_input_locally = false
|
||||
render_target_update_mode = 4
|
||||
|
||||
[node name="Sprite" type="Sprite2D" parent="Sprite3D/SubViewport"]
|
||||
unique_name_in_owner = true
|
||||
material = ExtResource("2_eat5q")
|
||||
scale = Vector2(0.1, 0.1)
|
||||
texture = ExtResource("2_cu1v3")
|
||||
centered = false
|
||||
offset = Vector2(2000, 2000)
|
||||
|
||||
@@ -20,3 +20,7 @@ A wand fitted with charms said to cleanse and purify that which belongs to other
|
||||
It's unaligned nature has the power to balance all that it comes into contact with, should the wielder have the will."
|
||||
Texture = ExtResource("1_wiylj")
|
||||
SpawnRate = 0.5
|
||||
ThrowSpeed = 12.0
|
||||
HealHPAmount = 0
|
||||
HealVTAmount = 0
|
||||
ThrowDamage = 5
|
||||
|
||||
Reference in New Issue
Block a user