mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 10:15:45 +00:00
Exploding barrels
This commit is contained in:
parent
6a62fe2871
commit
71eeb3f1d1
12 changed files with 132 additions and 20 deletions
48
Scenes/Barrel.cs
Normal file
48
Scenes/Barrel.cs
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
using Godot;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
public partial class Barrel : Area2D, IDestructible
|
||||
{
|
||||
|
||||
[Export]
|
||||
public float Health = 1f;
|
||||
|
||||
[Export]
|
||||
public float ExplosionRadius = 1;
|
||||
|
||||
private float _currentHealth;
|
||||
|
||||
private bool _isDestroyed = false;
|
||||
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready()
|
||||
{
|
||||
_currentHealth = Health;
|
||||
}
|
||||
|
||||
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
}
|
||||
|
||||
public void Explode() {
|
||||
Debug.WriteLine("Boom");
|
||||
QueueFree();
|
||||
}
|
||||
|
||||
public void Hit(float damage)
|
||||
{
|
||||
if (_isDestroyed) return;
|
||||
_isDestroyed = true;
|
||||
Explode();
|
||||
|
||||
// TODO: Change sprite
|
||||
}
|
||||
|
||||
public bool IsDestroyed()
|
||||
{
|
||||
return _isDestroyed;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://bj28qiai2x2ar"]
|
||||
[gd_scene load_steps=6 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"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_2ewfl"]
|
||||
|
|
@ -9,9 +10,13 @@ size = Vector2(11, 14)
|
|||
atlas = ExtResource("1_e66t6")
|
||||
region = Rect2(0, 0, 16, 16)
|
||||
|
||||
[node name="Barrel" type="Area2D"]
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_ss2y0"]
|
||||
size = Vector2(11, 14)
|
||||
|
||||
[node name="Barrel" type="Area2D" groups=["Destroyable"]]
|
||||
collision_layer = 64
|
||||
collision_mask = 10
|
||||
script = ExtResource("1_avwdx")
|
||||
metadata/_edit_group_ = true
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
|
|
@ -21,3 +26,13 @@ shape = SubResource("RectangleShape2D_2ewfl")
|
|||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
texture = SubResource("AtlasTexture_v7gy8")
|
||||
|
||||
[node name="RigidBody2D" type="RigidBody2D" parent="."]
|
||||
collision_layer = 64
|
||||
collision_mask = 10
|
||||
gravity_scale = 0.0
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="RigidBody2D"]
|
||||
visible = false
|
||||
position = Vector2(0.5, -1)
|
||||
shape = SubResource("RectangleShape2D_ss2y0")
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://uaf5r6cd71hu"]
|
||||
[gd_scene load_steps=5 format=3 uid="uid://uaf5r6cd71hu"]
|
||||
|
||||
[ext_resource type="Script" path="res://Scenes/Barrel.cs" id="1_7ckvo"]
|
||||
[ext_resource type="Texture2D" uid="uid://d2rvjbllnogx4" path="res://Sprites/LargeTank.png" id="1_7h6ee"]
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_i3nxh"]
|
||||
|
|
@ -12,6 +13,8 @@ size = Vector2(61, 61)
|
|||
[node name="LargeTank" type="Area2D"]
|
||||
collision_layer = 65
|
||||
collision_mask = 11
|
||||
script = ExtResource("1_7ckvo")
|
||||
Health = 4.0
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
texture = SubResource("AtlasTexture_i3nxh")
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://7cpk3c3d8cl7"]
|
||||
[gd_scene load_steps=5 format=3 uid="uid://7cpk3c3d8cl7"]
|
||||
|
||||
[ext_resource type="Script" path="res://Scenes/Barrel.cs" id="1_laidj"]
|
||||
[ext_resource type="Texture2D" uid="uid://dqx1di84tkfft" path="res://Sprites/MediumLiquidTanks.png" id="1_mv1jg"]
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_i3nxh"]
|
||||
|
|
@ -10,8 +11,10 @@ region = Rect2(64, 96, 32, 32)
|
|||
size = Vector2(28, 24)
|
||||
|
||||
[node name="LargeTank" type="Area2D"]
|
||||
collision_layer = 65
|
||||
collision_mask = 11
|
||||
collision_layer = 64
|
||||
collision_mask = 10
|
||||
script = ExtResource("1_laidj")
|
||||
Health = 2.0
|
||||
metadata/_edit_group_ = true
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://crmwuwhltmdq7"]
|
||||
[gd_scene load_steps=5 format=3 uid="uid://crmwuwhltmdq7"]
|
||||
|
||||
[ext_resource type="Script" path="res://Scenes/Barrel.cs" id="1_c66eg"]
|
||||
[ext_resource type="Texture2D" uid="uid://b80wf43ow5d8b" path="res://Sprites/MediumTank.png" id="1_y64dw"]
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_i3nxh"]
|
||||
|
|
@ -9,9 +10,11 @@ region = Rect2(0, 0, 64, 64)
|
|||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_0nhpj"]
|
||||
size = Vector2(30, 28)
|
||||
|
||||
[node name="LargeTank" type="Area2D"]
|
||||
collision_layer = 65
|
||||
collision_mask = 11
|
||||
[node name="LargeTank" type="Area2D" groups=["Destroyable"]]
|
||||
collision_layer = 64
|
||||
collision_mask = 10
|
||||
script = ExtResource("1_c66eg")
|
||||
Health = 2.0
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
texture = SubResource("AtlasTexture_i3nxh")
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://bnhck5eh0tqxf"]
|
||||
[gd_scene load_steps=5 format=3 uid="uid://bnhck5eh0tqxf"]
|
||||
|
||||
[ext_resource type="Script" path="res://Scenes/Barrel.cs" id="1_iba8l"]
|
||||
[ext_resource type="Texture2D" uid="uid://juyup7so2u4g" path="res://Sprites/MediumTerminals.png" id="1_sgrg1"]
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_i3nxh"]
|
||||
|
|
@ -9,9 +10,10 @@ region = Rect2(96, 0, 32, 32)
|
|||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_0nhpj"]
|
||||
size = Vector2(28, 24)
|
||||
|
||||
[node name="LargeTank" type="Area2D"]
|
||||
collision_layer = 65
|
||||
collision_mask = 11
|
||||
[node name="LargeTank" type="Area2D" groups=["Destroyable"]]
|
||||
collision_layer = 64
|
||||
collision_mask = 10
|
||||
script = ExtResource("1_iba8l")
|
||||
metadata/_edit_group_ = true
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ radius = 2.23607
|
|||
|
||||
[node name="Bullet" type="Area2D" groups=["bullets"]]
|
||||
collision_layer = 8
|
||||
collision_mask = 21
|
||||
collision_mask = 85
|
||||
script = ExtResource("1_jvxw3")
|
||||
Speed = 200.0
|
||||
metadata/_edit_group_ = true
|
||||
|
|
@ -24,5 +24,6 @@ editor_description = "Player Bullet"
|
|||
|
||||
[node name="VisibleOnScreenNotifier2D" type="VisibleOnScreenNotifier2D" parent="."]
|
||||
|
||||
[connection signal="area_entered" from="." to="." method="_on_area_entered"]
|
||||
[connection signal="body_entered" from="." to="." method="_on_body_entered"]
|
||||
[connection signal="screen_exited" from="VisibleOnScreenNotifier2D" to="." method="_on_visible_on_screen_notifier_2d_screen_exited"]
|
||||
|
|
|
|||
|
|
@ -6950,6 +6950,15 @@ layer_2/tile_data = PackedInt32Array(-852021, 131072, 6, -786485, 131072, 6, -72
|
|||
|
||||
[node name="Barrel" parent="Factory Tilemaps/Solid" instance=ExtResource("5_3uba3")]
|
||||
position = Vector2(-751, -166)
|
||||
Health = 2.0
|
||||
|
||||
[node name="Barrel2" parent="Factory Tilemaps/Solid" instance=ExtResource("5_3uba3")]
|
||||
position = Vector2(-615, -103)
|
||||
Health = 2.0
|
||||
|
||||
[node name="Barrel3" parent="Factory Tilemaps/Solid" instance=ExtResource("5_3uba3")]
|
||||
position = Vector2(-631, -103)
|
||||
Health = 2.0
|
||||
|
||||
[node name="LargeTank" parent="Factory Tilemaps/Solid" instance=ExtResource("6_nkauc")]
|
||||
position = Vector2(-639, 71)
|
||||
|
|
|
|||
|
|
@ -7,6 +7,9 @@ public partial class Bullet : Area2D
|
|||
[Export]
|
||||
public float Speed = 1900f;
|
||||
|
||||
[Export]
|
||||
public float Damage = 1f;
|
||||
|
||||
private Vector2 _direction = Vector2.Right;
|
||||
|
||||
//public delegate void BulletHitEventHandler(Node Body);
|
||||
|
|
@ -53,15 +56,28 @@ public partial class Bullet : Area2D
|
|||
{
|
||||
if (body.IsInGroup("Solid"))
|
||||
{
|
||||
Debug.WriteLine("Collision");
|
||||
//Debug.WriteLine("Collision");
|
||||
QueueFree();
|
||||
}
|
||||
else if (body.IsInGroup("Destroyable"))
|
||||
{
|
||||
Debug.WriteLine("Collision with destroyable object body");
|
||||
QueueFree();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void _on_area_entered(Area2D area)
|
||||
{
|
||||
// Replace with function body.
|
||||
if (area.IsInGroup("Destroyable") && area is IDestructible destructible)
|
||||
{
|
||||
//Debug.WriteLine("Collision with destroyable object area");
|
||||
|
||||
destructible.Hit(Damage);
|
||||
|
||||
QueueFree();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
6
Scripts/IDestructible.cs
Normal file
6
Scripts/IDestructible.cs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
|
||||
public interface IDestructible
|
||||
{
|
||||
public void Hit(float damage);
|
||||
public bool IsDestroyed();
|
||||
}
|
||||
BIN
Sprites/boxes-sprites.aseprite
(Stored with Git LFS)
Normal file
BIN
Sprites/boxes-sprites.aseprite
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Sprites/chest_generic_red.aseprite
(Stored with Git LFS)
Normal file
BIN
Sprites/chest_generic_red.aseprite
(Stored with Git LFS)
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue