mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-07 11:25:55 +00:00
Weapon Sprites
This commit is contained in:
parent
b4a35ac3d4
commit
f4f193af7a
19 changed files with 321 additions and 42 deletions
|
|
@ -89,6 +89,7 @@ public class BulletInfo
|
|||
public Vector2 Position { get; set; }
|
||||
public Vector2 Direction { get; set; }
|
||||
public float Speed { get; set; }
|
||||
public float LifeTime { get; set; }
|
||||
public BulletOwner Owner { get; set; }
|
||||
public int BulletCount { get; set; }
|
||||
public float RotationSpeed { get; set; }
|
||||
|
|
|
|||
42
Scripts/Resources/WeaponResource.cs
Normal file
42
Scripts/Resources/WeaponResource.cs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
using Cirno.Scripts.Components;
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
|
||||
namespace Cirno.Scripts.Resources;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class WeaponResource : Resource
|
||||
{
|
||||
[Export]
|
||||
public string Name { get; set; }
|
||||
|
||||
[Export]
|
||||
public PackedScene BulletScene { get; set; }
|
||||
|
||||
[Export] public double RateOfFire = 0.4f;
|
||||
|
||||
[Export] public int BulletCapacity = 20;
|
||||
|
||||
[Export] public double ReloadTime = 1.0f;
|
||||
|
||||
[Export] public bool AutoReload = true;
|
||||
|
||||
[Export] public bool InfiniteAmmo = true;
|
||||
|
||||
[Export] public int BulletsPerShot = 1;
|
||||
|
||||
[Export] public float SpreadAngle = 0f;
|
||||
[Export] public float RandomSpread = 0f;
|
||||
|
||||
#region Bullet spawn data
|
||||
|
||||
[Export] public float BulletSpeed = 100f;
|
||||
[Export] public float BulletDamage = 1;
|
||||
[Export] private float _rotationOffset = 0f;
|
||||
[Export] private BulletOwner owner = BulletOwner.None;
|
||||
[Export] private Resource _modifier;
|
||||
[Export] private Array<Resource> _timeModifiers;
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
|
@ -2,32 +2,21 @@ using Godot;
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using Cirno.Scripts;
|
||||
using Cirno.Scripts.Components;
|
||||
using Cirno.Scripts.Resources;
|
||||
|
||||
public partial class Weapon : Node2D
|
||||
{
|
||||
|
||||
[Export]
|
||||
public WeaponResource WeaponData { get; set; }
|
||||
|
||||
[Export]
|
||||
public PackedScene BulletScene { get; set; }
|
||||
|
||||
[Export]
|
||||
public Marker2D Muzzle { get; set; }
|
||||
|
||||
[Export] public double RateOfFire = 0.4f;
|
||||
|
||||
[Export] public int BulletCapacity = 20;
|
||||
|
||||
[Export] public double ReloadTime = 1.0f;
|
||||
|
||||
[Export] public float BulletSpeed = 100f;
|
||||
|
||||
[Export] public bool AutoReload = true;
|
||||
|
||||
[Export] public bool InfiniteAmmo = true;
|
||||
|
||||
[Export] public int BulletsPerShot = 1;
|
||||
|
||||
[Export] public float BulletsSpreadAngle = 0f;
|
||||
|
||||
public int Ammo { get; set; } = 0;
|
||||
|
||||
public int LoadedAmmo { get; private set; }
|
||||
|
|
@ -53,16 +42,16 @@ public partial class Weapon : Node2D
|
|||
|
||||
public void Reload()
|
||||
{
|
||||
_cooldownTimer.Start(ReloadTime);
|
||||
_cooldownTimer.Start(WeaponData.ReloadTime);
|
||||
|
||||
if (InfiniteAmmo)
|
||||
if (WeaponData.InfiniteAmmo)
|
||||
{
|
||||
LoadedAmmo = BulletCapacity;
|
||||
LoadedAmmo = WeaponData.BulletCapacity;
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: Calculate subtraction, etc
|
||||
LoadedAmmo = BulletCapacity;
|
||||
LoadedAmmo = WeaponData.BulletCapacity;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -77,7 +66,7 @@ public partial class Weapon : Node2D
|
|||
// Out of ammo?
|
||||
if (LoadedAmmo <= 0)
|
||||
{
|
||||
if (AutoReload)
|
||||
if (WeaponData.AutoReload)
|
||||
{
|
||||
Reload();
|
||||
}
|
||||
|
|
@ -86,11 +75,11 @@ public partial class Weapon : Node2D
|
|||
|
||||
// TODO: Shoot at muzzle position, need to provide a way to turn it, on a radius?
|
||||
|
||||
float halfSpread = BulletsSpreadAngle / 2f;
|
||||
float spreadStep = BulletsPerShot > 1 ? BulletsSpreadAngle / (BulletsPerShot - 1) : 0;
|
||||
float halfSpread = WeaponData.SpreadAngle / 2f;
|
||||
float spreadStep = WeaponData.BulletsPerShot > 1 ? WeaponData.SpreadAngle / (WeaponData.BulletsPerShot - 1) : 0;
|
||||
|
||||
|
||||
for (int i = 0; i < BulletsPerShot; i++)
|
||||
for (int i = 0; i < WeaponData.BulletsPerShot; i++)
|
||||
{
|
||||
// Calculate angle offset for this bullet
|
||||
float spreadOffset = -halfSpread + (spreadStep * i);
|
||||
|
|
@ -98,7 +87,7 @@ public partial class Weapon : Node2D
|
|||
// Rotate the ShootDirection by the spread angle
|
||||
Vector2 spreadDirection = ShootDirection.Rotated(Mathf.DegToRad(spreadOffset));
|
||||
|
||||
var bullet = this.CreateChildOf<Bullet>(_gameManager.BulletsContainer, BulletScene, _muzzle.GlobalPosition);
|
||||
var bullet = this.CreateChildOf<Bullet>(_gameManager.BulletsContainer, WeaponData.BulletScene, _muzzle.GlobalPosition);
|
||||
|
||||
if (bullet == null)
|
||||
{
|
||||
|
|
@ -108,11 +97,11 @@ public partial class Weapon : Node2D
|
|||
|
||||
//bullet.SetDirection(ShootDirection);
|
||||
bullet.SetDirection(spreadDirection);
|
||||
bullet.Speed = BulletSpeed;
|
||||
bullet.Speed = WeaponData.BulletSpeed;
|
||||
}
|
||||
|
||||
LoadedAmmo -= 1;
|
||||
|
||||
_cooldownTimer.Start(RateOfFire);
|
||||
_cooldownTimer.Start(WeaponData.RateOfFire);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue