private void CreateCompositeButton(IEnumerable <IButtonAble> buttons, BaseMovable entityMover, Vector2 moveBy, MoverManager moverManager) { var smartButton = new CompositeSmartButton(buttons) { OnButtonJustPressed = (sender, args) => { ButtonsDown++; ToMove.Moving = PlayerMove; moverManager.RemoveMover(entityMover); MoveBy(moveBy, entityMover.Position); }, OnButtonHeldDown = (sender, args) => { ToMove.Moving = PlayerMove; MoveBy(moveBy, entityMover.Position); }, OnButtonReleased = (sender, args) => { ButtonsDown--; ToMove.Moving = PlayerMove; moverManager.RemoveMover(entityMover); Release(moveBy); } }; AddButton(smartButton); }
public DelayTracker(BaseMovable follower, BaseMovable following) { _follower = follower; _following = following; _cachedPosition = following.Position; _endPosition = following.Position; }
public override BaseMovableController CreateEntityController(BaseMovable entity, IPossibleMovements possibleMovements, MoverManager moverManager) { var directions = new Dictionary <BaseMovableController.Directions, List <IButtonAble> > { [BaseMovableController.Directions.Down] = new List <IButtonAble>(), [BaseMovableController.Directions.Up] = new List <IButtonAble>(), [BaseMovableController.Directions.Left] = new List <IButtonAble>(), [BaseMovableController.Directions.Right] = new List <IButtonAble>() }; if (ControllerSettings.GamePadEnabled) { directions[BaseMovableController.Directions.Down].Add(new JoyStickGamePadButton(Buttons.DPadDown)); directions[BaseMovableController.Directions.Left].Add(new JoyStickGamePadButton(Buttons.DPadLeft)); directions[BaseMovableController.Directions.Up].Add(new JoyStickGamePadButton(Buttons.DPadUp)); directions[BaseMovableController.Directions.Right].Add(new JoyStickGamePadButton(Buttons.DPadRight)); } if (ControllerSettings.KeyBoardMouseEnabled) { directions[BaseMovableController.Directions.Down].Add(new KeyButton(Keys.S)); directions[BaseMovableController.Directions.Down].Add(new KeyButton(Keys.Down)); directions[BaseMovableController.Directions.Left].Add(new KeyButton(Keys.A)); directions[BaseMovableController.Directions.Left].Add(new KeyButton(Keys.Left)); directions[BaseMovableController.Directions.Up].Add(new KeyButton(Keys.Up)); directions[BaseMovableController.Directions.Up].Add(new KeyButton(Keys.W)); directions[BaseMovableController.Directions.Right].Add(new KeyButton(Keys.D)); directions[BaseMovableController.Directions.Right].Add(new KeyButton(Keys.Right)); } return(new BaseMovableController(entity, possibleMovements, moverManager, directions)); }
public PathRenderer(MoverManager mover, BaseMovable moving, Texture2D texture, Texture2D endTexture, Point pointSize, int maxX, int maxY) : base(mover, moving) { _texture = texture; _endTexture = endTexture; _pointSize = pointSize; MaxX = maxX; MaxY = maxY; }
public BaseMovableController(BaseMovable baseMovable, IPossibleMovements possibleMovements, MoverManager moverManager, IReadOnlyDictionary <Directions, List <IButtonAble> > directionButtons) { _possibleMovements = possibleMovements; ToMove = baseMovable; SmartController = new SmartController(); CreateCompositeButton(directionButtons[Directions.Up], baseMovable, new Vector2(0, -1), moverManager); CreateCompositeButton(directionButtons[Directions.Down], baseMovable, new Vector2(0, 1), moverManager); CreateCompositeButton(directionButtons[Directions.Left], baseMovable, new Vector2(-1, 0), moverManager); CreateCompositeButton(directionButtons[Directions.Right], baseMovable, new Vector2(1, 0), moverManager); }
public void PathsFinderTestManhattanDistance() { var entity = new BaseMovable(); var endPoint = new Point(); var collisionSystem = new CompositeAbstractCollisionSystem(new EightWayPossibleMovement(new ManhattanDistance())); var tileSize = new Point(); var searchParams = new SearchParameters(entity.Position.ToPoint(), endPoint, collisionSystem, new Rectangle(new Point(), tileSize)); var path = new AStarPathFinder(searchParams, new EightWayPossibleMovement(new ManhattanDistance())); Assert.AreNotSame(path.ClosedNodes, path.MapNodes); }
public void TestMovement() { var expiringSpatialHash = new ExpiringSpatialHashCollisionSystem <BaseMovable>(new EightWayPossibleMovement(new CrowDistance())); var startPoint = new Point(3, 4); var endPoint = new Point(3, 5); var toMove = new BaseMovable { Position = startPoint.ToVector2() }; expiringSpatialHash.AddNode(startPoint, toMove); Assert.IsTrue(expiringSpatialHash.CheckCollision(startPoint)); Assert.IsFalse(expiringSpatialHash.CheckCollision(endPoint)); }
public override BaseMovableController CreateEntityController(BaseMovable moveable, IPossibleMovements possibleMovements, MoverManager moverManager) { var controller = base.CreateEntityController(moveable, possibleMovements, moverManager); var runningButton = new List <IButtonAble>(); AddKeyBoardButton(runningButton, Keys.LeftShift); AddKeyBoardButton(runningButton, Keys.RightShift); AddGamePadButton(runningButton, Buttons.B); var entity = moveable as Entity; if (entity != null) { var smartButton = new CompositeSmartButton(runningButton) { OnButtonJustPressed = (sender, args) => { entity.SpeedContext.SpeedState = new SpeedRunning(); }, OnButtonReleased = (sender, args) => { entity.SpeedContext.SpeedState = new SpeedNormal(); } }; controller.AddButton(smartButton); } return(controller); }
public static BaseMovableController AddEntityController(BaseMovable moveable, IPossibleMovements possibleMovements, MoverManager moverManager) { var controller = new EntityControllerFactory(); return(controller.CreateEntityController(moveable, possibleMovements, moverManager)); }
protected AbstractPathRenderer(MoverManager mover, BaseMovable moving) { Mover = mover; Moving = moving; }
public abstract BaseMovableController CreateEntityController(BaseMovable entity, IPossibleMovements possibleMovements, MoverManager moverManager);
public EndPointPathRenderer(MoverManager mover, BaseMovable moving, Texture2D endTexture, Point pointSize) : base(mover, moving) { _pointSize = pointSize; _endTexture = endTexture; }