mirror of
https://github.com/AlexMacocian/MonoGame.Extended.git
synced 2026-07-26 00:45:20 +00:00
very rough platformer demo
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using MonoGame.Extended.Entities;
|
||||
using Platformer.Components;
|
||||
|
||||
namespace Platformer.Systems
|
||||
{
|
||||
[Aspect(AspectType.All, typeof(VelocityComponent), typeof(PlayerComponent))]
|
||||
[EntitySystem(GameLoopType.Update, Layer = 0)]
|
||||
public class PlayerSystem : EntityProcessingSystem
|
||||
{
|
||||
private readonly KeyboardInputService _inputService;
|
||||
|
||||
public PlayerSystem(KeyboardInputService inputService)
|
||||
{
|
||||
_inputService = inputService;
|
||||
}
|
||||
|
||||
protected override void Process(GameTime gameTime, Entity entity)
|
||||
{
|
||||
var movement = entity.Get<VelocityComponent>();
|
||||
|
||||
movement.Velocity = new Vector2(0, movement.Velocity.Y);
|
||||
|
||||
if (_inputService.IsKeyDown(Keys.Left) || _inputService.IsKeyDown(Keys.A))
|
||||
movement.Velocity = new Vector2(-260, movement.Velocity.Y);
|
||||
|
||||
if (_inputService.IsKeyDown(Keys.Right) || _inputService.IsKeyDown(Keys.D))
|
||||
movement.Velocity = new Vector2(260, movement.Velocity.Y);
|
||||
|
||||
if (_inputService.IsKeyTapped(Keys.Up) || _inputService.IsKeyTapped(Keys.W))
|
||||
movement.Velocity = new Vector2(movement.Velocity.X, -600);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user