diff --git a/Scenes/Barrel.cs b/Scenes/Barrel.cs index 9a24d904..d0a9ca37 100644 --- a/Scenes/Barrel.cs +++ b/Scenes/Barrel.cs @@ -104,7 +104,7 @@ public partial class Barrel : Area2D, IDestructible } - public void Hit(float damage) + public void Hit(float damage, DamageType damageType = DamageType.Neutral) { if (_isDestroyed) return; diff --git a/Scripts/AttackPatterns/SpiralPattern.cs b/Scripts/AttackPatterns/SpiralPattern.cs index b3a15557..63ac24bf 100644 --- a/Scripts/AttackPatterns/SpiralPattern.cs +++ b/Scripts/AttackPatterns/SpiralPattern.cs @@ -20,6 +20,8 @@ public partial class SpiralPattern : AttackPattern [Export] private float burstInterval = 0.5f; [Export] private float spread = 360f; [Export] private BulletOwner owner = BulletOwner.Enemy; + [Export] private DamageType _damageType = DamageType.Neutral; + [Export] private float _bulletDamage = 1f; [Export] private Resource _modifier; [Export] private Array _timeModifiers; @@ -49,6 +51,8 @@ public partial class SpiralPattern : AttackPattern Direction = Vector2.Right, Speed = bulletSpeed, Owner = owner, + DamageType = _damageType, + Damage = _bulletDamage, BulletCount = bulletCount, Spread = spread, BulletScene = BulletScene, diff --git a/Scripts/Bullet.cs b/Scripts/Bullet.cs index 5488a7b4..db97f063 100644 --- a/Scripts/Bullet.cs +++ b/Scripts/Bullet.cs @@ -8,24 +8,25 @@ public partial class Bullet : Area2D { [Export] public float Speed = 1900f; - - [Export] - public float Damage = 1f; - [Export] - public BulletOwner Owner = BulletOwner.None; + public BulletOwner BulletOwner => _bulletInfo?.Owner ?? BulletOwner.None; + + public float Damage => _bulletInfo?.Damage ?? 1; + + public DamageType DamageType => _bulletInfo?.DamageType ?? DamageType.Neutral; private Vector2 _direction = Vector2.Right; private double _elapsedTime = 0f; private BulletInfo _bulletInfo; + + public BulletInfo BulletInfo => _bulletInfo; public void Initialize(BulletInfo bulletInfo) { _bulletInfo = bulletInfo; - Position = bulletInfo.Position; - Owner = bulletInfo.Owner; + //Position = bulletInfo.Position; } private void ApplyTimeModifiers() @@ -141,7 +142,7 @@ public partial class Bullet : Area2D { //Debug.WriteLine("Collision with destroyable object area"); - destructible.Hit(Damage); + destructible.Hit(Damage, DamageType); QueueFree(); } @@ -154,3 +155,13 @@ public enum BulletOwner Player, Enemy } + +public enum DamageType +{ + Neutral, + Ballistic, + Fire, + Ice, + Explosive, + Acid +} \ No newline at end of file diff --git a/Scripts/Components/BulletSpawner.cs b/Scripts/Components/BulletSpawner.cs index 4573b81d..92128413 100644 --- a/Scripts/Components/BulletSpawner.cs +++ b/Scripts/Components/BulletSpawner.cs @@ -13,7 +13,7 @@ public partial class BulletSpawner : Node2D public override void _Ready() { - _gameManager = GetNode("/root/GameScene"); + _gameManager = this.GetGameManager(); } public void SpawnBullet(BulletInfo bulletInfo) @@ -52,7 +52,6 @@ public partial class BulletSpawner : Node2D //var bullet = BulletScene.Instantiate(); bullet.Position = position; - bullet.Owner = owner; //bullet.Speed = speed; float modifiedSpeed = modifier?.ModifySpeed(speed, i, count) ?? speed; @@ -75,13 +74,6 @@ public partial class BulletSpawner : Node2D Vector2 direction = (target - position).Normalized(); SpawnBullet(position, direction, speed, owner, burstCount, spread: spread, bulletScene: bulletScene, modifier: modifier); } - - [Obsolete] - public void SpawnSpiralPattern(Vector2 position, float speed, BulletOwner owner, int bulletCount, float rotationSpeed, double time, float spread, PackedScene bulletScene = null) - { - float angleOffset = (float)(rotationSpeed * time); - SpawnBullet(position, Vector2.Right, speed, owner, bulletCount, angleOffset, spread, bulletScene: bulletScene); - } } public class BulletInfo @@ -91,6 +83,8 @@ public class BulletInfo public float Speed { get; set; } public float LifeTime { get; set; } public BulletOwner Owner { get; set; } + public DamageType DamageType { get; set; } + public float Damage { get; set; } public int BulletCount { get; set; } public float RotationSpeed { get; set; } public float RotationOffset { get; set; } diff --git a/Scripts/Hud.cs b/Scripts/Hud.cs index e7589940..d9ad8a7f 100644 --- a/Scripts/Hud.cs +++ b/Scripts/Hud.cs @@ -80,9 +80,6 @@ public partial class Hud : CanvasLayer public void UpdateInteractable(Interactable interactable) { GD.Print($"Interactable ${interactable.Name} entered in HUD"); - - - //_selector.Position = _selector.tolo } diff --git a/Scripts/IDestructible.cs b/Scripts/IDestructible.cs index 74b9d5ea..0d9c22ed 100644 --- a/Scripts/IDestructible.cs +++ b/Scripts/IDestructible.cs @@ -1,6 +1,6 @@ public interface IDestructible { - public void Hit(float damage); + public void Hit(float damage, DamageType type = DamageType.Neutral); public bool IsDestroyed(); } \ No newline at end of file diff --git a/Scripts/PlayerMovement.cs b/Scripts/PlayerMovement.cs index a8744f6f..b279f3ae 100644 --- a/Scripts/PlayerMovement.cs +++ b/Scripts/PlayerMovement.cs @@ -426,7 +426,7 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible } } - public void Hit(float damage) + public void Hit(float damage, DamageType type = DamageType.Neutral) { if (!_canMove) return; GD.Print($"Player damaged for {damage}"); @@ -446,10 +446,9 @@ public partial class PlayerMovement : CharacterBody2D, IDestructible private void _on_damage_hit_box_area_entered(Area2D area) { if (!_canMove) return; - if (area is Bullet bullet) + if (area is Bullet bullet && bullet.BulletOwner != BulletOwner.Player) { - GD.Print("Received damage manually"); - this.Hit(bullet.Damage); + this.Hit(bullet.Damage, bullet.DamageType); bullet.QueueFree(); } } diff --git a/Scripts/Resources/WeaponResource.cs b/Scripts/Resources/WeaponResource.cs index 4946f95b..99d7833c 100644 --- a/Scripts/Resources/WeaponResource.cs +++ b/Scripts/Resources/WeaponResource.cs @@ -1,3 +1,5 @@ +using System.Collections.Generic; +using System.Linq; using Cirno.Scripts.Components; using Godot; using Godot.Collections; @@ -33,11 +35,33 @@ public partial class WeaponResource : Resource [Export] public string AmmoKey; [Export] public float BulletSpeed = 100f; [Export] public float BulletDamage = 1; + [Export] public float LifeTime = 10f; [Export] private float _rotationOffset = 0f; [Export] private BulletOwner owner = BulletOwner.None; + [Export] private DamageType _damageType = DamageType.Neutral; [Export] private Resource _modifier; [Export] private Array _timeModifiers; #endregion + public BulletInfo MakeBullet(Vector2 position) + { + return new BulletInfo() + { + Position = position, + Direction = Vector2.Right, + Speed = BulletSpeed, + Owner = owner, + DamageType = _damageType, + Damage = BulletDamage, + BulletCount = BulletsPerShot, + Spread = SpreadAngle, + BulletScene = BulletScene, + RotationOffset = _rotationOffset, + Modifier = _modifier as IBulletModifier, + LifeTime = LifeTime, + TimeModifiers = _timeModifiers?.Where(mod => mod is TimeModifier).Cast().ToList() ?? + new List() + }; + } } \ No newline at end of file diff --git a/Scripts/Weapon.cs b/Scripts/Weapon.cs index 8cd4cf25..2f9b15ed 100644 --- a/Scripts/Weapon.cs +++ b/Scripts/Weapon.cs @@ -106,6 +106,8 @@ public partial class Weapon : Node2D GD.PrintErr("Bullet is null, not shooting"); return; }; + + bullet.Initialize(WeaponData.MakeBullet(_muzzle.GlobalPosition)); //bullet.SetDirection(ShootDirection); bullet.SetDirection(spreadDirection);