diff --git a/Characters/Character.cs b/Characters/Character.cs index 8cf725b..97d7b0a 100644 --- a/Characters/Character.cs +++ b/Characters/Character.cs @@ -5,7 +5,7 @@ namespace SupaLidlGame.Characters public partial class Character : CharacterBody2D { [Export] - public float Speed { get; protected set; } = 128.0f; + public float Speed { get; protected set; } = 32.0f; [Export] public float Mass diff --git a/Characters/ExampleEnemy.tscn b/Characters/ExampleEnemy.tscn index 31c160b..6444d31 100644 --- a/Characters/ExampleEnemy.tscn +++ b/Characters/ExampleEnemy.tscn @@ -15,7 +15,6 @@ size = Vector2(32, 32) [node name="ExampleEnemy" type="CharacterBody2D" node_paths=PackedStringArray("StateMachine")] script = ExtResource("1_4x3dm") -Speed = 32.0 StateMachine = NodePath("StateMachine") [node name="Icon" type="Sprite2D" parent="."] diff --git a/Characters/Player.tscn b/Characters/Player.tscn index 66c9aaa..87373b7 100644 --- a/Characters/Player.tscn +++ b/Characters/Player.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=9 format=3 uid="uid://bncaar8vp3b84"] +[gd_scene load_steps=11 format=3 uid="uid://bncaar8vp3b84"] [ext_resource type="Script" path="res://Characters/Player.cs" id="1_flygr"] [ext_resource type="Texture2D" uid="uid://bw052v8ikfget" path="res://icon.svg" id="2_xmgd1"] @@ -6,6 +6,8 @@ [ext_resource type="Script" path="res://Characters/States/PlayerIdleState.cs" id="4_4k4mb"] [ext_resource type="Script" path="res://Characters/States/PlayerMoveState.cs" id="5_tx5rw"] [ext_resource type="Script" path="res://Characters/States/PlayerRollState.cs" id="6_6bgrj"] +[ext_resource type="PackedScene" uid="uid://cajlwb67xenfy" path="res://Items/Weapons/Sword.tscn" id="7_4rxuv"] +[ext_resource type="Script" path="res://Items/Inventory.cs" id="7_xyenu"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_bfqew"] size = Vector2(32, 16) @@ -15,6 +17,7 @@ font_size = 24 [node name="Player" type="CharacterBody2D" node_paths=PackedStringArray("StateMachine")] script = ExtResource("1_flygr") +Speed = 64.0 StateMachine = NodePath("StateMachine") [node name="Sprite2D" type="Sprite2D" parent="."] @@ -64,3 +67,7 @@ horizontal_alignment = 1 [node name="Node" type="Node" parent="."] [node name="Inventory" type="Node2D" parent="."] +script = ExtResource("7_xyenu") + +[node name="Sword" parent="Inventory" instance=ExtResource("7_4rxuv")] +position = Vector2(21, 0) diff --git a/Characters/States/PlayerMoveState.cs b/Characters/States/PlayerMoveState.cs index 2fad5f9..440824a 100644 --- a/Characters/States/PlayerMoveState.cs +++ b/Characters/States/PlayerMoveState.cs @@ -26,13 +26,12 @@ namespace SupaLidlGame.Characters.State return null; } - public override CharacterState Input(Godot.InputEvent @event) + public override CharacterState Input(InputEvent @event) { if (@event.IsActionPressed("roll")) { return RollState; } - return null; } } diff --git a/Characters/Items/Inventory.cs b/Items/Inventory.cs similarity index 87% rename from Characters/Items/Inventory.cs rename to Items/Inventory.cs index b27ad25..0a1346d 100644 --- a/Characters/Items/Inventory.cs +++ b/Items/Inventory.cs @@ -55,6 +55,13 @@ namespace SupaLidlGame.Items public override void _Ready() { Owner = GetParent(); + foreach (Node child in GetChildren()) + { + if (child is Item item) + { + Items.Add(item); + } + } base._Ready(); } } diff --git a/Characters/Items/Item.cs b/Items/Item.cs similarity index 100% rename from Characters/Items/Item.cs rename to Items/Item.cs diff --git a/Characters/Items/Weapon.cs b/Items/Weapon.cs similarity index 100% rename from Characters/Items/Weapon.cs rename to Items/Weapon.cs diff --git a/Characters/Items/Weapons/Sword.cs b/Items/Weapons/Sword.cs similarity index 54% rename from Characters/Items/Weapons/Sword.cs rename to Items/Weapons/Sword.cs index 1725292..9fe20d3 100644 --- a/Characters/Items/Weapons/Sword.cs +++ b/Items/Weapons/Sword.cs @@ -1,11 +1,13 @@ +using Godot; +using SupaLidlGame.BoundingBoxes; using SupaLidlGame.Characters; namespace SupaLidlGame.Items.Weapons { public partial class Sword : Weapon { - //[Export] - //public Damagebox + [Export] + public Hitbox Hitbox { get; set; } public override void Equip(Character character) { @@ -14,7 +16,12 @@ namespace SupaLidlGame.Items.Weapons public override void Use() { - //base.Use(); + Hitbox.IsEnabled = true; + } + + public override void Deuse() + { + Hitbox.IsEnabled = false; } } } diff --git a/Items/Weapons/Sword.tscn b/Items/Weapons/Sword.tscn new file mode 100644 index 0000000..73e6f9f --- /dev/null +++ b/Items/Weapons/Sword.tscn @@ -0,0 +1,26 @@ +[gd_scene load_steps=5 format=3 uid="uid://cajlwb67xenfy"] + +[ext_resource type="Script" path="res://Items/Weapons/Sword.cs" id="1_mlo73"] +[ext_resource type="Texture2D" uid="uid://dt6u8p4h6g7le" path="res://Sprites/knife.png" id="2_dmsp2"] +[ext_resource type="PackedScene" uid="uid://du5vhccg75nrq" path="res://BoundingBoxes/Hitbox.tscn" id="3_up3ob"] + +[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_yln58"] +radius = 8.0 +height = 24.0 + +[node name="Sword" type="Node2D" node_paths=PackedStringArray("Hitbox")] +texture_filter = 3 +script = ExtResource("1_mlo73") +Hitbox = NodePath("Hitbox") + +[node name="Sprite2D" type="Sprite2D" parent="."] +texture = ExtResource("2_dmsp2") + +[node name="Hitbox" parent="." instance=ExtResource("3_up3ob")] + +[node name="CollisionShape2D" parent="Hitbox" index="0"] +shape = SubResource("CapsuleShape2D_yln58") + +[node name="AnimationPlayer" type="AnimationPlayer" parent="."] + +[editable path="Hitbox"] diff --git a/Scenes/Level.tscn b/Scenes/Level.tscn index 70d9cd0..1ef7d43 100644 --- a/Scenes/Level.tscn +++ b/Scenes/Level.tscn @@ -1136,7 +1136,6 @@ layer_3/tile_data = PackedInt32Array(-458765, 393216, 1, -393229, 327680, 0, -39 position = Vector2(-81, -34) scale = Vector2(0.25, 0.25) motion_mode = 1 -Speed = 64.0 [node name="ExampleEnemy" parent="TileMap" instance=ExtResource("2_uti3y")] position = Vector2(-4, 60) diff --git a/project.godot b/project.godot index 39ac952..c9241d8 100644 --- a/project.godot +++ b/project.godot @@ -48,6 +48,7 @@ ui_down={ roll={ "deadzone": 0.5, "events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":3,"pressed":false,"double_click":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":32,"unicode":0,"echo":false,"script":null) ] }