A Smoll game engine
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

40 lignes
1.6 KiB

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));
}
}
}
}