feat: Movement Box Boundaries
This commit is contained in:
		@@ -6,10 +6,12 @@ using Syntriax.Engine.Input;
 | 
			
		||||
 | 
			
		||||
namespace Pong.Behaviours;
 | 
			
		||||
 | 
			
		||||
public class MovementBoxBehaviour(Keys Up, Keys Down, float Speed) : BehaviourOverride
 | 
			
		||||
public class MovementBoxBehaviour(Keys Up, Keys Down, float High, float Low, float Speed) : BehaviourOverride
 | 
			
		||||
{
 | 
			
		||||
    private Keys Up { get; } = Up;
 | 
			
		||||
    private Keys Down { get; } = Down;
 | 
			
		||||
    public float High { get; } = High;
 | 
			
		||||
    public float Low { get; } = Low;
 | 
			
		||||
    public float Speed { get; set; } = Speed;
 | 
			
		||||
 | 
			
		||||
    private bool isUpPressed = false;
 | 
			
		||||
@@ -26,6 +28,8 @@ public class MovementBoxBehaviour(Keys Up, Keys Down, float Speed) : BehaviourOv
 | 
			
		||||
            GameObject.Transform.Position = GameObject.Transform.Position + Vector2.UnitY * (float)time.ElapsedGameTime.TotalSeconds * Speed;
 | 
			
		||||
        else if (isDownPressed)
 | 
			
		||||
            GameObject.Transform.Position = GameObject.Transform.Position + -Vector2.UnitY * (float)time.ElapsedGameTime.TotalSeconds * Speed;
 | 
			
		||||
 | 
			
		||||
        GameObject.Transform.Position = new Vector2(GameObject.Transform.Position.X, MathF.Max(MathF.Min(GameObject.Transform.Position.Y, High), Low));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected override void OnInitialize()
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System;
 | 
			
		||||
using Microsoft.Xna.Framework;
 | 
			
		||||
using Microsoft.Xna.Framework.Graphics;
 | 
			
		||||
using Microsoft.Xna.Framework.Input;
 | 
			
		||||
@@ -59,7 +59,7 @@ public class Game1 : Game
 | 
			
		||||
        gameObjectLeft.Transform.Position = new Vector2(-350f, 0f);
 | 
			
		||||
        gameObjectLeft.Transform.Scale = new Vector2(10f, 40f);
 | 
			
		||||
        gameObjectLeft.BehaviourController.AddBehaviour<KeyboardInputsBehaviour>();
 | 
			
		||||
        gameObjectLeft.BehaviourController.AddBehaviour<MovementBoxBehaviour>(Keys.W, Keys.S, 400f);
 | 
			
		||||
        gameObjectLeft.BehaviourController.AddBehaviour<MovementBoxBehaviour>(Keys.W, Keys.S, 268f, -268f, 400f);
 | 
			
		||||
        gameObjectLeft.BehaviourController.AddBehaviour<DisplayableSpriteBehaviour>().Assign(spriteBox);
 | 
			
		||||
 | 
			
		||||
        IGameObject gameObjectRight = gameManager.InstantiateGameObject<GameObject>();
 | 
			
		||||
@@ -67,7 +67,7 @@ public class Game1 : Game
 | 
			
		||||
        gameObjectRight.Transform.Position = new Vector2(350f, 0f);
 | 
			
		||||
        gameObjectRight.Transform.Scale = new Vector2(10f, 40f);
 | 
			
		||||
        gameObjectRight.BehaviourController.AddBehaviour<KeyboardInputsBehaviour>();
 | 
			
		||||
        gameObjectRight.BehaviourController.AddBehaviour<MovementBoxBehaviour>(Keys.Up, Keys.Down, 400f);
 | 
			
		||||
        gameObjectRight.BehaviourController.AddBehaviour<MovementBoxBehaviour>(Keys.Up, Keys.Down, 268f, -268f, 400f);
 | 
			
		||||
        gameObjectRight.BehaviourController.AddBehaviour<DisplayableSpriteBehaviour>().Assign(spriteBox);
 | 
			
		||||
        // TODO: use this.Content to load your game content here
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user