mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-06 01:55:54 +00:00
Time modifiers
This commit is contained in:
parent
690bae01bc
commit
4e6257dbe3
6 changed files with 99 additions and 9 deletions
|
|
@ -1,6 +1,8 @@
|
|||
using Godot;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using Cirno.Scripts.Components;
|
||||
using Cirno.Scripts.Resources;
|
||||
|
||||
public partial class Bullet : Area2D
|
||||
{
|
||||
|
|
@ -14,15 +16,66 @@ public partial class Bullet : Area2D
|
|||
public BulletOwner Owner = BulletOwner.None;
|
||||
|
||||
private Vector2 _direction = Vector2.Right;
|
||||
|
||||
//public delegate void BulletHitEventHandler(Node Body);
|
||||
//public event BulletHitEventHandler BulletHit;
|
||||
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready()
|
||||
|
||||
private double _elapsedTime = 0f;
|
||||
private BulletInfo _bulletInfo;
|
||||
|
||||
public void Initialize(BulletInfo bulletInfo)
|
||||
{
|
||||
//this.Connect("body_entered", new Callable(this, nameof(OnBodyEntered)));
|
||||
_bulletInfo = bulletInfo;
|
||||
|
||||
Position = bulletInfo.Position;
|
||||
Owner = bulletInfo.Owner;
|
||||
}
|
||||
|
||||
private void ApplyTimeModifiers()
|
||||
{
|
||||
foreach (var modifier in _bulletInfo.TimeModifiers)
|
||||
{
|
||||
if (modifier.Applied)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (_elapsedTime >= modifier.TimeInSeconds)
|
||||
{
|
||||
switch (modifier.ModifierType)
|
||||
{
|
||||
case TimeModifierType.SpeedChange:
|
||||
//_bulletInfo.Speed += modifier.Value;
|
||||
Speed = modifier.Value;
|
||||
break;
|
||||
case TimeModifierType.RotationChange:
|
||||
RotateBullet(modifier.Value);
|
||||
//Rotation += Mathf.DegToRad(modifier.Value);
|
||||
break;
|
||||
case TimeModifierType.FacePlayer:
|
||||
FacePlayer();
|
||||
break;
|
||||
}
|
||||
|
||||
modifier.Applied = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void RotateBullet(float degrees)
|
||||
{
|
||||
float radians = Mathf.DegToRad(degrees);
|
||||
_direction = _direction.Rotated(radians).Normalized(); // Rotate direction
|
||||
}
|
||||
|
||||
|
||||
private void FacePlayer()
|
||||
{
|
||||
// TODO: cache player
|
||||
var player = GetTree().GetFirstNodeInGroup("Player") as Node2D;
|
||||
if (player != null)
|
||||
{
|
||||
_direction = (player.GlobalPosition - this.GlobalPosition).Normalized();
|
||||
//LookAt(player.GlobalPosition);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//private void OnBodyEntered(Node body)
|
||||
//{
|
||||
|
|
@ -45,6 +98,12 @@ public partial class Bullet : Area2D
|
|||
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
_elapsedTime += delta;
|
||||
if (_bulletInfo != null)
|
||||
{
|
||||
ApplyTimeModifiers();
|
||||
}
|
||||
|
||||
this.Position += ((float)(Speed * delta) * _direction);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue