Explosion sprites and lifetime

This commit is contained in:
Marco 2025-02-20 12:17:21 +01:00
commit a0b5cedff9
10 changed files with 102 additions and 18 deletions

View file

@ -13,6 +13,7 @@ BulletScene = ExtResource("4_epbro")
BulletSpeed = 0.0 BulletSpeed = 0.0
BulletDamage = 8.0 BulletDamage = 8.0
LifeTime = 1.0 LifeTime = 1.0
DestroyOnCollision = false
Owner = 0 Owner = 0
DamageType = 4 DamageType = 4
TimeModifiers = null TimeModifiers = null

View file

@ -1,8 +1,72 @@
[gd_scene load_steps=4 format=3 uid="uid://h11o0et1y54v"] [gd_scene load_steps=13 format=3 uid="uid://h11o0et1y54v"]
[ext_resource type="Script" path="res://Scripts/Bullet.cs" id="1_f0epf"] [ext_resource type="Script" path="res://Scripts/Bullet.cs" id="1_f0epf"]
[ext_resource type="Texture2D" uid="uid://b2bp03a70cpyd" path="res://Sprites/Explosion1.png" id="2_gmwb3"] [ext_resource type="Texture2D" uid="uid://b2bp03a70cpyd" path="res://Sprites/Explosion1.png" id="2_gmwb3"]
[sub_resource type="AtlasTexture" id="AtlasTexture_ltwjd"]
atlas = ExtResource("2_gmwb3")
region = Rect2(0, 0, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_b8hsa"]
atlas = ExtResource("2_gmwb3")
region = Rect2(32, 0, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_1jqx0"]
atlas = ExtResource("2_gmwb3")
region = Rect2(64, 0, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_g2luq"]
atlas = ExtResource("2_gmwb3")
region = Rect2(96, 0, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_yyc14"]
atlas = ExtResource("2_gmwb3")
region = Rect2(128, 0, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_qhukn"]
atlas = ExtResource("2_gmwb3")
region = Rect2(160, 0, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_afp5d"]
atlas = ExtResource("2_gmwb3")
region = Rect2(192, 0, 32, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_cpopo"]
atlas = ExtResource("2_gmwb3")
region = Rect2(224, 0, 32, 32)
[sub_resource type="SpriteFrames" id="SpriteFrames_6egyg"]
animations = [{
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_ltwjd")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_b8hsa")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_1jqx0")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_g2luq")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_yyc14")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_qhukn")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_afp5d")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_cpopo")
}],
"loop": false,
"name": &"default",
"speed": 8.0
}]
[sub_resource type="CircleShape2D" id="CircleShape2D_jxptd"] [sub_resource type="CircleShape2D" id="CircleShape2D_jxptd"]
radius = 17.0 radius = 17.0
@ -13,8 +77,10 @@ script = ExtResource("1_f0epf")
Speed = 0.0 Speed = 0.0
metadata/_edit_group_ = true metadata/_edit_group_ = true
[node name="Sprite2D" type="Sprite2D" parent="."] [node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
texture = ExtResource("2_gmwb3") sprite_frames = SubResource("SpriteFrames_6egyg")
autoplay = "default"
frame = 1
[node name="CollisionShape2D" type="CollisionShape2D" parent="."] [node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource("CircleShape2D_jxptd") shape = SubResource("CircleShape2D_jxptd")

File diff suppressed because one or more lines are too long

View file

@ -34,14 +34,15 @@ public partial class Bullet : Area2D
_gameManager = gameManager; _gameManager = gameManager;
_elapsedTime = 0f;
// Need to clone them here // Need to clone them here
// _modifiers = _bulletInfo.TimeModifiers.Select(x => x.MakeClone()).ToList(); // _modifiers = _bulletInfo.TimeModifiers.Select(x => x.MakeClone()).ToList();
// var clonedModifiers = _bulletInfo.TimeModifiers.Select(x => x.MakeClone()); // var clonedModifiers = _bulletInfo.TimeModifiers.Select(x => x.MakeClone());
// _modifiers = clonedModifiers.ToList(); // _modifiers = clonedModifiers.ToList();
// Ugly hack to make instances unique // Ugly hack to make instances unique
_modifiers = _bulletInfo.TimeModifiers.Select(x => x.Wrap()).ToList(); _modifiers = _bulletInfo.TimeModifiers.Select(x => x.Wrap()).ToList();
} }
@ -136,6 +137,11 @@ public partial class Bullet : Area2D
public override void _Process(double delta) public override void _Process(double delta)
{ {
_elapsedTime += delta; _elapsedTime += delta;
if (_elapsedTime >= _bulletInfo.LifeTime)
{
Destroy();
}
} }
public override void _PhysicsProcess(double delta) public override void _PhysicsProcess(double delta)
@ -159,7 +165,7 @@ public partial class Bullet : Area2D
if (body.IsInGroup("Solid")) if (body.IsInGroup("Solid"))
{ {
//Debug.WriteLine("Collision"); //Debug.WriteLine("Collision");
Destroy(); RequestCollisionDestruction();
} }
//// Do not Collide with body for purpose of destroying bullets //// Do not Collide with body for purpose of destroying bullets
// else if (body.IsInGroup("Destroyable")) // else if (body.IsInGroup("Destroyable"))
@ -173,7 +179,7 @@ public partial class Bullet : Area2D
{ {
if (area.IsInGroup("Solid")) if (area.IsInGroup("Solid"))
{ {
Destroy(); RequestCollisionDestruction();
return; return;
} }
@ -183,7 +189,7 @@ public partial class Bullet : Area2D
// hit // hit
destructible.Hit(Damage, DamageType); destructible.Hit(Damage, DamageType);
Destroy(); RequestCollisionDestruction();
} }
} }
@ -199,8 +205,15 @@ public partial class Bullet : Area2D
return bulletOwner != targetGroup; return bulletOwner != targetGroup;
} }
public void RequestCollisionDestruction()
{
if (_bulletInfo.DestroyOnCollision)
{
Destroy();
}
}
public void Destroy() private void Destroy()
{ {
if (_bulletInfo?.DestructionParticlesScene != null) if (_bulletInfo?.DestructionParticlesScene != null)
{ {

View file

@ -88,6 +88,7 @@ public class BulletInfo
public Vector2 Direction { get; set; } public Vector2 Direction { get; set; }
public float Speed { get; set; } public float Speed { get; set; }
public float LifeTime { get; set; } public float LifeTime { get; set; }
public bool DestroyOnCollision { get; set; }
public BulletOwner Owner { get; set; } public BulletOwner Owner { get; set; }
public DamageType DamageType { get; set; } public DamageType DamageType { get; set; }
public float Damage { get; set; } public float Damage { get; set; }

View file

@ -251,7 +251,7 @@ public partial class Enemy : CharacterBody2D
if (bullet.BulletInfo.Owner == BulletOwner.Enemy) return; if (bullet.BulletInfo.Owner == BulletOwner.Enemy) return;
this.Hit(bullet.Damage); this.Hit(bullet.Damage);
bullet.QueueFree(); bullet.RequestCollisionDestruction();
} }
// Bullets collision // Bullets collision

View file

@ -442,7 +442,7 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible
if (area is Bullet bullet && bullet.BulletOwner != BulletGroup) if (area is Bullet bullet && bullet.BulletOwner != BulletGroup)
{ {
this.Hit(bullet.Damage, bullet.DamageType); this.Hit(bullet.Damage, bullet.DamageType);
bullet.QueueFree(); bullet.RequestCollisionDestruction();
} }
} }

View file

@ -15,6 +15,7 @@ public partial class BulletResource : Resource
[Export] public float BulletSpeed = 100f; [Export] public float BulletSpeed = 100f;
[Export] public float BulletDamage = 1; [Export] public float BulletDamage = 1;
[Export] public float LifeTime = 10f; [Export] public float LifeTime = 10f;
[Export] public bool DestroyOnCollision = true;
[Export] public BulletOwner Owner = BulletOwner.None; [Export] public BulletOwner Owner = BulletOwner.None;
[Export] public DamageType DamageType = DamageType.Neutral; [Export] public DamageType DamageType = DamageType.Neutral;
@ -38,6 +39,7 @@ public partial class BulletResource : Resource
RotationOffset = rotationOffset, RotationOffset = rotationOffset,
Modifier = Modifier, Modifier = Modifier,
LifeTime = LifeTime, LifeTime = LifeTime,
DestroyOnCollision = DestroyOnCollision,
DestructionParticlesScene = DestructionParticlesScene, DestructionParticlesScene = DestructionParticlesScene,
TimeModifiers = TimeModifiers.Select(x => x).ToList() TimeModifiers = TimeModifiers.Select(x => x).ToList()
// TimeModifiers = TimeModifiers?.Where(mod => mod is TimeModifier).Cast<TimeModifier>().Select(m => new ModifierWrapper() // TimeModifiers = TimeModifiers?.Where(mod => mod is TimeModifier).Cast<TimeModifier>().Select(m => new ModifierWrapper()

BIN
Sprites/Explosion1.aseprite (Stored with Git LFS)

Binary file not shown.

BIN
Sprites/Explosion1.png (Stored with Git LFS)

Binary file not shown.