add StacksWith property

item-info
HumanoidSandvichDispenser 2023-03-19 13:54:48 -07:00
parent cfb3af6519
commit 548e9131f2
Signed by: sandvich
GPG Key ID: 9A39BE37E602B22D
9 changed files with 87 additions and 33 deletions

View File

@ -212,7 +212,7 @@ namespace SupaLidlGame.Characters
if (this.GetNode("HurtSound") is AudioStreamPlayer2D sound) if (this.GetNode("HurtSound") is AudioStreamPlayer2D sound)
{ {
sound.Play(); sound.PlayOnRoot();
} }
} }
} }

View File

@ -72,11 +72,6 @@ namespace SupaLidlGame.Characters
} }
DrawLine(Vector2.Zero, vec, c); DrawLine(Vector2.Zero, vec, c);
} }
/*
DrawLine(Vector2.Zero, Direction * 32, new Color(0, 1, 0));
DrawLine(Vector2.Zero, Target * 32, Colors.Blue);
DrawLine(Vector2.Zero, _blockingDir, Colors.Red, 2);
*/
#endif #endif
base._Draw(); base._Draw();
@ -110,7 +105,6 @@ namespace SupaLidlGame.Characters
QueueRedraw(); QueueRedraw();
} }
//Direction = GetDirection(Target);
Direction = _weightDirs[_bestWeightIdx]; Direction = _weightDirs[_bestWeightIdx];
} }
@ -228,10 +222,6 @@ namespace SupaLidlGame.Characters
directWeight = 1 - Mathf.Pow(Mathf.E, -(dist / PreferredDistance)); directWeight = 1 - Mathf.Pow(Mathf.E, -(dist / PreferredDistance));
strafeWeight = 1 - directWeight; strafeWeight = 1 - directWeight;
/*
Vector2 midpoint = (strafeDir * strafeWeight)
.Midpoint(directDir * directWeight);
*/
Vector2 midpoint = (directDir * directWeight) Vector2 midpoint = (directDir * directWeight)
.Midpoint(strafeDir * strafeWeight); .Midpoint(strafeDir * strafeWeight);
@ -269,9 +259,6 @@ namespace SupaLidlGame.Characters
{ {
Vector2 position = (Vector2)result["position"]; Vector2 position = (Vector2)result["position"];
float hitDist = GlobalPosition.DistanceTo(position); float hitDist = GlobalPosition.DistanceTo(position);
//float hitDist = GlobalPosition.DistanceSquaredTo(position);
//float rayDist = Mathf.Pow(rayLength, 2);
//float weight = rayDist - hitDist;
float weight = rayLength - hitDist; float weight = rayLength - hitDist;
GD.Print(weight); GD.Print(weight);
rays[i] = _weightDirs[i] * weight; rays[i] = _weightDirs[i] * weight;
@ -289,8 +276,9 @@ namespace SupaLidlGame.Characters
protected virtual void Think() protected virtual void Think()
{ {
// TODO: the entity should wander if it doesn't find a best target
Vector2 pos = FindBestTarget().GlobalPosition; Vector2 pos = FindBestTarget().GlobalPosition;
Target = pos - GlobalPosition;//GlobalPosition.DirectionTo(pos); Target = pos - GlobalPosition;
Vector2 dir = Target; Vector2 dir = Target;
float dist = GlobalPosition.DistanceSquaredTo(pos); float dist = GlobalPosition.DistanceSquaredTo(pos);
UpdateWeights(pos); UpdateWeights(pos);

View File

@ -26,7 +26,7 @@ namespace SupaLidlGame.Characters
return; return;
} }
_sprite.Animation = value; _sprite.Play(value);
} }
} }

View File

@ -15,7 +15,7 @@
[sub_resource type="ShaderMaterial" id="ShaderMaterial_h78y7"] [sub_resource type="ShaderMaterial" id="ShaderMaterial_h78y7"]
shader = ExtResource("2_ngsgt") shader = ExtResource("2_ngsgt")
shader_parameter/color = null shader_parameter/color = Quaternion(1, 1, 1, 1)
shader_parameter/intensity = 0.0 shader_parameter/intensity = 0.0
[sub_resource type="AtlasTexture" id="AtlasTexture_us1ce"] [sub_resource type="AtlasTexture" id="AtlasTexture_us1ce"]
@ -48,12 +48,33 @@ region = Rect2(144, 0, 24, 24)
[sub_resource type="SpriteFrames" id="SpriteFrames_2h7cf"] [sub_resource type="SpriteFrames" id="SpriteFrames_2h7cf"]
animations = [{ animations = [{
"frames": [SubResource("AtlasTexture_us1ce"), SubResource("AtlasTexture_hn4kf")], "frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_us1ce")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_hn4kf")
}],
"loop": true, "loop": true,
"name": &"idle", "name": &"idle",
"speed": 5.0 "speed": 5.0
}, { }, {
"frames": [SubResource("AtlasTexture_wfbeq"), SubResource("AtlasTexture_qlmwk"), SubResource("AtlasTexture_l1vgu"), SubResource("AtlasTexture_ytlaa"), SubResource("AtlasTexture_1q30d")], "frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_wfbeq")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_qlmwk")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_l1vgu")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_ytlaa")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_1q30d")
}],
"loop": true, "loop": true,
"name": &"move", "name": &"move",
"speed": 12.0 "speed": 12.0
@ -125,9 +146,8 @@ position_smoothing_speed = 8.0
[node name="Sprite" type="AnimatedSprite2D" parent="."] [node name="Sprite" type="AnimatedSprite2D" parent="."]
use_parent_material = true use_parent_material = true
frames = SubResource("SpriteFrames_2h7cf") sprite_frames = SubResource("SpriteFrames_2h7cf")
animation = &"move" animation = &"idle"
playing = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="."] [node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2(0, 8) position = Vector2(0, 8)
@ -158,6 +178,7 @@ layout_mode = 3
anchors_preset = 0 anchors_preset = 0
[node name="State" type="Label" parent="Debug"] [node name="State" type="Label" parent="Debug"]
layout_mode = 0
offset_left = -20.0 offset_left = -20.0
offset_top = -60.0 offset_top = -60.0
offset_right = 20.0 offset_right = 20.0

View File

@ -0,0 +1,24 @@
using Godot;
namespace SupaLidlGame
{
public static class AudioStreamPlayer2DExtensions
{
public static void PlayOn(this AudioStreamPlayer2D audio, Node parent)
{
var clone = audio.Duplicate() as AudioStreamPlayer2D;
parent.AddChild(clone);
clone.Play();
clone.Finished += () =>
{
clone.QueueFree();
};
}
public static void PlayOnRoot(this AudioStreamPlayer2D audio)
{
var root = audio.GetTree().Root.GetChild(0);
audio.PlayOn(root);
}
}
}

View File

@ -5,11 +5,39 @@ namespace SupaLidlGame.Items
{ {
public abstract partial class Item : Node2D public abstract partial class Item : Node2D
{ {
[Export]
public string ItemName { get; set; }
[Export] [Export]
public string Description { get; set; } public string Description { get; set; }
[Export]
public int StackSize { get; set; }
public int Count { get; set; } = 1;
public Character CharacterOwner { get; set; } public Character CharacterOwner { get; set; }
/// <summary>
/// Determines if this item can stack with other items
/// </summary>
public virtual bool StacksWith(Item item)
{
if (ItemName != item.ItemName)
{
return false;
}
if (Count + item.Count <= StackSize)
{
return true;
}
// several more conditions may be added soon
return false;
}
public abstract void Equip(Character character); public abstract void Equip(Character character);
public abstract void Unequip(Character character); public abstract void Unequip(Character character);

View File

@ -47,6 +47,8 @@ namespace SupaLidlGame.Items
public Character Character { get; set; } public Character Character { get; set; }
public override bool StacksWith(Item item) => false;
public override void Equip(Character character) public override void Equip(Character character)
{ {
Character = character; Character = character;

View File

@ -108,15 +108,6 @@ namespace SupaLidlGame.Items.Weapons
public override void _Process(double delta) public override void _Process(double delta)
{ {
/*
if (RemainingAttackTime > 0)
{
if ((RemainingAttackTime -= delta) <= 0)
{
Deattack();
}
}
*/
base._Process(delta); base._Process(delta);
} }
@ -148,7 +139,7 @@ namespace SupaLidlGame.Items.Weapons
IsParried = true; IsParried = true;
AnimationPlayer.SpeedScale = 0.25f; AnimationPlayer.SpeedScale = 0.25f;
Character.Stun(1.5f); Character.Stun(1.5f);
GetNode<AudioStreamPlayer2D>("ParrySound").Play(); GetNode<AudioStreamPlayer2D>("ParrySound").PlayOnRoot();
} }
} }
//this.GetAncestor<TileMap>().AddChild(instance); //this.GetAncestor<TileMap>().AddChild(instance);
@ -166,7 +157,6 @@ namespace SupaLidlGame.Items.Weapons
Weapon w = hb.GetAncestor<Weapon>(); Weapon w = hb.GetAncestor<Weapon>();
if (w is not null) if (w is not null)
{ {
//Vector2 a = new Vector2(2, 2) * new Vector2(5, 2);
AttemptParry(w); AttemptParry(w);
} }
} }

View File

@ -307,6 +307,7 @@ ParryParticles = NodePath("Anchor/Sprite2D/ParryParticles")
Damage = 20.0 Damage = 20.0
UseTime = 0.8 UseTime = 0.8
Knockback = 80.0 Knockback = 80.0
ItemName = "Sword"
Description = "A basic sword." Description = "A basic sword."
[node name="Anchor" type="Node2D" parent="."] [node name="Anchor" type="Node2D" parent="."]