mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-12 02:15:54 +00:00
Projectile Rotation
This commit is contained in:
parent
c8eb582f01
commit
56ac07367b
12 changed files with 188 additions and 27 deletions
|
|
@ -1,6 +1,8 @@
|
|||
using Godot;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using Cirno.Scripts;
|
||||
using Cirno.Scripts.Components;
|
||||
using Cirno.Scripts.Resources;
|
||||
|
|
@ -22,32 +24,41 @@ public partial class Bullet : Area2D
|
|||
private BulletInfo _bulletInfo;
|
||||
|
||||
public BulletInfo BulletInfo => _bulletInfo;
|
||||
|
||||
private List<ModifierWrapper> _modifiers = new();
|
||||
|
||||
public void Initialize(BulletInfo bulletInfo)
|
||||
{
|
||||
_bulletInfo = bulletInfo;
|
||||
|
||||
// Ugly hack to make instances unique
|
||||
_modifiers = _bulletInfo.TimeModifiers.Select(x => new ModifierWrapper()
|
||||
{
|
||||
TimeModifier = x.TimeModifier,
|
||||
Applied = x.Applied
|
||||
}).ToList();
|
||||
|
||||
//Position = bulletInfo.Position;
|
||||
}
|
||||
|
||||
private void ApplyTimeModifiers()
|
||||
{
|
||||
foreach (var modifier in _bulletInfo.TimeModifiers)
|
||||
foreach (var modifier in _modifiers)
|
||||
{
|
||||
if (modifier.Applied)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (_elapsedTime >= modifier.TimeInSeconds)
|
||||
if (_elapsedTime >= modifier.TimeModifier.TimeInSeconds)
|
||||
{
|
||||
switch (modifier.ModifierType)
|
||||
GD.Print("Applied time modifier");
|
||||
switch (modifier.TimeModifier.ModifierType)
|
||||
{
|
||||
case TimeModifierType.SpeedChange:
|
||||
//_bulletInfo.Speed += modifier.Value;
|
||||
Speed = modifier.Value;
|
||||
Speed = modifier.TimeModifier.Value;
|
||||
break;
|
||||
case TimeModifierType.RotationChange:
|
||||
RotateBullet(modifier.Value);
|
||||
RotateBullet(modifier.TimeModifier.Value);
|
||||
//Rotation += Mathf.DegToRad(modifier.Value);
|
||||
break;
|
||||
case TimeModifierType.FacePlayer:
|
||||
|
|
@ -64,6 +75,8 @@ public partial class Bullet : Area2D
|
|||
{
|
||||
float radians = Mathf.DegToRad(degrees);
|
||||
_direction = _direction.Rotated(radians).Normalized(); // Rotate direction
|
||||
SetRotation(Rotation + radians);
|
||||
//Rotation = radians;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -93,7 +106,9 @@ public partial class Bullet : Area2D
|
|||
var normalized = direction.Normalized();
|
||||
|
||||
_direction = normalized;
|
||||
|
||||
|
||||
SetRotation(Mathf.Atan2(normalized.Y,normalized.X) + Mathf.Pi / 2);
|
||||
|
||||
//Debug.WriteLine($"Bullet Shot at direction {direction.X} {direction.Y}");
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue