mirror of
https://github.com/AlexMacocian/MonoGame.Extended.git
synced 2026-07-24 03:56:31 +00:00
tweaks and bug fixes
This commit is contained in:
@@ -10,7 +10,8 @@ namespace Platformer.Components
|
||||
public enum State
|
||||
{
|
||||
Idle,
|
||||
Attacking,
|
||||
Kicking,
|
||||
Punching,
|
||||
Jumping,
|
||||
Falling,
|
||||
Walking,
|
||||
@@ -22,5 +23,7 @@ namespace Platformer.Components
|
||||
{
|
||||
public Facing Facing { get; set; } = Facing.Right;
|
||||
public State State { get; set; }
|
||||
public bool IsAttacking => State == State.Kicking || State == State.Punching;
|
||||
public bool CanJump => State == State.Idle || State == State.Walking;
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 2.3 KiB |
@@ -34,8 +34,9 @@ namespace Platformer
|
||||
animationFactory.Add("jump", new SpriteSheetAnimationData(new[] { 10, 12 }, frameDuration: 1.0f, isLooping: false));
|
||||
animationFactory.Add("fall", new SpriteSheetAnimationData(new[] { 13, 14 }, frameDuration: 1.0f, isLooping: false));
|
||||
animationFactory.Add("swim", new SpriteSheetAnimationData(new[] { 18, 19, 20, 21, 22, 23 }));
|
||||
animationFactory.Add("kick", new SpriteSheetAnimationData(new[] { 15 }, frameDuration: 0.5f, isLooping: false));
|
||||
animationFactory.Add("cool", new SpriteSheetAnimationData(new[] { 17 }, frameDuration: 0.5f, isLooping: false));
|
||||
animationFactory.Add("kick", new SpriteSheetAnimationData(new[] { 15 }, frameDuration: 0.3f, isLooping: false));
|
||||
animationFactory.Add("punch", new SpriteSheetAnimationData(new[] { 26 }, frameDuration: 0.3f, isLooping: false));
|
||||
animationFactory.Add("cool", new SpriteSheetAnimationData(new[] { 17 }, frameDuration: 0.3f, isLooping: false));
|
||||
entity.Attach(new AnimatedSprite(animationFactory, "idle"));
|
||||
entity.Attach(new Transform2(position, 0, Vector2.One * 4));
|
||||
entity.Attach(new Body { Position = position, Size = new Vector2(32, 64), BodyType = BodyType.Dynamic });
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using Autofac;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using MonoGame.Extended;
|
||||
using MonoGame.Extended.Entities;
|
||||
using MonoGame.Extended.Tiled;
|
||||
using MonoGame.Extended.Tiled.Renderers;
|
||||
using Platformer.Systems;
|
||||
@@ -12,6 +14,8 @@ namespace Platformer
|
||||
private TiledMap _map;
|
||||
private TiledMapRenderer _renderer;
|
||||
private EntityFactory _entityFactory;
|
||||
private OrthographicCamera _camera;
|
||||
private Entity _playerEntity;
|
||||
|
||||
public GameMain()
|
||||
{
|
||||
@@ -19,7 +23,10 @@ namespace Platformer
|
||||
|
||||
protected override void RegisterDependencies(ContainerBuilder builder)
|
||||
{
|
||||
_camera = new OrthographicCamera(GraphicsDevice);
|
||||
|
||||
builder.RegisterInstance(new SpriteBatch(GraphicsDevice));
|
||||
builder.RegisterInstance(_camera);
|
||||
builder.RegisterType<RenderSystem>();
|
||||
builder.RegisterType<PlayerSystem>();
|
||||
builder.RegisterType<WorldSystem>();
|
||||
@@ -28,7 +35,7 @@ namespace Platformer
|
||||
protected override void LoadContent()
|
||||
{
|
||||
_entityFactory = new EntityFactory(EntityComponentSystem.EntityManager, Content);
|
||||
_entityFactory.CreatePlayer(new Vector2(100, 240));
|
||||
_playerEntity = _entityFactory.CreatePlayer(new Vector2(100, 240));
|
||||
|
||||
// TOOD: Load maps and collision data more nicely :)
|
||||
_map = Content.Load<TiledMap>("test-map");
|
||||
@@ -63,13 +70,16 @@ namespace Platformer
|
||||
// Exit();
|
||||
|
||||
_renderer.Update(gameTime);
|
||||
//_camera.LookAt(_playerEntity.Get<Transform2>().Position);
|
||||
|
||||
base.Update(gameTime);
|
||||
}
|
||||
|
||||
protected override void Draw(GameTime gameTime)
|
||||
{
|
||||
_renderer.Draw();
|
||||
GraphicsDevice.Clear(Color.Black);
|
||||
|
||||
_renderer.Draw(_camera.GetViewMatrix());
|
||||
|
||||
base.Draw(gameTime);
|
||||
}
|
||||
|
||||
@@ -23,20 +23,16 @@ namespace Platformer.Systems
|
||||
var body = entity.Get<Body>();
|
||||
var keyboardState = KeyboardExtended.GetState();
|
||||
|
||||
if (keyboardState.WasKeyJustUp(Keys.Up))
|
||||
if (player.CanJump)
|
||||
{
|
||||
if (player.State != State.Jumping && player.State != State.Falling && player.State != State.Attacking)
|
||||
if(keyboardState.WasKeyJustUp(Keys.Up))
|
||||
body.Velocity.Y -= 550 + Math.Abs(body.Velocity.X) * 0.4f;
|
||||
|
||||
player.State = State.Jumping;
|
||||
}
|
||||
|
||||
if (keyboardState.WasKeyJustUp(Keys.Z))
|
||||
{
|
||||
if(player.State == State.Idle)
|
||||
if (keyboardState.WasKeyJustUp(Keys.Z))
|
||||
{
|
||||
body.Velocity.Y -= 550 + Math.Abs(body.Velocity.X) * 0.4f;
|
||||
|
||||
player.State = State.Attacking;
|
||||
player.State = player.State == State.Idle ? State.Punching : State.Kicking;
|
||||
}
|
||||
}
|
||||
|
||||
if (keyboardState.IsKeyDown(Keys.Right))
|
||||
@@ -51,18 +47,18 @@ namespace Platformer.Systems
|
||||
player.Facing = Facing.Left;
|
||||
}
|
||||
|
||||
if (body.Velocity.Y < 0)
|
||||
player.State = State.Jumping;
|
||||
|
||||
if (body.Velocity.Y > 0)
|
||||
player.State = State.Falling;
|
||||
|
||||
if (player.State != State.Attacking)
|
||||
if (!player.IsAttacking)
|
||||
{
|
||||
if (body.Velocity.X > 0 || body.Velocity.X < 0)
|
||||
player.State = State.Walking;
|
||||
|
||||
if (body.Velocity.Y < 0)
|
||||
player.State = State.Jumping;
|
||||
|
||||
if (body.Velocity.Y > 0)
|
||||
player.State = State.Falling;
|
||||
|
||||
if (body.Velocity.EqualsWithTolerence(Vector2.Zero, 5f))
|
||||
if (body.Velocity.EqualsWithTolerence(Vector2.Zero, 5))
|
||||
player.State = State.Idle;
|
||||
}
|
||||
|
||||
@@ -84,9 +80,12 @@ namespace Platformer.Systems
|
||||
case State.Idle:
|
||||
sprite.Play("idle");
|
||||
break;
|
||||
case State.Attacking:
|
||||
case State.Kicking:
|
||||
sprite.Play("kick", () => player.State = State.Idle);
|
||||
break;
|
||||
case State.Punching:
|
||||
sprite.Play("punch", () => player.State = State.Idle);
|
||||
break;
|
||||
case State.Cool:
|
||||
sprite.Play("cool");
|
||||
break;
|
||||
|
||||
@@ -12,15 +12,17 @@ namespace Platformer.Systems
|
||||
public class RenderSystem : EntityProcessingSystem
|
||||
{
|
||||
private readonly SpriteBatch _spriteBatch;
|
||||
private readonly OrthographicCamera _camera;
|
||||
|
||||
public RenderSystem(SpriteBatch spriteBatch)
|
||||
public RenderSystem(SpriteBatch spriteBatch, OrthographicCamera camera)
|
||||
{
|
||||
_spriteBatch = spriteBatch;
|
||||
_camera = camera;
|
||||
}
|
||||
|
||||
protected override void Begin(GameTime gameTime)
|
||||
{
|
||||
_spriteBatch.Begin(samplerState: SamplerState.PointClamp);
|
||||
_spriteBatch.Begin(samplerState: SamplerState.PointClamp, transformMatrix: _camera.GetViewMatrix());
|
||||
}
|
||||
|
||||
protected override void Process(GameTime gameTime, Entity entity)
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace MonoGame.Extended
|
||||
|
||||
public float Zoom
|
||||
{
|
||||
get { return _zoom; }
|
||||
get => _zoom;
|
||||
set
|
||||
{
|
||||
if ((value < MinimumZoom) || (value > MaximumZoom))
|
||||
@@ -47,7 +47,7 @@ namespace MonoGame.Extended
|
||||
|
||||
public float MinimumZoom
|
||||
{
|
||||
get { return _minimumZoom; }
|
||||
get => _minimumZoom;
|
||||
set
|
||||
{
|
||||
if (value < 0)
|
||||
@@ -62,7 +62,7 @@ namespace MonoGame.Extended
|
||||
|
||||
public float MaximumZoom
|
||||
{
|
||||
get { return _maximumZoom; }
|
||||
get => _maximumZoom;
|
||||
set
|
||||
{
|
||||
if (value < 0)
|
||||
|
||||
Reference in New Issue
Block a user