using Smoll;
|
|
using Raylib_cs;
|
|
using System.Numerics;
|
|
using Smoll.Ex1;
|
|
|
|
namespace Smoll.Ex2
|
|
{
|
|
class ExampleShootingInputComponent : Component {
|
|
Transform2DComponent? transform;
|
|
ArrowComponent? arrow;
|
|
|
|
public ExampleShootingInputComponent() {
|
|
}
|
|
|
|
public override void OnAttached()
|
|
{
|
|
base.OnAttached();
|
|
transform = owner.GetComponent<Transform2DComponent>();
|
|
arrow = owner.GetComponent<ArrowComponent>();
|
|
}
|
|
|
|
public override void Update(float deltaTimeSeconds)
|
|
{
|
|
transform ??= owner.GetComponent<Transform2DComponent>();
|
|
if(transform == null) throw new Exception("Example Input used on immovable object");
|
|
arrow ??= owner.GetComponent<ArrowComponent>();
|
|
if(arrow == null) throw new Exception("Example Shooter used on arrowless object");
|
|
if(Raylib.IsKeyPressed(KeyboardKey.Space)) {
|
|
var shoot = new Entity(owner.layers.First());
|
|
shoot.zOrder = -5;
|
|
var details = arrow.OriginAndVector();
|
|
var selfTransform = transform.AbsoluteTransform();
|
|
shoot.Attach(new Transform2DComponent((float)details.Item1.Real, (float)details.Item1.Imaginary, selfTransform.angle, selfTransform.scale));
|
|
shoot.Attach(new TimeToLiveComponent(4f));
|
|
shoot.Attach(new SpriteComponent("Beam.png"));
|
|
shoot.Attach(new InertiaComponent(1.0f, (float)details.Item2.Real, (float)details.Item2.Imaginary));
|
|
}
|
|
}
|
|
}
|
|
}
|