public static async ValueTask <CharacterGame> Create(BECanvasComponent canvas, AnimationsSet animationsSet) { var warrior = new GameObject(); var animation = animationsSet.GetAnimation("Idle"); warrior.Components.Add(new Transform(warrior) { Position = Vector2.Zero, Direction = Vector2.One, Size = animation.FrameSize }); warrior.Components.Add(new AnimatedSpriteRenderComponent(warrior) { Animation = animation }); warrior.Components.Add(new CharacterBrain(animationsSet, warrior)); var game = new CharacterGame { _context = await canvas.CreateCanvas2DAsync(), _warrior = warrior }; return(game); }
public override async ValueTask Update(GameContext game) { var right = InputSystem.Instance.GetKeyState(Keys.Right); var left = InputSystem.Instance.GetKeyState(Keys.Left); if (right.State == ButtonState.States.Down) { _transform.Direction = Vector2.UnitX; _animationComponent.Animation = _animationsSet.GetAnimation("Run"); } else if (left.State == ButtonState.States.Down) { _transform.Direction = -Vector2.UnitX; _animationComponent.Animation = _animationsSet.GetAnimation("Run"); } else if (right.State == ButtonState.States.Up) { _animationComponent.Animation = _animationsSet.GetAnimation("Idle"); } else if (left.State == ButtonState.States.Up) { _animationComponent.Animation = _animationsSet.GetAnimation("Idle"); } }