Basic throw works
This commit is contained in:
21
src/items/throwable/Dissolve.gdshader
Normal file
21
src/items/throwable/Dissolve.gdshader
Normal file
@@ -0,0 +1,21 @@
|
||||
shader_type canvas_item;
|
||||
|
||||
float random(vec2 uv) {
|
||||
return fract(sin(dot(uv, vec2(12.9898, 78.233))) * 438.5453);
|
||||
}
|
||||
|
||||
uniform float sensitivity : hint_range(0.0, 1.0) = .5;
|
||||
|
||||
void fragment() {
|
||||
// Get size of texture in pixels
|
||||
float size_x = float(textureSize(TEXTURE, 0).x);
|
||||
float size_y = float(textureSize(TEXTURE, 0).y);
|
||||
//
|
||||
vec4 pixelColor = texture(TEXTURE, UV);
|
||||
// Create a new "UV" which remaps every UV value to a snapped pixel value
|
||||
vec2 UVr = vec2(floor(UV.x*size_x)/size_x, floor(UV.y*size_y)/size_y);
|
||||
// Determine whether pixel should be visible or not
|
||||
float visible = step(sensitivity, random(UVr));
|
||||
// Draw the pixel, or not depending on if it is visible or not
|
||||
COLOR = vec4(pixelColor.r, pixelColor.g, pixelColor.b, min(visible, pixelColor.a));
|
||||
}
|
||||
@@ -11,7 +11,7 @@ public partial class ThrowableItem : Node3D, IInventoryItem
|
||||
|
||||
[Dependency] public IGameRepo GameRepo => this.DependOn<IGameRepo>();
|
||||
|
||||
[Node] public IHitbox Hitbox { get; set; } = default!;
|
||||
[Dependency] public IGame Game => this.DependOn<IGame>();
|
||||
|
||||
public InventoryItemStats Info => ThrowableItemInfo;
|
||||
|
||||
@@ -26,15 +26,18 @@ public partial class ThrowableItem : Node3D, IInventoryItem
|
||||
|
||||
[Node] public Area3D Pickup { get; set; } = default!;
|
||||
|
||||
public void OnReady()
|
||||
public void OnResolved()
|
||||
{
|
||||
Sprite.Texture = ThrowableItemInfo.Texture;
|
||||
Pickup.BodyEntered += OnEntered;
|
||||
}
|
||||
|
||||
public void Throw()
|
||||
public void Throw(ThrowableItemStats throwableItemStats)
|
||||
{
|
||||
GameRepo.PlayerData.Inventory.Remove(this);
|
||||
var throwableScene = GD.Load<PackedScene>("res://src/items/throwable/ThrownItem.tscn");
|
||||
var throwable = throwableScene.Instantiate<ThrownItem>();
|
||||
Game.AddChild(throwable);
|
||||
throwable.Throw(throwableItemStats);
|
||||
}
|
||||
|
||||
public void Drop()
|
||||
@@ -48,9 +51,4 @@ public partial class ThrowableItem : Node3D, IInventoryItem
|
||||
if (isAdded)
|
||||
QueueFree();
|
||||
}
|
||||
|
||||
private void OnAnimationFinished(StringName animName)
|
||||
{
|
||||
QueueFree();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,41 +1,26 @@
|
||||
[gd_scene load_steps=6 format=3 uid="uid://1fl6s352e2ej"]
|
||||
[gd_scene load_steps=3 format=3 uid="uid://1fl6s352e2ej"]
|
||||
|
||||
[ext_resource type="Script" path="res://src/items/throwable/ThrowableItem.cs" id="1_nac2l"]
|
||||
[ext_resource type="Resource" uid="uid://bph8c6by4s047" path="res://src/items/throwable/resources/GeomanticDice.tres" id="2_pefeg"]
|
||||
[ext_resource type="Script" path="res://src/hitbox/Hitbox.cs" id="3_qpunu"]
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_qihtb"]
|
||||
size = Vector3(0.371643, 0.289612, 0.286743)
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_03cqg"]
|
||||
size = Vector3(0.778381, 0.929947, 0.731567)
|
||||
|
||||
[node name="ThrowableItem" type="Node3D"]
|
||||
script = ExtResource("1_nac2l")
|
||||
ThrowableItemInfo = ExtResource("2_pefeg")
|
||||
|
||||
[node name="Hitbox" type="Area3D" parent="."]
|
||||
[node name="Pickup" type="Area3D" parent="."]
|
||||
unique_name_in_owner = true
|
||||
collision_layer = 16
|
||||
collision_mask = 16
|
||||
script = ExtResource("3_qpunu")
|
||||
collision_layer = 0
|
||||
collision_mask = 4
|
||||
|
||||
[node name="Sprite" type="Sprite3D" parent="Hitbox"]
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="Pickup"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.0600509, 0.26725, 0.180481)
|
||||
shape = SubResource("BoxShape3D_03cqg")
|
||||
|
||||
[node name="Sprite" type="Sprite3D" parent="Pickup"]
|
||||
unique_name_in_owner = true
|
||||
pixel_size = 0.0005
|
||||
billboard = 2
|
||||
shaded = true
|
||||
texture_filter = 0
|
||||
render_priority = 100
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="Hitbox"]
|
||||
shape = SubResource("BoxShape3D_qihtb")
|
||||
|
||||
[node name="Pickup" type="Area3D" parent="Hitbox"]
|
||||
unique_name_in_owner = true
|
||||
collision_layer = 0
|
||||
collision_mask = 4
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="Hitbox/Pickup"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.0600509, 0.26725, 0.180481)
|
||||
shape = SubResource("BoxShape3D_03cqg")
|
||||
|
||||
@@ -5,6 +5,9 @@ namespace GameJamDungeon;
|
||||
[GlobalClass]
|
||||
public partial class ThrowableItemStats : InventoryItemStats
|
||||
{
|
||||
[Export]
|
||||
public int Damage { get; set; } = 0;
|
||||
|
||||
[Export]
|
||||
public Godot.Collections.Array<ThrowableItemTag> ThrowableItemTags { get; set; } = new Godot.Collections.Array<ThrowableItemTag>();
|
||||
}
|
||||
|
||||
37
src/items/throwable/ThrownItem.cs
Normal file
37
src/items/throwable/ThrownItem.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using Chickensoft.AutoInject;
|
||||
using Chickensoft.GodotNodeInterfaces;
|
||||
using Chickensoft.Introspection;
|
||||
using GameJamDungeon;
|
||||
using Godot;
|
||||
|
||||
[Meta(typeof(IAutoNode))]
|
||||
public partial class ThrownItem : RigidBody3D
|
||||
{
|
||||
public override void _Notification(int what) => this.Notify(what);
|
||||
|
||||
[Dependency] public IGame Game => this.DependOn<IGame>();
|
||||
|
||||
[Node] public Sprite2D Sprite { get; set; } = default!;
|
||||
|
||||
private int _damage = 0;
|
||||
|
||||
public void OnResolved()
|
||||
{
|
||||
BodyEntered += ThrownItem_BodyEntered;
|
||||
GlobalPosition = Game.Player.GlobalPosition + Vector3.Up;
|
||||
AddCollisionExceptionWith((Node)Game.Player);
|
||||
}
|
||||
|
||||
private void ThrownItem_BodyEntered(Node body)
|
||||
{
|
||||
if (body is IEnemy enemy)
|
||||
enemy.EnemyLogic.Input(new EnemyLogic.Input.HitByPlayer(_damage));
|
||||
QueueFree();
|
||||
}
|
||||
|
||||
public void Throw(ThrowableItemStats throwableItemStats)
|
||||
{
|
||||
_damage = throwableItemStats.Damage;
|
||||
ApplyCentralImpulse(Game.Player.GlobalBasis.Z.Normalized() * -20.0f);
|
||||
}
|
||||
}
|
||||
48
src/items/throwable/ThrownItem.tscn
Normal file
48
src/items/throwable/ThrownItem.tscn
Normal file
@@ -0,0 +1,48 @@
|
||||
[gd_scene load_steps=7 format=3 uid="uid://b1twcuneob5kt"]
|
||||
|
||||
[ext_resource type="Script" path="res://src/items/throwable/ThrownItem.cs" id="1_l0mpw"]
|
||||
[ext_resource type="Shader" path="res://src/items/throwable/Dissolve.gdshader" id="2_lukp6"]
|
||||
[ext_resource type="Texture2D" uid="uid://mi70lolgtf3n" path="res://src/items/throwable/textures/GEOMANCER-DICE.png" id="2_oyhi4"]
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_s4ym5"]
|
||||
size = Vector3(0.288967, 0.302734, 0.28064)
|
||||
|
||||
[sub_resource type="ViewportTexture" id="ViewportTexture_vebu3"]
|
||||
viewport_path = NodePath("Sprite3D/SubViewport")
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_vnlpn"]
|
||||
shader = ExtResource("2_lukp6")
|
||||
shader_parameter/sensitivity = 0.0
|
||||
|
||||
[node name="Hitbox" type="RigidBody3D"]
|
||||
collision_layer = 17
|
||||
collision_mask = 16
|
||||
mass = 0.001
|
||||
gravity_scale = 0.0
|
||||
contact_monitor = true
|
||||
max_contacts_reported = 1
|
||||
script = ExtResource("1_l0mpw")
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.00739601, 0.0986328, 0.137878)
|
||||
shape = SubResource("BoxShape3D_s4ym5")
|
||||
|
||||
[node name="Sprite3D" type="Sprite3D" parent="."]
|
||||
billboard = 2
|
||||
double_sided = false
|
||||
texture = SubResource("ViewportTexture_vebu3")
|
||||
|
||||
[node name="SubViewport" type="SubViewport" parent="Sprite3D"]
|
||||
disable_3d = true
|
||||
transparent_bg = true
|
||||
handle_input_locally = false
|
||||
size = Vector2i(100, 100)
|
||||
|
||||
[node name="Sprite" type="Sprite2D" parent="Sprite3D/SubViewport"]
|
||||
unique_name_in_owner = true
|
||||
z_index = 100
|
||||
material = SubResource("ShaderMaterial_vnlpn")
|
||||
scale = Vector2(0.1, 0.1)
|
||||
texture = ExtResource("2_oyhi4")
|
||||
centered = false
|
||||
flip_h = true
|
||||
Reference in New Issue
Block a user