Interactions

This commit is contained in:
MaddoScientisto 2024-06-09 18:19:57 +02:00
commit abff2ea59e
19 changed files with 282 additions and 10 deletions

View file

@ -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<Barrel>();
Owner.AddChild(debris);
debris.Transform = this.GlobalTransform;
debris.Position = this.Position;
this.CreateChild<Barrel>(DebrisScene);
// if (DebrisScene == null) return;
// var debris = DebrisScene.Instantiate<Barrel>();
// Owner.CallDeferred("add_child", debris); //.AddChild(debris);
// debris.Transform = this.GlobalTransform;
// debris.Position = this.Position;
}
private void CreateParticles()
{
var particle = this.CreateChild<GpuParticles2D>(ExplosionParticles);
if (particle == null) return;
particle.Emitting = true;
// if (ExplosionParticles == null) return;
// var emitter = ExplosionParticles.Instantiate<GpuParticles2D>();
// Owner.CallDeferred("add_child", emitter);
// emitter.Transform = this.GlobalTransform;
// emitter.Position = this.Position;
//
// emitter.Emitting = true;
}
// private T CreateChild<T>(PackedScene prefab) where T : Node2D
// {
// if (prefab == null) return null;
// var newInstance = prefab.Instantiate<T>();
// Owner.CallDeferred("add_child", newInstance);
// newInstance.Transform = this.GlobalTransform;
// newInstance.Position = this.Position;
//
// return newInstance;
// }
public void Hit(float damage)
{
if (_isDestroyed) return;

View file

@ -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="."]

View file

@ -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="."]

17
Scenes/Control_Pad.tscn Normal file
View file

@ -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")

View file

@ -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

21
Scenes/Interactable.cs Normal file
View file

@ -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");
}
}

View file

@ -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)
{
}
}

8
Scenes/Selector.tscn Normal file
View file

@ -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")

View file

@ -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"]

View file

@ -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")

View file

@ -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<Node2D>(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;
}
}
}
}

17
Scripts/Tools.cs Normal file
View file

@ -0,0 +1,17 @@
using Godot;
namespace Cirno.Scripts;
public static class Tools
{
public static T CreateChild<T>(this Node2D node, PackedScene prefab) where T : Node2D
{
if (prefab == null) return null;
var newInstance = prefab.Instantiate<T>();
node.Owner.CallDeferred("add_child", newInstance);
newInstance.Transform = node.GlobalTransform;
newInstance.Position = node.Position;
return newInstance;
}
}

BIN
Sprites/Control_Pad.aseprite (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Sprites/Control_Pad.png (Stored with Git LFS) Normal file

Binary file not shown.

View file

@ -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

BIN
Sprites/selector.aseprite (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Sprites/selector.png (Stored with Git LFS) Normal file

Binary file not shown.

View file

@ -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

View file

@ -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]