about to sleep
							parent
							
								
									2c73590018
								
							
						
					
					
						commit
						ac14ed0aee
					
				|  | @ -212,7 +212,8 @@ namespace SupaLidlGame.Characters | |||
| 
 | ||||
|             if (this.GetNode("HurtSound") is AudioStreamPlayer2D sound) | ||||
|             { | ||||
|                 sound.PlayOnRoot(); | ||||
|                 // very small pitch deviation | ||||
|                 sound.At(GlobalPosition).WithPitchDeviation(0.125f).Play(); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  |  | |||
|  | @ -13,7 +13,7 @@ | |||
| 
 | ||||
| [sub_resource type="ShaderMaterial" id="ShaderMaterial_ms3xg"] | ||||
| shader = ExtResource("1_fx1w5") | ||||
| shader_parameter/color = null | ||||
| shader_parameter/color = Quaternion(1, 1, 1, 1) | ||||
| shader_parameter/intensity = 0.0 | ||||
| 
 | ||||
| [sub_resource type="AtlasTexture" id="AtlasTexture_6d2tf"] | ||||
|  | @ -46,12 +46,33 @@ region = Rect2(144, 0, 24, 24) | |||
| 
 | ||||
| [sub_resource type="SpriteFrames" id="SpriteFrames_4tm2b"] | ||||
| 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, | ||||
| "name": &"idle", | ||||
| "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, | ||||
| "name": &"move", | ||||
| "speed": 12.0 | ||||
|  | @ -113,9 +134,8 @@ StateMachine = NodePath("StateMachine") | |||
| Faction = 2 | ||||
| 
 | ||||
| [node name="Sprite" type="AnimatedSprite2D" parent="."] | ||||
| frames = SubResource("SpriteFrames_4tm2b") | ||||
| sprite_frames = SubResource("SpriteFrames_4tm2b") | ||||
| animation = &"move" | ||||
| playing = true | ||||
| 
 | ||||
| [node name="CollisionShape2D" type="CollisionShape2D" parent="."] | ||||
| position = Vector2(0, 8) | ||||
|  |  | |||
|  | @ -277,17 +277,21 @@ 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; | ||||
|             Vector2 dir = Target; | ||||
|             float dist = GlobalPosition.DistanceSquaredTo(pos); | ||||
|             UpdateWeights(pos); | ||||
| 
 | ||||
|             if (Target.LengthSquared() < 1024) | ||||
|             Character bestTarget = FindBestTarget(); | ||||
|             if (bestTarget is not null) | ||||
|             { | ||||
|                 if (Inventory.SelectedItem is Weapon weapon) | ||||
|                 Vector2 pos = FindBestTarget().GlobalPosition; | ||||
|                 Target = pos - GlobalPosition; | ||||
|                 Vector2 dir = Target; | ||||
|                 float dist = GlobalPosition.DistanceSquaredTo(pos); | ||||
|                 UpdateWeights(pos); | ||||
| 
 | ||||
|                 if (Target.LengthSquared() < 1024) | ||||
|                 { | ||||
|                     UseCurrentItem(); | ||||
|                     if (Inventory.SelectedItem is Weapon weapon) | ||||
|                     { | ||||
|                         UseCurrentItem(); | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|  |  | |||
|  | @ -52,6 +52,7 @@ namespace SupaLidlGame.Characters | |||
|         public override void Stun(float time) | ||||
|         { | ||||
|             base.Stun(time); | ||||
|             Camera.Shake(2, 0.8f); | ||||
|             // TODO: implement visual effects for stun | ||||
|         } | ||||
| 
 | ||||
|  |  | |||
|  | @ -209,6 +209,7 @@ libraries = { | |||
| 
 | ||||
| [node name="HurtSound" type="AudioStreamPlayer2D" parent="."] | ||||
| stream = ExtResource("12_h0x0g") | ||||
| max_distance = 64.0 | ||||
| 
 | ||||
| [node name="AudioListener2D" type="AudioListener2D" parent="."] | ||||
| current = true | ||||
|  |  | |||
|  | @ -26,12 +26,27 @@ region = Rect2(64, 0, 16, 16) | |||
| 
 | ||||
| [sub_resource type="SpriteFrames" id="SpriteFrames_o6lfi"] | ||||
| 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, | ||||
| "name": &"active", | ||||
| "speed": 5.0 | ||||
| }, { | ||||
| "frames": [SubResource("AtlasTexture_jg745")], | ||||
| "frames": [{ | ||||
| "duration": 1.0, | ||||
| "texture": SubResource("AtlasTexture_jg745") | ||||
| }], | ||||
| "loop": true, | ||||
| "name": &"default", | ||||
| "speed": 8.0 | ||||
|  | @ -46,9 +61,8 @@ position = Vector2(0, -8) | |||
| script = ExtResource("1_w4gfp") | ||||
| 
 | ||||
| [node name="Sprite2D" type="AnimatedSprite2D" parent="."] | ||||
| frames = SubResource("SpriteFrames_o6lfi") | ||||
| sprite_frames = SubResource("SpriteFrames_o6lfi") | ||||
| animation = &"active" | ||||
| playing = true | ||||
| 
 | ||||
| [node name="PointLight2D" type="PointLight2D" parent="."] | ||||
| color = Color(0.976471, 0.564706, 0.168627, 1) | ||||
|  |  | |||
|  | @ -1,24 +1,83 @@ | |||
| using Godot; | ||||
| using System; | ||||
| using SupaLidlGame.Utils; | ||||
| 
 | ||||
| namespace SupaLidlGame | ||||
| namespace SupaLidlGame.Extensions | ||||
| { | ||||
|     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; | ||||
|             parent.AddChild(clone); | ||||
|             clone.Play(); | ||||
|             clone.Finished += () => | ||||
|             { | ||||
|                 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); | ||||
|             audio.PlayOn(root); | ||||
|             var clone = audio.Duplicate() as AudioStreamPlayer2D; | ||||
|             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; | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -25,6 +25,9 @@ namespace SupaLidlGame.Extensions | |||
|             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) | ||||
|         { | ||||
|             return new Vector2(-vector.Y, vector.X); | ||||
|  |  | |||
|  | @ -14,30 +14,57 @@ namespace SupaLidlGame.Items | |||
| 
 | ||||
|         private Item _selectedItem; | ||||
| 
 | ||||
|         private Item _offhandItem; | ||||
| 
 | ||||
|         public Item SelectedItem | ||||
|         { | ||||
|             get => _selectedItem; | ||||
|             set | ||||
|             set => EquipItem(value, ref _selectedItem); | ||||
|         } | ||||
| 
 | ||||
|         public Item OffhandItem | ||||
|         { | ||||
|             get => _selectedItem; | ||||
|             set => EquipItem(value, ref _offhandItem); | ||||
|         } | ||||
| 
 | ||||
|         private bool EquipItem(Item item, ref Item slot) | ||||
|         { | ||||
|             if (item is not null && item.IsOneHanded) | ||||
|             { | ||||
|                 if (!Items.Contains(value)) | ||||
|                 // we can not equip this if either hand is occupied by | ||||
|                 // two-handed item | ||||
| 
 | ||||
|                 if (_selectedItem is not null && !_selectedItem.IsOneHanded) | ||||
|                 { | ||||
|                     GD.PrintErr("Tried to equip an item not in the inventory."); | ||||
|                     return; | ||||
|                     return false; | ||||
|                 } | ||||
| 
 | ||||
|                 if (_selectedItem is not null) | ||||
|                 if (_offhandItem is not null && !_offhandItem.IsOneHanded) | ||||
|                 { | ||||
|                     _selectedItem.Unequip(Character); | ||||
|                 } | ||||
| 
 | ||||
|                 _selectedItem = value; | ||||
| 
 | ||||
|                 // this is to handle if item was manually unequipped | ||||
|                 if (_selectedItem is not null) | ||||
|                 { | ||||
|                     _selectedItem.Equip(Character); | ||||
|                     return false; | ||||
|                 } | ||||
|             } | ||||
| 
 | ||||
|             if (!Items.Contains(item)) | ||||
|             { | ||||
|                 GD.PrintErr("Tried to equip an item not in the inventory."); | ||||
|                 return false; | ||||
|             } | ||||
| 
 | ||||
|             if (slot is not null) | ||||
|             { | ||||
|                 slot.Unequip(Character); | ||||
|             } | ||||
| 
 | ||||
|             slot = item; | ||||
| 
 | ||||
|             if (item is not null) | ||||
|             { | ||||
|                 item.Equip(Character); | ||||
|             } | ||||
| 
 | ||||
|             return true; | ||||
|         } | ||||
| 
 | ||||
|         public Item AddItem(Item item) | ||||
|  | @ -57,6 +84,7 @@ namespace SupaLidlGame.Items | |||
|         { | ||||
|             item.CharacterOwner = null; | ||||
|             item.Visible = true; | ||||
|             var e = SelectedItem = item; | ||||
|             throw new System.NotImplementedException(); | ||||
|         } | ||||
| 
 | ||||
|  |  | |||
|  | @ -12,30 +12,32 @@ namespace SupaLidlGame.Items | |||
|         public string Description { get; set; } | ||||
| 
 | ||||
|         [Export] | ||||
|         public int StackSize { get; set; } | ||||
|         public bool CanStack { get; set; } = false; | ||||
| 
 | ||||
|         public int Count { get; set; } = 1; | ||||
| 
 | ||||
|         public Character CharacterOwner { get; set; } | ||||
| 
 | ||||
|         public bool IsOneHanded { get; set; } = false; | ||||
| 
 | ||||
|         /// <summary> | ||||
|         /// Determines if this item can stack with other items | ||||
|         /// Determines if this item can directly stack with other items | ||||
|         /// </summary> | ||||
|         public virtual bool StacksWith(Item item) | ||||
|         { | ||||
|             if (!CanStack) | ||||
|             { | ||||
|                 return false; | ||||
|             } | ||||
| 
 | ||||
|             if (ItemName != item.ItemName) | ||||
|             { | ||||
|                 return false; | ||||
|             } | ||||
| 
 | ||||
|             if (Count + item.Count <= StackSize) | ||||
|             { | ||||
|                 return true; | ||||
|             } | ||||
| 
 | ||||
|             // several more conditions may be added soon | ||||
| 
 | ||||
|             return false; | ||||
|             return true; | ||||
|         } | ||||
| 
 | ||||
|         public abstract void Equip(Character character); | ||||
|  |  | |||
|  | @ -139,7 +139,7 @@ namespace SupaLidlGame.Items.Weapons | |||
|                     IsParried = true; | ||||
|                     AnimationPlayer.SpeedScale = 0.25f; | ||||
|                     Character.Stun(1.5f); | ||||
|                     GetNode<AudioStreamPlayer2D>("ParrySound").PlayOnRoot(); | ||||
|                     GetNode<AudioStreamPlayer2D>("ParrySound").OnWorld().Play(); | ||||
|                 } | ||||
|             } | ||||
|             //this.GetAncestor<TileMap>().AddChild(instance); | ||||
|  |  | |||
|  | @ -323,7 +323,7 @@ texture = ExtResource("2_rnfo4") | |||
| position = Vector2(-0.221825, -3.12132) | ||||
| rotation = 0.785398 | ||||
| emitting = false | ||||
| amount = 12 | ||||
| amount = 24 | ||||
| lifetime = 0.4 | ||||
| one_shot = true | ||||
| explosiveness = 1.0 | ||||
|  | @ -365,9 +365,11 @@ texture = ExtResource("5_pywek") | |||
| hframes = 4 | ||||
| 
 | ||||
| [node name="SwingSound" type="AudioStreamPlayer2D" parent="."] | ||||
| max_distance = 256.0 | ||||
| 
 | ||||
| [node name="ParrySound" type="AudioStreamPlayer2D" parent="."] | ||||
| stream = ExtResource("6_8nxjm") | ||||
| max_distance = 256.0 | ||||
| 
 | ||||
| [connection signal="Hit" from="Hitbox" to="." method="_on_hitbox_hit"] | ||||
| 
 | ||||
|  |  | |||
											
												
													File diff suppressed because one or more lines are too long
												
											
										
									
								
		Loading…
	
		Reference in New Issue