Пример #1
0
        public override void Step()
        {
            var fgTile = GetOverlappingTile(TileLayerEnum.Middle);

            if (fgTile != null)
            {
                // Check toggle loop
                if (_lastSwitchTick == World.GameTicks - 1 && _lastSwitchTile == fgTile)
                {
                    _lastSwitchTick = World.GameTicks;
                    return;
                }

                World.ToggleBarriersState(BarrierColor);

                // Update tick & tile
                _lastSwitchTick = World.GameTicks;
                _lastSwitchTile = fgTile;

                var n = GetNeighborAtDirection(fgTile.NextDirection);
                if (n?.CanBePassedThrough(fgTile, fgTile.NextDirection) != false)
                {
                    fgTile.MoveTowards(fgTile.NextDirection);
                }
                else
                {
                    fgTile.MoveTowards(TileUtils.GetInvertedDirection(fgTile.NextDirection));
                }
            }
        }
Пример #2
0
        public override void Step()
        {
            if (MoveState == State.Moving)
            {
                return;
            }

            Direction playerDirection = Direction.None;

            if (World.PlayerInput.Right.Pressed)
            {
                playerDirection = Direction.Right;
            }
            else if (World.PlayerInput.Left.Pressed)
            {
                playerDirection = Direction.Left;
            }
            else if (World.PlayerInput.Up.Pressed)
            {
                playerDirection = Direction.Up;
            }
            else if (World.PlayerInput.Down.Pressed)
            {
                playerDirection = Direction.Down;
            }

            if (World.PlayerInput.Explode.Pressed)
            {
                Explode();
                return;
            }

            if (playerDirection != Direction.None)
            {
                if (CanGoTowards(playerDirection))
                {
                    var neighbor = GetNeighborAtDirection(playerDirection);
                    if (neighbor?.CanBePicked() == true)
                    {
                        neighbor?.Pick();
                    }

                    if (!World.PlayerInput.Action.Pressed)
                    {
                        if (neighbor?.IsGate == true)
                        {
                            // Handle warp
                            WillWarpTo(neighbor, playerDirection);
                        }
                        else if (neighbor?.IsSwitch == true)
                        {
                            // Handle back
                            var n = neighbor.GetNeighborAtDirection(playerDirection);
                            if (n?.CanBePassedThrough(this, playerDirection) != false)
                            {
                                WillWarpTo(neighbor, playerDirection);
                            }
                            else
                            {
                                WillWarpTo(neighbor, TileUtils.GetInvertedDirection(playerDirection));
                            }
                        }
                        else
                        {
                            WillMoveTowards(playerDirection);
                        }
                    }
                }
                else if (CanPushTowards(playerDirection))
                {
                    var tile = GetNeighborAtDirection(playerDirection);
                    tile.PushTowards(playerDirection);

                    if (!World.PlayerInput.Action.Pressed)
                    {
                        WillMoveTowards(playerDirection);
                    }
                }
                else if (CanActionTowards(playerDirection))
                {
                    var tile = GetNeighborAtDirection(playerDirection);
                    tile.DoAction();
                }
            }
            else
            {
                Stop();
            }
        }