about to sleep

item-info
John Montagu, the 4th Earl of Sandvich 2023-03-19 23:36:36 -07:00
parent 2c73590018
commit ac14ed0aee
Signed by: sandvich
GPG Key ID: 9A39BE37E602B22D
13 changed files with 215 additions and 79 deletions

View File

@ -212,7 +212,8 @@ namespace SupaLidlGame.Characters
if (this.GetNode("HurtSound") is AudioStreamPlayer2D sound) if (this.GetNode("HurtSound") is AudioStreamPlayer2D sound)
{ {
sound.PlayOnRoot(); // very small pitch deviation
sound.At(GlobalPosition).WithPitchDeviation(0.125f).Play();
} }
} }
} }

View File

@ -13,7 +13,7 @@
[sub_resource type="ShaderMaterial" id="ShaderMaterial_ms3xg"] [sub_resource type="ShaderMaterial" id="ShaderMaterial_ms3xg"]
shader = ExtResource("1_fx1w5") shader = ExtResource("1_fx1w5")
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_6d2tf"] [sub_resource type="AtlasTexture" id="AtlasTexture_6d2tf"]
@ -46,12 +46,33 @@ region = Rect2(144, 0, 24, 24)
[sub_resource type="SpriteFrames" id="SpriteFrames_4tm2b"] [sub_resource type="SpriteFrames" id="SpriteFrames_4tm2b"]
animations = [{ animations = [{
"frames": [SubResource("AtlasTexture_6d2tf"), SubResource("AtlasTexture_bdyma")], "frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_6d2tf")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_bdyma")
}],
"loop": true, "loop": true,
"name": &"idle", "name": &"idle",
"speed": 5.0 "speed": 5.0
}, { }, {
"frames": [SubResource("AtlasTexture_0dwbr"), SubResource("AtlasTexture_r7fn6"), SubResource("AtlasTexture_py8k0"), SubResource("AtlasTexture_g3nb2"), SubResource("AtlasTexture_jauql")], "frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_0dwbr")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_r7fn6")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_py8k0")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_g3nb2")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_jauql")
}],
"loop": true, "loop": true,
"name": &"move", "name": &"move",
"speed": 12.0 "speed": 12.0
@ -113,9 +134,8 @@ StateMachine = NodePath("StateMachine")
Faction = 2 Faction = 2
[node name="Sprite" type="AnimatedSprite2D" parent="."] [node name="Sprite" type="AnimatedSprite2D" parent="."]
frames = SubResource("SpriteFrames_4tm2b") sprite_frames = SubResource("SpriteFrames_4tm2b")
animation = &"move" animation = &"move"
playing = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="."] [node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2(0, 8) position = Vector2(0, 8)

View File

@ -277,6 +277,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 // TODO: the entity should wander if it doesn't find a best target
Character bestTarget = FindBestTarget();
if (bestTarget is not null)
{
Vector2 pos = FindBestTarget().GlobalPosition; Vector2 pos = FindBestTarget().GlobalPosition;
Target = pos - GlobalPosition; Target = pos - GlobalPosition;
Vector2 dir = Target; Vector2 dir = Target;
@ -292,4 +295,5 @@ namespace SupaLidlGame.Characters
} }
} }
} }
}
} }

View File

@ -52,6 +52,7 @@ namespace SupaLidlGame.Characters
public override void Stun(float time) public override void Stun(float time)
{ {
base.Stun(time); base.Stun(time);
Camera.Shake(2, 0.8f);
// TODO: implement visual effects for stun // TODO: implement visual effects for stun
} }

View File

@ -209,6 +209,7 @@ libraries = {
[node name="HurtSound" type="AudioStreamPlayer2D" parent="."] [node name="HurtSound" type="AudioStreamPlayer2D" parent="."]
stream = ExtResource("12_h0x0g") stream = ExtResource("12_h0x0g")
max_distance = 64.0
[node name="AudioListener2D" type="AudioListener2D" parent="."] [node name="AudioListener2D" type="AudioListener2D" parent="."]
current = true current = true

View File

@ -26,12 +26,27 @@ region = Rect2(64, 0, 16, 16)
[sub_resource type="SpriteFrames" id="SpriteFrames_o6lfi"] [sub_resource type="SpriteFrames" id="SpriteFrames_o6lfi"]
animations = [{ animations = [{
"frames": [SubResource("AtlasTexture_68qj1"), SubResource("AtlasTexture_rt0be"), SubResource("AtlasTexture_0embb"), SubResource("AtlasTexture_victi")], "frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_68qj1")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_rt0be")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_0embb")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_victi")
}],
"loop": true, "loop": true,
"name": &"active", "name": &"active",
"speed": 5.0 "speed": 5.0
}, { }, {
"frames": [SubResource("AtlasTexture_jg745")], "frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_jg745")
}],
"loop": true, "loop": true,
"name": &"default", "name": &"default",
"speed": 8.0 "speed": 8.0
@ -46,9 +61,8 @@ position = Vector2(0, -8)
script = ExtResource("1_w4gfp") script = ExtResource("1_w4gfp")
[node name="Sprite2D" type="AnimatedSprite2D" parent="."] [node name="Sprite2D" type="AnimatedSprite2D" parent="."]
frames = SubResource("SpriteFrames_o6lfi") sprite_frames = SubResource("SpriteFrames_o6lfi")
animation = &"active" animation = &"active"
playing = true
[node name="PointLight2D" type="PointLight2D" parent="."] [node name="PointLight2D" type="PointLight2D" parent="."]
color = Color(0.976471, 0.564706, 0.168627, 1) color = Color(0.976471, 0.564706, 0.168627, 1)

View File

@ -1,24 +1,83 @@
using Godot; using Godot;
using System;
using SupaLidlGame.Utils;
namespace SupaLidlGame namespace SupaLidlGame.Extensions
{ {
public static class AudioStreamPlayer2DExtensions public static class AudioStreamPlayer2DExtensions
{ {
public static void PlayOn(this AudioStreamPlayer2D audio, Node parent) public static AudioBuilder Derive(this AudioStreamPlayer2D audio)
{ {
var clone = audio.Duplicate() as AudioStreamPlayer2D; var clone = audio.Duplicate() as AudioStreamPlayer2D;
parent.AddChild(clone);
clone.Play();
clone.Finished += () => clone.Finished += () =>
{ {
clone.QueueFree(); clone.QueueFree();
}; };
return new AudioBuilder(clone);
} }
public static void PlayOnRoot(this AudioStreamPlayer2D audio) public static AudioStreamPlayer2D Clone(
this AudioStreamPlayer2D audio)
{ {
var root = audio.GetTree().Root.GetChild(0); var clone = audio.Duplicate() as AudioStreamPlayer2D;
audio.PlayOn(root); clone.Finished += () =>
{
clone.QueueFree();
};
return clone;
}
public static AudioStreamPlayer2D On(
this AudioStreamPlayer2D audio,
Node parent)
{
var clone = audio.Clone();
parent.AddChild(clone);
clone.GlobalPosition = audio.GlobalPosition;
return clone;
}
public static AudioStreamPlayer2D OnWorld(
this AudioStreamPlayer2D audio)
{
var world = audio.GetTree().Root.GetNode("World/TileMap");
if (world is null)
{
throw new NullReferenceException("World does not exist");
}
var clone = audio.On(world);
clone.GlobalPosition = audio.GlobalPosition;
return clone;
}
public static AudioStreamPlayer2D At(
this AudioStreamPlayer2D audio,
Vector2 globalPosition)
{
var world = audio.GetTree().Root.GetNode("World/TileMap");
if (world is null)
{
throw new NullReferenceException("World does not exist");
}
var parent = new Node2D();
world.AddChild(parent);
parent.GlobalPosition = globalPosition;
var clone = audio.On(world);
clone.Finished += () =>
{
parent.QueueFree();
};
return clone;
}
public static AudioStreamPlayer2D WithPitchDeviation(
this AudioStreamPlayer2D audio,
float deviation)
{
audio.PitchScale = (float)GD.Randfn(audio.PitchScale, deviation);
return audio;
} }
} }
} }

View File

@ -25,6 +25,9 @@ namespace SupaLidlGame.Extensions
return new Vector2(x / length, y / length); return new Vector2(x / length, y / length);
} }
/// <summary>
/// Returns this vector 90 degrees counter clockwise (x, y) -> (-y, x)
/// </summary>
public static Vector2 Counterclockwise90(this Vector2 vector) public static Vector2 Counterclockwise90(this Vector2 vector)
{ {
return new Vector2(-vector.Y, vector.X); return new Vector2(-vector.Y, vector.X);

View File

@ -14,30 +14,57 @@ namespace SupaLidlGame.Items
private Item _selectedItem; private Item _selectedItem;
private Item _offhandItem;
public Item SelectedItem public Item SelectedItem
{ {
get => _selectedItem; get => _selectedItem;
set set => EquipItem(value, ref _selectedItem);
}
public Item OffhandItem
{ {
if (!Items.Contains(value)) get => _selectedItem;
set => EquipItem(value, ref _offhandItem);
}
private bool EquipItem(Item item, ref Item slot)
{
if (item is not null && item.IsOneHanded)
{
// we can not equip this if either hand is occupied by
// two-handed item
if (_selectedItem is not null && !_selectedItem.IsOneHanded)
{
return false;
}
if (_offhandItem is not null && !_offhandItem.IsOneHanded)
{
return false;
}
}
if (!Items.Contains(item))
{ {
GD.PrintErr("Tried to equip an item not in the inventory."); GD.PrintErr("Tried to equip an item not in the inventory.");
return; return false;
} }
if (_selectedItem is not null) if (slot is not null)
{ {
_selectedItem.Unequip(Character); slot.Unequip(Character);
} }
_selectedItem = value; slot = item;
// this is to handle if item was manually unequipped if (item is not null)
if (_selectedItem is not null)
{ {
_selectedItem.Equip(Character); item.Equip(Character);
}
} }
return true;
} }
public Item AddItem(Item item) public Item AddItem(Item item)
@ -57,6 +84,7 @@ namespace SupaLidlGame.Items
{ {
item.CharacterOwner = null; item.CharacterOwner = null;
item.Visible = true; item.Visible = true;
var e = SelectedItem = item;
throw new System.NotImplementedException(); throw new System.NotImplementedException();
} }

View File

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

View File

@ -139,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").PlayOnRoot(); GetNode<AudioStreamPlayer2D>("ParrySound").OnWorld().Play();
} }
} }
//this.GetAncestor<TileMap>().AddChild(instance); //this.GetAncestor<TileMap>().AddChild(instance);

View File

@ -323,7 +323,7 @@ texture = ExtResource("2_rnfo4")
position = Vector2(-0.221825, -3.12132) position = Vector2(-0.221825, -3.12132)
rotation = 0.785398 rotation = 0.785398
emitting = false emitting = false
amount = 12 amount = 24
lifetime = 0.4 lifetime = 0.4
one_shot = true one_shot = true
explosiveness = 1.0 explosiveness = 1.0
@ -365,9 +365,11 @@ texture = ExtResource("5_pywek")
hframes = 4 hframes = 4
[node name="SwingSound" type="AudioStreamPlayer2D" parent="."] [node name="SwingSound" type="AudioStreamPlayer2D" parent="."]
max_distance = 256.0
[node name="ParrySound" type="AudioStreamPlayer2D" parent="."] [node name="ParrySound" type="AudioStreamPlayer2D" parent="."]
stream = ExtResource("6_8nxjm") stream = ExtResource("6_8nxjm")
max_distance = 256.0
[connection signal="Hit" from="Hitbox" to="." method="_on_hitbox_hit"] [connection signal="Hit" from="Hitbox" to="." method="_on_hitbox_hit"]

File diff suppressed because one or more lines are too long