mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 11:15:33 +00:00
Bullet data overhaul
This commit is contained in:
parent
3682de18d5
commit
76221ca7a6
9 changed files with 57 additions and 26 deletions
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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<Resource> _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,
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
@ -13,7 +13,7 @@ public partial class BulletSpawner : Node2D
|
|||
|
||||
public override void _Ready()
|
||||
{
|
||||
_gameManager = GetNode<GameManager>("/root/GameScene");
|
||||
_gameManager = this.GetGameManager();
|
||||
}
|
||||
|
||||
public void SpawnBullet(BulletInfo bulletInfo)
|
||||
|
|
@ -52,7 +52,6 @@ public partial class BulletSpawner : Node2D
|
|||
|
||||
//var bullet = BulletScene.Instantiate<Bullet>();
|
||||
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; }
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
public interface IDestructible
|
||||
{
|
||||
public void Hit(float damage);
|
||||
public void Hit(float damage, DamageType type = DamageType.Neutral);
|
||||
public bool IsDestroyed();
|
||||
}
|
||||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<Resource> _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<TimeModifier>().ToList() ??
|
||||
new List<TimeModifier>()
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue