Generic enemies

This commit is contained in:
Marco 2025-06-03 10:11:09 +02:00
commit d99c773641
55 changed files with 968 additions and 204 deletions

View file

@ -0,0 +1,14 @@
using System;
namespace Cirno.Scripts.Components;
[Flags]
public enum BulletFlags
{
Freezable = 1 << 1,
Controllable = 1 << 2,
Bouncy = 1 << 3,
Piercing = 1 << 4,
Grazeable = 1 << 5,
Rotateable = 1 << 6,
}

View file

@ -0,0 +1 @@
uid://d6fmk6vngnxi

View file

@ -0,0 +1,45 @@
using System.Collections.Generic;
using Cirno.Scripts.Resources;
using Godot;
namespace Cirno.Scripts.Components;
public class BulletInfo(BulletResource originalBulletResource)
{
public BulletResource OriginalBulletResource { get; set; } = originalBulletResource;
public Vector2 Position { get; set; }
public Vector2 Direction { get; set; }
public float Speed { get; set; }
public float LifeTime { get; set; }
public bool DestroyOnCollision { get; set; }
public BulletOwner Owner { get; set; }
public DamageType DamageType { get; set; }
public float Damage { get; set; }
public float Knockback { get; set; }
public int BulletCount { get; set; }
public float RotationSpeed { get; set; }
public float RotationOffset { get; set; }
//public double Time { get; set; }
public float Spread { get; set; }
public bool RotateSprite { get; set; } = false;
public bool Controllabe { get; set; } = false;
public bool Freezable { get; set; } = true;
public PackedScene BulletScene { get; set; }
public PackedScene DestructionParticlesScene { get; set; }
public IBulletModifier Modifier { get; set; }
public List<TimeModifier> TimeModifiers { get; set; } = new List<TimeModifier>();
public bool Grazeable { get; set; }
public float GrazeValue { get; set; }
public BulletFlags Attributes { get; set; }
#region Laser
public bool IsLaser { get; set; }
public float SpawnDelay { get; set; } = 0.3f; // Delay before beam appears
public float PreFireTime { get; set; } = 0.5f; // Time before laser becomes lethal
public float LethalTime { get; set; } = 1.5f; // Time laser remains lethal
public Color PreFireColor { get; set; } = new Color(1, 0, 0, 0.5f); // Thin red beam
public Color LethalColor { get; set; } = new Color(1, 0, 0, 1.0f); // Thicker beam
#endregion
}

View file

@ -0,0 +1 @@
uid://r80khe0f3jj8

View file

@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using Cirno.Scripts.Resources;
using Cirno.Scripts.Weapons;
using Godot;
using Godot.Collections;
@ -90,42 +88,4 @@ public partial class BulletSpawner : Node2D
// Vector2 direction = (target - position).Normalized();
// SpawnBullet(position, direction, speed, owner, burstCount, spread: spread, bulletScene: bulletScene, modifier: modifier);
// }
}
public class BulletInfo(BulletResource originalBulletResource)
{
public BulletResource OriginalBulletResource { get; set; } = originalBulletResource;
public Vector2 Position { get; set; }
public Vector2 Direction { get; set; }
public float Speed { get; set; }
public float LifeTime { get; set; }
public bool DestroyOnCollision { get; set; }
public BulletOwner Owner { get; set; }
public DamageType DamageType { get; set; }
public float Damage { get; set; }
public float Knockback { get; set; }
public int BulletCount { get; set; }
public float RotationSpeed { get; set; }
public float RotationOffset { get; set; }
//public double Time { get; set; }
public float Spread { get; set; }
public bool RotateSprite { get; set; } = false;
public bool Controllabe { get; set; } = false;
public bool Freezable { get; set; } = true;
public PackedScene BulletScene { get; set; }
public PackedScene DestructionParticlesScene { get; set; }
public IBulletModifier Modifier { get; set; }
public List<TimeModifier> TimeModifiers { get; set; } = new List<TimeModifier>();
public bool Grazeable { get; set; }
public float GrazeValue { get; set; }
#region Laser
public bool IsLaser { get; set; }
public float SpawnDelay { get; set; } = 0.3f; // Delay before beam appears
public float PreFireTime { get; set; } = 0.5f; // Time before laser becomes lethal
public float LethalTime { get; set; } = 1.5f; // Time laser remains lethal
public Color PreFireColor { get; set; } = new Color(1, 0, 0, 0.5f); // Thin red beam
public Color LethalColor { get; set; } = new Color(1, 0, 0, 1.0f); // Thicker beam
#endregion
}
}

View file

@ -36,6 +36,16 @@ public partial class Shooting : EnemyStateBase
public float CurrentHealth => DamageReceiver.HealthProvider.CurrentResource;
public override void Init(IStateMachine<EnemyState, CharacterBody2D> machine)
{
base.Init(machine);
if (StorageModule.Root.EnemyResource.BossScript is not null)
{
this.BossScript = StorageModule.Root.EnemyResource.BossScript;
}
}
public override void EnterState()
{
base.EnterState();

View file

@ -0,0 +1,16 @@
using Godot;
namespace Cirno.Scripts.Components.FSM.Enemy;
public partial class EnemyFSMAnimatedSprite : AnimatedSprite2D
{
public override void _Ready()
{
var enemyFsmProxy = this.GetParentOrNull<EnemyFSMProxy>();
if (enemyFsmProxy?.EnemyResource?.AnimationFrames != null)
{
this.SpriteFrames = enemyFsmProxy.EnemyResource.AnimationFrames;
}
}
}

View file

@ -0,0 +1 @@
uid://dathhlufbe6gr

View file

@ -27,6 +27,12 @@ public partial class EnemyFSMProxy : CharacterBody2D, IActivable
[Signal] public delegate void DeathEventHandler(EnemyFSMProxy enemy);
public void Init(EnemyResource enemyResource)
{
this.EnemyResource = enemyResource;
}
public void TriggerDeath()
{
EmitSignalDeath(this);