diff --git a/Characters/Character.cs b/Characters/Character.cs index 7f65604..e6c86ba 100644 --- a/Characters/Character.cs +++ b/Characters/Character.cs @@ -212,7 +212,7 @@ namespace SupaLidlGame.Characters if (this.GetNode("HurtSound") is AudioStreamPlayer2D sound) { - sound.Play(); + sound.PlayOnRoot(); } } } diff --git a/Characters/NPC.cs b/Characters/NPC.cs index a5da9ff..85f957b 100644 --- a/Characters/NPC.cs +++ b/Characters/NPC.cs @@ -72,11 +72,6 @@ namespace SupaLidlGame.Characters } 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 base._Draw(); @@ -110,7 +105,6 @@ namespace SupaLidlGame.Characters QueueRedraw(); } - //Direction = GetDirection(Target); Direction = _weightDirs[_bestWeightIdx]; } @@ -228,10 +222,6 @@ namespace SupaLidlGame.Characters directWeight = 1 - Mathf.Pow(Mathf.E, -(dist / PreferredDistance)); strafeWeight = 1 - directWeight; - /* - Vector2 midpoint = (strafeDir * strafeWeight) - .Midpoint(directDir * directWeight); - */ Vector2 midpoint = (directDir * directWeight) .Midpoint(strafeDir * strafeWeight); @@ -269,9 +259,6 @@ namespace SupaLidlGame.Characters { Vector2 position = (Vector2)result["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; GD.Print(weight); rays[i] = _weightDirs[i] * weight; @@ -289,8 +276,9 @@ namespace SupaLidlGame.Characters protected virtual void Think() { + // TODO: the entity should wander if it doesn't find a best target Vector2 pos = FindBestTarget().GlobalPosition; - Target = pos - GlobalPosition;//GlobalPosition.DirectionTo(pos); + Target = pos - GlobalPosition; Vector2 dir = Target; float dist = GlobalPosition.DistanceSquaredTo(pos); UpdateWeights(pos); diff --git a/Characters/Player.cs b/Characters/Player.cs index 3990467..9c619be 100644 --- a/Characters/Player.cs +++ b/Characters/Player.cs @@ -26,7 +26,7 @@ namespace SupaLidlGame.Characters return; } - _sprite.Animation = value; + _sprite.Play(value); } } diff --git a/Characters/Player.tscn b/Characters/Player.tscn index 7ccb415..0adcac6 100644 --- a/Characters/Player.tscn +++ b/Characters/Player.tscn @@ -15,7 +15,7 @@ [sub_resource type="ShaderMaterial" id="ShaderMaterial_h78y7"] shader = ExtResource("2_ngsgt") -shader_parameter/color = null +shader_parameter/color = Quaternion(1, 1, 1, 1) shader_parameter/intensity = 0.0 [sub_resource type="AtlasTexture" id="AtlasTexture_us1ce"] @@ -48,12 +48,33 @@ region = Rect2(144, 0, 24, 24) [sub_resource type="SpriteFrames" id="SpriteFrames_2h7cf"] 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, "name": &"idle", "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, "name": &"move", "speed": 12.0 @@ -125,9 +146,8 @@ position_smoothing_speed = 8.0 [node name="Sprite" type="AnimatedSprite2D" parent="."] use_parent_material = true -frames = SubResource("SpriteFrames_2h7cf") -animation = &"move" -playing = true +sprite_frames = SubResource("SpriteFrames_2h7cf") +animation = &"idle" [node name="CollisionShape2D" type="CollisionShape2D" parent="."] position = Vector2(0, 8) @@ -158,6 +178,7 @@ layout_mode = 3 anchors_preset = 0 [node name="State" type="Label" parent="Debug"] +layout_mode = 0 offset_left = -20.0 offset_top = -60.0 offset_right = 20.0 diff --git a/Extensions/AudioStreamPlayer2D.cs b/Extensions/AudioStreamPlayer2D.cs new file mode 100644 index 0000000..a8b4e02 --- /dev/null +++ b/Extensions/AudioStreamPlayer2D.cs @@ -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); + } + } +} diff --git a/Items/Item.cs b/Items/Item.cs index c1813b5..63cc101 100644 --- a/Items/Item.cs +++ b/Items/Item.cs @@ -5,11 +5,39 @@ namespace SupaLidlGame.Items { public abstract partial class Item : Node2D { + [Export] + public string ItemName { get; set; } + [Export] public string Description { get; set; } + [Export] + public int StackSize { get; set; } + + public int Count { get; set; } = 1; + public Character CharacterOwner { get; set; } + /// + /// Determines if this item can stack with other items + /// + 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 Unequip(Character character); diff --git a/Items/Weapon.cs b/Items/Weapon.cs index bdac648..4db25d1 100644 --- a/Items/Weapon.cs +++ b/Items/Weapon.cs @@ -47,6 +47,8 @@ namespace SupaLidlGame.Items public Character Character { get; set; } + public override bool StacksWith(Item item) => false; + public override void Equip(Character character) { Character = character; diff --git a/Items/Weapons/Sword.cs b/Items/Weapons/Sword.cs index 0db61c9..6d14fa1 100644 --- a/Items/Weapons/Sword.cs +++ b/Items/Weapons/Sword.cs @@ -108,15 +108,6 @@ namespace SupaLidlGame.Items.Weapons public override void _Process(double delta) { - /* - if (RemainingAttackTime > 0) - { - if ((RemainingAttackTime -= delta) <= 0) - { - Deattack(); - } - } - */ base._Process(delta); } @@ -148,7 +139,7 @@ namespace SupaLidlGame.Items.Weapons IsParried = true; AnimationPlayer.SpeedScale = 0.25f; Character.Stun(1.5f); - GetNode("ParrySound").Play(); + GetNode("ParrySound").PlayOnRoot(); } } //this.GetAncestor().AddChild(instance); @@ -166,7 +157,6 @@ namespace SupaLidlGame.Items.Weapons Weapon w = hb.GetAncestor(); if (w is not null) { - //Vector2 a = new Vector2(2, 2) * new Vector2(5, 2); AttemptParry(w); } } diff --git a/Items/Weapons/Sword.tscn b/Items/Weapons/Sword.tscn index 8b0c1d1..b911951 100644 --- a/Items/Weapons/Sword.tscn +++ b/Items/Weapons/Sword.tscn @@ -307,6 +307,7 @@ ParryParticles = NodePath("Anchor/Sprite2D/ParryParticles") Damage = 20.0 UseTime = 0.8 Knockback = 80.0 +ItemName = "Sword" Description = "A basic sword." [node name="Anchor" type="Node2D" parent="."]