diff --git a/Scenes/Barrel.cs b/Scenes/Barrel.cs index 160e7aaf..35cfdf55 100644 --- a/Scenes/Barrel.cs +++ b/Scenes/Barrel.cs @@ -1,6 +1,7 @@ using Godot; using System; using System.Diagnostics; +using Cirno.Scripts; public partial class Barrel : Area2D, IDestructible { @@ -11,8 +12,10 @@ public partial class Barrel : Area2D, IDestructible [Export] public float ExplosionDamage = 1; [Export] public PackedScene DebrisScene { get; set; } + + [Export] public PackedScene ExplosionParticles { get; set; } - private float _currentHealth; + private float _currentHealth = 0f; private bool _isDestroyed = false; @@ -30,19 +33,50 @@ public partial class Barrel : Area2D, IDestructible private void Explode() { Debug.WriteLine("Boom"); + CreateParticles(); CreateDebris(); QueueFree(); } private void CreateDebris() { - if (DebrisScene == null) return; - var debris = DebrisScene.Instantiate(); - Owner.AddChild(debris); - debris.Transform = this.GlobalTransform; - debris.Position = this.Position; + this.CreateChild(DebrisScene); + + // if (DebrisScene == null) return; + // var debris = DebrisScene.Instantiate(); + // Owner.CallDeferred("add_child", debris); //.AddChild(debris); + // debris.Transform = this.GlobalTransform; + // debris.Position = this.Position; } + private void CreateParticles() + { + + var particle = this.CreateChild(ExplosionParticles); + if (particle == null) return; + + particle.Emitting = true; + + // if (ExplosionParticles == null) return; + // var emitter = ExplosionParticles.Instantiate(); + // Owner.CallDeferred("add_child", emitter); + // emitter.Transform = this.GlobalTransform; + // emitter.Position = this.Position; + // + // emitter.Emitting = true; + } + + // private T CreateChild(PackedScene prefab) where T : Node2D + // { + // if (prefab == null) return null; + // var newInstance = prefab.Instantiate(); + // Owner.CallDeferred("add_child", newInstance); + // newInstance.Transform = this.GlobalTransform; + // newInstance.Position = this.Position; + // + // return newInstance; + // } + public void Hit(float damage) { if (_isDestroyed) return; diff --git a/Scenes/Barrel.tscn b/Scenes/Barrel.tscn index e3271152..830b8cfb 100644 --- a/Scenes/Barrel.tscn +++ b/Scenes/Barrel.tscn @@ -1,8 +1,9 @@ -[gd_scene load_steps=7 format=3 uid="uid://bj28qiai2x2ar"] +[gd_scene load_steps=8 format=3 uid="uid://bj28qiai2x2ar"] [ext_resource type="Script" path="res://Scenes/Barrel.cs" id="1_avwdx"] [ext_resource type="Texture2D" uid="uid://d2f16ke8c7vwx" path="res://Sprites/Barrel.png" id="1_e66t6"] [ext_resource type="PackedScene" uid="uid://clyyl3jgpfoo7" path="res://Scenes/Broken_Barrel.tscn" id="2_f145b"] +[ext_resource type="PackedScene" uid="uid://jmijre3eaf8m" path="res://Scenes/Explosion.tscn" id="3_sm378"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_2ewfl"] size = Vector2(11, 14) @@ -22,6 +23,7 @@ Health = 2.0 ExplosionRadius = 2.0 ExplosionDamage = 2.0 DebrisScene = ExtResource("2_f145b") +ExplosionParticles = ExtResource("3_sm378") metadata/_edit_group_ = true [node name="CollisionShape2D" type="CollisionShape2D" parent="."] diff --git a/Scenes/Box_Red.tscn b/Scenes/Box_Red.tscn index aa047c52..1f054db3 100644 --- a/Scenes/Box_Red.tscn +++ b/Scenes/Box_Red.tscn @@ -1,8 +1,9 @@ -[gd_scene load_steps=6 format=3 uid="uid://bgk7fgwiis425"] +[gd_scene load_steps=7 format=3 uid="uid://bgk7fgwiis425"] [ext_resource type="Script" path="res://Scenes/Barrel.cs" id="1_flhlf"] [ext_resource type="PackedScene" uid="uid://dpaobtgb3l4ft" path="res://Scenes/Box_Red_Broken.tscn" id="2_baxfl"] [ext_resource type="Texture2D" uid="uid://c1djpk8lbgjfe" path="res://Sprites/Box_Red.png" id="2_g1pum"] +[ext_resource type="PackedScene" uid="uid://jmijre3eaf8m" path="res://Scenes/Explosion.tscn" id="3_mbs7l"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_2ewfl"] size = Vector2(11, 14) @@ -18,6 +19,7 @@ Health = 4.0 ExplosionRadius = 0.0 ExplosionDamage = 0.0 DebrisScene = ExtResource("2_baxfl") +ExplosionParticles = ExtResource("3_mbs7l") metadata/_edit_group_ = true [node name="CollisionShape2D" type="CollisionShape2D" parent="."] diff --git a/Scenes/Control_Pad.tscn b/Scenes/Control_Pad.tscn new file mode 100644 index 00000000..aae07dad --- /dev/null +++ b/Scenes/Control_Pad.tscn @@ -0,0 +1,17 @@ +[gd_scene load_steps=4 format=3 uid="uid://crph24e6e0v0q"] + +[ext_resource type="Texture2D" uid="uid://dwpocd22r4pas" path="res://Sprites/Control_Pad.png" id="1_bgeyn"] +[ext_resource type="Script" path="res://Scenes/Interactable.cs" id="1_g3j01"] + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_x0adl"] + +[node name="ControlPad" type="Area2D" groups=["Interactable"]] +collision_layer = 4 +collision_mask = 2 +script = ExtResource("1_g3j01") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +shape = SubResource("RectangleShape2D_x0adl") + +[node name="Sprite2D" type="Sprite2D" parent="."] +texture = ExtResource("1_bgeyn") diff --git a/Scenes/Explosion.tscn b/Scenes/Explosion.tscn index 59dbdb41..fcf6eb03 100644 --- a/Scenes/Explosion.tscn +++ b/Scenes/Explosion.tscn @@ -25,6 +25,8 @@ scale_curve = SubResource("CurveTexture_y21cl") color_ramp = SubResource("GradientTexture1D_b2evf") [node name="Explosion" type="GPUParticles2D"] +emitting = false amount = 20 process_material = SubResource("ParticleProcessMaterial_4vw6r") +one_shot = true explosiveness = 1.0 diff --git a/Scenes/Interactable.cs b/Scenes/Interactable.cs new file mode 100644 index 00000000..9c6cfd7c --- /dev/null +++ b/Scenes/Interactable.cs @@ -0,0 +1,21 @@ +using Godot; +using System; +using System.Diagnostics; + +public partial class Interactable : Area2D +{ + // Called when the node enters the scene tree for the first time. + public override void _Ready() + { + } + + // Called every frame. 'delta' is the elapsed time since the previous frame. + public override void _Process(double delta) + { + } + + public void Activate() + { + Debug.WriteLine("Activated"); + } +} diff --git a/Scenes/InteractionController.cs b/Scenes/InteractionController.cs new file mode 100644 index 00000000..2173c784 --- /dev/null +++ b/Scenes/InteractionController.cs @@ -0,0 +1,15 @@ +using Godot; +using System; + +public partial class InteractionController : Area2D +{ + // Called when the node enters the scene tree for the first time. + public override void _Ready() + { + } + + // Called every frame. 'delta' is the elapsed time since the previous frame. + public override void _Process(double delta) + { + } +} diff --git a/Scenes/Selector.tscn b/Scenes/Selector.tscn new file mode 100644 index 00000000..41592cfd --- /dev/null +++ b/Scenes/Selector.tscn @@ -0,0 +1,8 @@ +[gd_scene load_steps=2 format=3 uid="uid://chkpk7erlqajg"] + +[ext_resource type="Texture2D" uid="uid://kgs1d0m47u3g" path="res://Sprites/selector.png" id="1_ui0xt"] + +[node name="Selector" type="Node2D"] + +[node name="Sprite2D" type="Sprite2D" parent="."] +texture = ExtResource("1_ui0xt") diff --git a/Scenes/player.tscn b/Scenes/player.tscn index 922a83a0..5ea116f7 100644 --- a/Scenes/player.tscn +++ b/Scenes/player.tscn @@ -1,11 +1,13 @@ -[gd_scene load_steps=23 format=3 uid="uid://bghghp5ep4w2j"] +[gd_scene load_steps=26 format=3 uid="uid://bghghp5ep4w2j"] [ext_resource type="Script" path="res://Scripts/PlayerMovement.cs" id="1_m27vu"] [ext_resource type="Texture2D" uid="uid://la06powu57hu" path="res://Sprites/Cirno_Big.png" id="2_bwf6x"] [ext_resource type="PackedScene" uid="uid://b1qnfiuokpvsr" path="res://Scenes/bullet.tscn" id="2_ov36d"] +[ext_resource type="PackedScene" uid="uid://chkpk7erlqajg" path="res://Scenes/Selector.tscn" id="3_8wt6s"] [ext_resource type="Script" path="res://addons/smoothing/smoothing_2d.gd" id="4_j4xhu"] [ext_resource type="Script" path="res://Scenes/CameraTarget.gd" id="5_cxvyt"] [ext_resource type="PackedScene" uid="uid://cfb3nsay84xdb" path="res://Scenes/crosshair.tscn" id="6_l43rf"] +[ext_resource type="Script" path="res://Scenes/InteractionController.cs" id="7_uvgjg"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_ai4rh"] size = Vector2(6, 6) @@ -133,6 +135,9 @@ animations = [{ "speed": 5.0 }] +[sub_resource type="CircleShape2D" id="CircleShape2D_oevaq"] +radius = 17.2627 + [node name="Player" type="CharacterBody2D" node_paths=PackedStringArray("Muzzle") groups=["player"]] collision_layer = 2 collision_mask = 99 @@ -140,6 +145,7 @@ script = ExtResource("1_m27vu") Speed = 2500 CrosshairDistance = 20.0 BulletScene = ExtResource("2_ov36d") +SelectorScene = ExtResource("3_8wt6s") Muzzle = NodePath("Muzzle") metadata/_edit_group_ = true @@ -173,3 +179,13 @@ sprite_frames = SubResource("SpriteFrames_q0rt3") animation = &"walk_left" [node name="Crosshair" parent="Smoothing2D" instance=ExtResource("6_l43rf")] + +[node name="InteractionController" type="Area2D" parent="."] +collision_layer = 2 +collision_mask = 4 +script = ExtResource("7_uvgjg") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="InteractionController"] +shape = SubResource("CircleShape2D_oevaq") + +[connection signal="area_entered" from="InteractionController" to="." method="_on_interaction_controller_area_entered"] diff --git a/Scenes/test.tscn b/Scenes/test.tscn index 484c6ccb..2fe31d30 100644 --- a/Scenes/test.tscn +++ b/Scenes/test.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=22 format=3 uid="uid://bv451a8wgty4u"] +[gd_scene load_steps=23 format=3 uid="uid://bv451a8wgty4u"] [ext_resource type="Texture2D" uid="uid://bxclo2fg3ulur" path="res://Sprites/tinyBlocks_NOiL_1.1update.png" id="1_43rfa"] [ext_resource type="TileSet" uid="uid://c26fvvju514rc" path="res://Tilesets/test_tileset.tres" id="1_k3ie3"] @@ -13,6 +13,7 @@ [ext_resource type="Texture2D" uid="uid://tphqodqyere1" path="res://Tilesets/factory.png" id="8_0km4o"] [ext_resource type="PackedScene" uid="uid://7cpk3c3d8cl7" path="res://Scenes/Furniture/MediumLiquidTank.tscn" id="8_2wpw7"] [ext_resource type="PackedScene" uid="uid://byms2dhliyux0" path="res://Scenes/teleporter.tscn" id="10_mc6y5"] +[ext_resource type="PackedScene" uid="uid://crph24e6e0v0q" path="res://Scenes/Control_Pad.tscn" id="12_hfkf1"] [ext_resource type="PackedScene" uid="uid://bnhck5eh0tqxf" path="res://Scenes/Furniture/MediumTerminal.tscn" id="13_acrmt"] [ext_resource type="PackedScene" uid="uid://bgk7fgwiis425" path="res://Scenes/Box_Red.tscn" id="15_m0y0j"] @@ -6989,6 +6990,12 @@ position = Vector2(-744, 152) [node name="Red Box4" parent="Factory Tilemaps/Solid" instance=ExtResource("15_m0y0j")] position = Vector2(-728, 152) +[node name="ControlPad" parent="Factory Tilemaps/Solid" instance=ExtResource("12_hfkf1")] +position = Vector2(-713, -153) + +[node name="ControlPad2" parent="Factory Tilemaps/Solid" instance=ExtResource("12_hfkf1")] +position = Vector2(-616, -154) + [node name="CameraController" type="Camera2D" parent="."] script = ExtResource("6_t8ide") diff --git a/Scripts/PlayerMovement.cs b/Scripts/PlayerMovement.cs index 814be691..cdc8f0d7 100644 --- a/Scripts/PlayerMovement.cs +++ b/Scripts/PlayerMovement.cs @@ -1,6 +1,7 @@ using Godot; using System; using System.Diagnostics; +using Cirno.Scripts; public partial class PlayerMovement : CharacterBody2D { @@ -12,6 +13,13 @@ public partial class PlayerMovement : CharacterBody2D [Export] public PackedScene BulletScene { get; set; } + + [Export] + public PackedScene SelectorScene { get; set; } + + private Node2D _selector; + + private Interactable _lastInteractable; [Export] public Marker2D Muzzle { get; set; } @@ -31,6 +39,12 @@ public partial class PlayerMovement : CharacterBody2D _movementDirection = Vector2.Zero; _facingDirection = Vector2.Zero; + + if (SelectorScene != null) + { + _selector = this.CreateChild(SelectorScene); + _selector.Visible = false; + } } /*public override _Process(float _delta) @@ -49,6 +63,20 @@ public partial class PlayerMovement : CharacterBody2D { HandleShoot(); SetAnimation(); + + FindInteractable(); + } + + private void FindInteractable() + { + if (Input.IsActionJustPressed("Use") && _lastInteractable != null) + { + _lastInteractable.Activate(); + } + + //var spaceState = GetWorld2D().DirectSpaceState; + + //var query = PhysicsRayQueryParameters2D.Create(Vector2.Zero, ) } private void HandleShoot() @@ -124,5 +152,23 @@ public partial class PlayerMovement : CharacterBody2D _crosshair.Position = CalculateCrosshairPosition(); + //FindInteractable(); + + } + + private void _on_interaction_controller_area_entered(Area2D area) + { + // Replace with function body. + if (area.IsInGroup("Interactable") && area is Interactable interactable) + { + Debug.WriteLine("Interactable Entered"); + + if (_selector != null) + { + _selector.Position = interactable.Position; + _selector.Visible = true; + _lastInteractable = interactable; + } + } } } diff --git a/Scripts/Tools.cs b/Scripts/Tools.cs new file mode 100644 index 00000000..caef746c --- /dev/null +++ b/Scripts/Tools.cs @@ -0,0 +1,17 @@ +using Godot; + +namespace Cirno.Scripts; + +public static class Tools +{ + public static T CreateChild(this Node2D node, PackedScene prefab) where T : Node2D + { + if (prefab == null) return null; + var newInstance = prefab.Instantiate(); + node.Owner.CallDeferred("add_child", newInstance); + newInstance.Transform = node.GlobalTransform; + newInstance.Position = node.Position; + + return newInstance; + } +} \ No newline at end of file diff --git a/Sprites/Control_Pad.aseprite b/Sprites/Control_Pad.aseprite new file mode 100644 index 00000000..ac83fa03 --- /dev/null +++ b/Sprites/Control_Pad.aseprite @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e81cc981774a92ddcf3ac344434ee37a79d1b14bfcf63a9a0340133154e7c33c +size 373 diff --git a/Sprites/Control_Pad.png b/Sprites/Control_Pad.png new file mode 100644 index 00000000..4e29f3be --- /dev/null +++ b/Sprites/Control_Pad.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:02c4a52a198885b6933f1b870179d64cd603cc1595ffbbd67d91f5b6b55a1d94 +size 183 diff --git a/Sprites/Control_Pad.png.import b/Sprites/Control_Pad.png.import new file mode 100644 index 00000000..8a2599e4 --- /dev/null +++ b/Sprites/Control_Pad.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://dwpocd22r4pas" +path="res://.godot/imported/Control_Pad.png-a552e114c58627e0729538ead1fb0452.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Sprites/Control_Pad.png" +dest_files=["res://.godot/imported/Control_Pad.png-a552e114c58627e0729538ead1fb0452.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/Sprites/selector.aseprite b/Sprites/selector.aseprite new file mode 100644 index 00000000..54e572c0 --- /dev/null +++ b/Sprites/selector.aseprite @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:67d7edcf94619cbf5d2b4bad8f3a18f5ae515ccdb5dcf9abf1c28661828ace37 +size 367 diff --git a/Sprites/selector.png b/Sprites/selector.png new file mode 100644 index 00000000..5bb875d6 --- /dev/null +++ b/Sprites/selector.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e626770a15d4176e44d20787c719a9adc39763aa4b18d54c468ba8a8459eb42b +size 124 diff --git a/Sprites/selector.png.import b/Sprites/selector.png.import new file mode 100644 index 00000000..6703b09b --- /dev/null +++ b/Sprites/selector.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://kgs1d0m47u3g" +path="res://.godot/imported/selector.png-9fdedc73cd7bc02709aff9b59551be4e.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Sprites/selector.png" +dest_files=["res://.godot/imported/selector.png-9fdedc73cd7bc02709aff9b59551be4e.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/project.godot b/project.godot index c41b82b1..676da076 100644 --- a/project.godot +++ b/project.godot @@ -64,6 +64,11 @@ shoot={ "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":32,"key_label":0,"unicode":32,"echo":false,"script":null) ] } +Use={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":70,"key_label":0,"unicode":102,"echo":false,"script":null) +] +} [layer_names]