Esempio n. 1
0
    private void SetMovementPattern()
    {
        switch (currentMovementState)
        {
        case MovementState.Chase:
        {
            if (m_objectToChase.position.x > transform.position.x)
            {
                m_currentMovementDirection = MovementDirection.Right;
                m_rb.velocity = new Vector2(m_movementSpeed, m_rb.velocity.y);
            }
            else
            {
                m_currentMovementDirection = MovementDirection.Left;
                m_rb.velocity = new Vector2(-m_movementSpeed, m_rb.velocity.y);
            }
            m_currentMovementState = MovementState.Decide;
            break;
        }

        case MovementState.Move:
        {
            m_directionCounter--;
            if (m_directionCounter < 0 || m_actor.contacts.left || m_actor.contacts.right)
            {
                ChangeDirection();
            }
            if (currentMovementDirection == MovementDirection.Right)
            {
                m_rb.velocity = Vector2.right * m_movementSpeed + new Vector2(0, m_rb.velocity.y);
            }
            else
            {
                m_rb.velocity = Vector2.left * m_movementSpeed + new Vector2(0, m_rb.velocity.y);
            }
            m_currentMovementState = MovementState.Decide;
            break;
        }

        case MovementState.Jump:
        {
            m_rb.velocity          = Jump(m_jumpDirection);
            m_jumping              = true;
            m_directionCounter     = 200 + Random.Range(0, 200);   //vllt unnötig? oder besser wo anders?
            m_currentMovementState = MovementState.Decide;         //Falling
            break;
        }

        case MovementState.Falling:
        {
            //gegner bewegt sich mit seiner velcoity aus move weiter --> irgendwas dagegen tun
            if (m_actor.contacts.below)
            {         //&&CheckGroundBelow
                m_jumping = false;
                m_currentMovementState = MovementState.Decide;
            }
            break;
        }
        }
    }
Esempio n. 2
0
        public static bool DirectionAllowed(TileObject CurrentTile, MovementDirection direction, bool walkThroughGate)
        {
            // Check to see if we can move in the direction specified.
            try
            {
                switch (direction)
                {
                case MovementDirection.Up:
                    return(!(CurrentTile.TileUp.IsWall || (walkThroughGate ? false : CurrentTile.TileUp.IsGate)));

                case MovementDirection.Down:
                    return(!(CurrentTile.TileDown.IsWall || (walkThroughGate ? false : CurrentTile.TileDown.IsGate)));

                case MovementDirection.Left:
                    return(!(CurrentTile.TileLeft.IsWall || (walkThroughGate ? false : CurrentTile.TileLeft.IsGate)));

                case MovementDirection.Right:
                    return(!(CurrentTile.TileRight.IsWall || (walkThroughGate ? false : CurrentTile.TileRight.IsGate)));
                }
            }
            catch (Exception) // If we are here, then pacman or ghost is trying to warp to the other side of the map
            {
                return(true);
            }
            return(false);
        }
Esempio n. 3
0
        protected override void Move(MovementDirection direction)
        {
            MovementManager.Resolve(this, direction, out MovementManager.LastResolveResult);

            var x = (int)X;
            var y = (int)Y;

            switch (direction)
                {
                    case MovementDirection.Left:
                        x -= 16;
                        break;
                    case MovementDirection.Right:
                        x += 16;
                        break;
                    case MovementDirection.Up:
                        y -= 16;
                        break;
                    case MovementDirection.Down:
                        y += 16;
                        break;
                    default:
                        break;
                }

            if (MovementManager.LastResolveResult == MovementManager.ResolveResult.UnitBlocking)
            {
                Attack(UnitManager.GetUnitAtPosition(x, y));
                return;
            }
            base.Move(direction);
        }
Esempio n. 4
0
        public MovementDirection GetMove()
        {
            double[] annInputs = new double[6];

            for (int i = 0; i < sensors.Length; i++)
            {
                if (sensors[i] == Board.State.Food)
                {
                    annInputs[i] = 1;
                }
                else if (sensors[i] == Board.State.Poison)
                {
                    annInputs[i + 3] = 1;
                }
            }

            double[] res = ann.Run(annInputs);
            res = ann.Run(annInputs);
            res = ann.Run(annInputs);


            MovementDirection dir = GetBestMoveFromArray(res);

            dir = GetBestMoveFromArray(res);
            dir = GetBestMoveFromArray(res);

            return(GetBestMoveFromArray(res));
        }
Esempio n. 5
0
        /// <summary>
        /// Updates the players position on the board after moving.
        /// </summary>
        /// <param name="dir">Direction to move</param>
        public void Move(MovementDirection dir)
        {
            // Do nothing and die
            if (dir == MovementDirection.NONE)
            {
                return;
            }

            FacingDirection  nextFacingDirection = GetNewDirection(dir, facingDirection);
            Tuple <int, int> nextPos             = board.GetNextPosition(nextFacingDirection, position);

            // Remove the player from where we were before, i.e set it to FREE
            board.board[position.Item1, position.Item2] = Board.State.Free;

            // Update to new position
            position = nextPos;

            // Consume item at new position
            ConsumeItem(position);

            // Update direction
            facingDirection = nextFacingDirection;

            // Update position in board
            board.board[position.Item1, position.Item2] = Board.State.Player;

            UpdateSensors(position);
        }
Esempio n. 6
0
 private void seek()
 {
     if (!seeking)
     {
         return;
     }
     if ((DateTime.Now - startSeekTime).TotalMilliseconds < 600)
     {
         return;
     }
     if (pathIndex == path.Count)
     {
         if (target != null && !(target is Furniture))
         {
             move(seek(target), false);
         }
     }
     else
     {
         MovementDirection m = seek(path[pathIndex]);
         if (m != MovementDirection.none)
         {
             move(m, false);
         }
         else
         {
             pathIndex++;
         }
     }
     if ((target != null && !(target is Furniture) && isInRange(target)) || pathIndex == path.Count)
     {
         seeking = false;
         target  = null;
     }
 }
    private void PlayerMovement(MovementDirection direction)
    {
        int    x             = 0;
        int    y             = 0;
        string animationBool = "MovingLeft";

        if (direction == MovementDirection.Left)
        {
            x             = -1;
            animationBool = "MovingLeft";
        }
        else if (direction == MovementDirection.Right)
        {
            x             = 1;
            animationBool = "MovingRight";
        }

        if (direction == MovementDirection.Down)
        {
            y             = -1;
            animationBool = "MovingDown";
        }


        startTime   = Time.time;
        startMarker = new Vector2(transform.position.x, transform.position.y);
        endMarker   = new Vector2(transform.position.x + x, transform.position.y + y);
        movement    = true;
        LabyrinttiJonesAnimator.SetBool(animationBool, true);
        LabyrinttiJonesAnimator.SetInteger("LastMovementDirection", (int)direction);
        MovementHandling();
    }
Esempio n. 8
0
 private void MoveChosenComponent(MovementDirection movementDirection, float distance)
 {
     if (chosenCaliper != null)
     {
         chosenCaliper.MoveBarInDirection(movementDirection, distance, chosenComponent);
     }
 }
Esempio n. 9
0
 private void ResetResizer()
 {
     mouseDown   = false;
     mouseCorner = MovementDirection.None;
     this.Cursor = Cursors.Default;
     //Thread.Sleep(300);
 }
Esempio n. 10
0
    public void MoveCharacter(MovementDirection playerDirection)
    {
        if (Vector3.Distance(transform.position, movePoint.position) <= 1f)
        {
            switch (playerDirection)
            {
            case MovementDirection.up:
                movePoint.position += new Vector3(0f, 1, 0f);
                break;

            case MovementDirection.down:
                movePoint.position += new Vector3(0f, -1, 0f);
                break;

            case MovementDirection.left:
                movePoint.position += new Vector3(-1f, 0, 0f);
                break;

            case MovementDirection.right:
                movePoint.position += new Vector3(1f, 0, 0f);
                break;

            case MovementDirection.none:
                movePoint.position += new Vector3(1f, 0, 0f);
                break;

            default:
                break;
            }
        }
    }
Esempio n. 11
0
        /// <summary>
        /// Moves the block in the desired direction.
        /// </summary>
        /// <param name="direction">Direction the block should be moved in.</param>
        /// <returns>Returns true if block movement was succesful, false if not.</returns>
        public void MoveBlock(MovementDirection direction)
        {
            Point newPosition;

            switch (direction)
            {
            case MovementDirection.Left:
                newPosition = new Point(activeBlockPosition.X - 1, activeBlockPosition.Y);
                break;

            case MovementDirection.Right:
                newPosition = new Point(activeBlockPosition.X + 1, activeBlockPosition.Y);
                break;

            case MovementDirection.Down:
                newPosition = new Point(activeBlockPosition.X, activeBlockPosition.Y + 1);
                break;

            case MovementDirection.Up:
                newPosition = new Point(activeBlockPosition.X, activeBlockPosition.Y - 1);
                break;

            case MovementDirection.None:
                newPosition = activeBlockPosition;
                break;

            default:
                throw new NotImplementedException();
            }

            if (BlockPositionIsValid(activeBlock, newPosition))
            {
                activeBlockPosition = newPosition;
            }
        }
Esempio n. 12
0
        internal Tile NeighborInDirection(MovementDirection md)
        {
            var mm = MapManager.MapMgrSingleton;

            switch (md)
            {
            case MovementDirection.NONE:
                return(this);

            case MovementDirection.EAST:
                return(mm.GetTileAt(TileX + 1, TileY));

            case MovementDirection.NORTH:
                return(mm.GetTileAt(TileX, TileY - 1));

            case MovementDirection.WEST:
                return(mm.GetTileAt(TileX - 1, TileY));

            case MovementDirection.SOUTH:
                return(mm.GetTileAt(TileX, TileY + 1));

            default:
                return(null);
            }
        }
Esempio n. 13
0
        private void HandleMove(Pill pill, KeyCode pressedKey, MovementDirection movementDirection)
        {
            if (Input.GetKeyDown(pressedKey))
            {
                _keyIsDown[(int)movementDirection] = true;

                if (_board.CanMovePill(pill, movementDirection))
                {
                    _board.MovePill(pill, movementDirection);
                }
            }

            if (_keyIsDown[(int)movementDirection])
            {
                _timeSinceKeyDown[(int)movementDirection] += Time.unscaledDeltaTime;
            }

            if (_inputTime <= GameConstants.Input.Speed)
            {
                return;
            }

            if (!_keyIsDown[(int)movementDirection] || !(_timeSinceKeyDown[(int)movementDirection] > GameConstants.Input.KeyDownSpeed))
            {
                return;
            }

            if (_board.CanMovePill(pill, movementDirection))
            {
                _board.MovePill(pill, movementDirection);
            }
        }
Esempio n. 14
0
 public Movement(IInput input, Vector2 position, MovementAction action = MovementAction.IDLE, MovementDirection direction = MovementDirection.RIGHT)
 {
     _input    = input;
     Position  = position;
     Action    = action;
     Direction = direction;
 }
Esempio n. 15
0
 public void Stop()
 {
     this.isMoving = false;
     this.rightWheel.Disable();
     this.leftWheel.Disable();
     this.direction = MovementDirection.None;
 }
Esempio n. 16
0
        public void Move(MovementDirection movementDirection, GameTime gameTime,
                         out Vector2 change, out bool fullCycle)
        {
            if (Image == null)
            {
                throw new InvalidOperationException("Image wasn't loaded");
            }

            switch (movementDirection)
            {
            case MovementDirection.Down:
                Fall(gameTime, out change, out fullCycle);
                break;

            case MovementDirection.Up:
                MoveUp(gameTime, out change, out fullCycle);
                break;

            case MovementDirection.Right:
                MoveRight(gameTime, out change, out fullCycle);
                break;

            case MovementDirection.Left:
                MoveLeft(gameTime, out change, out fullCycle);
                break;

            default:
                change    = new Vector2(0, 0);
                fullCycle = false;
                break;
            }
        }
Esempio n. 17
0
    private static Vector2 movementToVector(MovementDirection movement, Thalmic.Myo.Arm conductingArm)
    {
        if (conductingArm == Thalmic.Myo.Arm.Unknown)
        {
            return(Vector2.zero);
        }

        switch (movement)
        {
        case MovementDirection.DOWN:
            return(Vector2.down);

        case MovementDirection.INWARDS:
            return((conductingArm == Thalmic.Myo.Arm.Right) ? Vector2.left : Vector2.right);

        case MovementDirection.OUTWARDS:
            return((conductingArm == Thalmic.Myo.Arm.Right) ? Vector2.right : Vector2.left);

        case MovementDirection.UP:
            return(Vector2.up);

        default:
            return(Vector2.zero);
        }
    }
Esempio n. 18
0
        public void MoveTetromino(MovementDirection direction)
        {
            if (this.fallingTetromino != null && this.gameState == GameState.Running)
            {
                var movingContext = TetrominoMover.GetMoveContext(fallingTetromino, direction, movementSpeed);
                if (!CollisionDetector.CollisionDetected(this.fallingTetromino, this.playfieldInfo.FieldMatrix, movingContext.Positions))
                {
                    TetrominoMover.Move(this.fallingTetromino, this.playfieldInfo.FieldMatrix, movingContext);
                    this.renderer.RenderGameField();
                }
                else
                {
                    if (direction == MovementDirection.Down)
                    {
                        int clearedRowsCount = this.playfieldInfo.ClearFullRows();

                        this.ClearedLinesCount += clearedRowsCount;
                        if (this.clearedLinesCount >= ((this.currentLevel * 10) + 10))
                        {
                            this.CurrentLevel++;

                            int currentTimerInterval = this.frameRenderTimer.Interval.Milliseconds;
                            this.frameRenderTimer.Interval = TimeSpan.FromMilliseconds(currentTimerInterval - 50);
                        }


                        this.AddToScore(ScoringSystem.GetScore(this.currentLevel, clearedRowsCount));
                        this.renderer.RenderGameField();
                        this.DropNewTetromino();
                    }
                }
            }
        }
 public void UpdateMovementDirection(float angleFromSightPosition)
 {
     if (_playerControl.inputs != Vector3.zero)
     {
         if (angleFromSightPosition < _angleContraintForForwardWalking && angleFromSightPosition > -_angleContraintForForwardWalking)
         {
             movementDirection = MovementDirection.FORWARD;
         }
         else if (angleFromSightPosition >= _angleConstraintForBackwardWalking)
         {
             movementDirection = MovementDirection.BACKWARD;
         }
         else if (Mathf.Abs(angleFromSightPosition) > _angleContraintForForwardWalking && angleFromSightPosition < 0)
         {
             movementDirection = MovementDirection.LEFT;
         }
         else if (Mathf.Abs(angleFromSightPosition) > _angleContraintForForwardWalking && angleFromSightPosition > 0)
         {
             movementDirection = MovementDirection.RIGHT;
         }
     }
     else if (_playerControl.inputs == Vector3.zero)
     {
         movementDirection = MovementDirection.IDLE;
     }
 }
Esempio n. 20
0
    public void MoveMinion(MovementDirection direction)
    {
        int xDir = 0, yDir = 0;

        switch (direction)
        {
        case MovementDirection.UP:
            yDir = 1;
            break;

        case MovementDirection.DOWN:
            yDir = -1;
            break;

        case MovementDirection.RIGHT:
            xDir = 1;
            break;

        case MovementDirection.LEFT:
            xDir = -1;
            break;
        }

        AttemptMove(xDir, yDir);
    }
Esempio n. 21
0
 internal void UpdateMovementDirection(MovementDirection movementDirection)
 {
     if (Snake != null)
     {
         Snake.UpdateMovementDirection(movementDirection);
     }
 }
Esempio n. 22
0
        public static string GetTileEdgeKey(IList <string> tileDefinition, MovementDirection edge)
        {
            if (tileDefinition == null || tileDefinition.Count == 0)
            {
                return(string.Empty);
            }

            if (MovementDirection.Up.Equals(edge))
            {
                return(tileDefinition[0]);
            }
            else if (MovementDirection.Down.Equals(edge))
            {
                return(tileDefinition[tileDefinition.Count - 1]);
            }
            else if (MovementDirection.Left.Equals(edge))
            {
                var result = new StringBuilder();
                for (int i = 0; i < tileDefinition.Count; i++)
                {
                    result.Append(tileDefinition[i][0]);
                }
                return(result.ToString());
            }
            else if (MovementDirection.Right.Equals(edge))
            {
                var result = new StringBuilder();
                for (int i = 0; i < tileDefinition.Count; i++)
                {
                    result.Append(tileDefinition[i][^ 1]);
Esempio n. 23
0
    private void Jump()
    {
        m_RigidBody2D.AddForce(transform.up * jumpForce, ForceMode2D.Impulse);
        currMoveSpdInAir = currMovementSpd;

        currMovementDir = MovementDirection.NEUTRAL;
    }
Esempio n. 24
0
 public CashMovement(decimal amount, DateTime issueDate, string executor, MovementDirection type)
 {
     IssueDate = issueDate;
     Executor  = executor;
     Amount    = amount;
     Type      = type;
 }
Esempio n. 25
0
        private static void ChangeDirection(MovementDirection direction)
        {
            // First, center pacman back on the tile
            Position         = CurrentTile.Position;
            distanceTraveled = 0.0f;

            currentDirection = direction;
            switch (direction)
            {
            case MovementDirection.Up:
                rotation = (float)Math.Atan2(0, 1);
                break;

            case MovementDirection.Down:
                rotation = (float)Math.Atan2(0, -1);
                break;

            case MovementDirection.Left:
                rotation = (float)Math.Atan2(-1, 0);
                break;

            case MovementDirection.Right:
                rotation = (float)Math.Atan2(1, 0);
                break;
            }
        }
Esempio n. 26
0
        public bool TryMove(MovementDirection direction)
        {
            bool moved;
            switch (direction)
            {
                case MovementDirection.Up:
                    moved = TryMove(currentPosition.Up);
                    break;
                case MovementDirection.Down:
                    moved = TryMove(currentPosition.Down);
                    break;
                case MovementDirection.Left:
                    moved = TryMove(currentPosition.Left);
                    break;
                case MovementDirection.Right:
                    moved = TryMove(currentPosition.Right);
                    break;
                default:
                    throw new ArgumentOutOfRangeException("direction");
            }

            if (moved)
            {
                LastMove = direction;
            }

            return moved;
        }
Esempio n. 27
0
        public bool OnMove(MovementDirection md, int val)
        {
            Vector3 p = Transform.position;
            Vector3 newPos;

            if (md == MovementDirection.HORIZONTAL)
            {
                newPos   = new Vector3(p.x + val, p.y, p.z);
                LastMove = new Vector3(val, 0, 0);
            }
            else if (md == MovementDirection.VERTICAL)
            {
                newPos   = new Vector3(p.x, p.y + val, p.z);
                LastMove = new Vector3(0, val, 0);
            }
            else
            {
                return(false);
            }
            if (CanMove(newPos))
            {
                return(false);
            }

            PreviousPosition   = Transform.position;
            Transform.position = newPos;

            SpriteRenderer.flipX = val == 1;
            if (reFlip)
            {
                SpriteRenderer.flipX = !SpriteRenderer.flipX;
            }
            return(true);
        }
Esempio n. 28
0
        public static void GetDeltaPixelsFromDirection(MovementDirection d, out int dx, out int dy)
        {
            switch (d)
            {
            case MovementDirection.EAST:
                dx = 8;
                dy = 0;
                break;

            case MovementDirection.NORTH:
                dx = 0;
                dy = 8;
                break;

            case MovementDirection.WEST:
                dx = -8;
                dy = 0;
                break;

            case MovementDirection.SOUTH:
                dx = 0;
                dy = -8;
                break;

            default:
                dx = 0;
                dy = 0;
                break;
            }
        }
Esempio n. 29
0
        public void Move(MovementDirection direction)
        {
            this.isMoving  = true;
            this.direction = direction;

            switch (direction)
            {
            case MovementDirection.None:
                Stop();
                break;

            case MovementDirection.Forward:
                this.rightWheel.Enable(Wheel.Direction.Forward);
                this.leftWheel.Enable(Wheel.Direction.Forward);
                break;

            case MovementDirection.Backward:
                this.rightWheel.Enable(Wheel.Direction.Reverse);
                this.leftWheel.Enable(Wheel.Direction.Reverse);
                break;

            case MovementDirection.Left:
                this.rightWheel.Enable(Wheel.Direction.Forward);
                this.leftWheel.Enable(Wheel.Direction.Reverse);
                break;

            case MovementDirection.Right:
                this.rightWheel.Enable(Wheel.Direction.Reverse);
                this.leftWheel.Enable(Wheel.Direction.Forward);
                break;
            }
        }
Esempio n. 30
0
        public override void MoveBarInDirection(MovementDirection movementDirection, float distance, CaliperComponent component)
        {
            CaliperComponent adjustedComponent = MoveCrossbarInsteadOfSideBar(movementDirection, component) ? CaliperComponent.Apex : component;

            if (adjustedComponent == CaliperComponent.Apex)
            {
                base.MoveBarInDirection(movementDirection, distance, CaliperComponent.CrossBar);
            }
            // TODO: test this
            // We use smaller increments for angle calipers, otherwise movement is too large.
            distance = distance / 2.0f;
            if (movementDirection == MovementDirection.Left)
            {
                distance = -distance;
            }
            switch (adjustedComponent)
            {
            case CaliperComponent.LeftBar:
                angleBar1 -= (float)(DegreesToRadians(distance));
                break;

            case CaliperComponent.RightBar:
                angleBar2 -= (float)(DegreesToRadians(distance));
                break;

            default:
                break;
            }
        }
Esempio n. 31
0
        /// <summary>
        /// Moves the entity. using the character controller attached to it.
        /// this DOES NOT involve pathfinding / navigation in any way
        /// </summary>
        /// <param name="Direction">Direction to move entity in</param>
        /// <param name="Speed">Speed (meters per second)</param>
        private void MoveEntity(MovementDirection Direction)
        {
            switch (Direction)
            {
            case MovementDirection.Left:
            {
                if (Sprinting)
                {
                    Controller.SimpleMove(Directions.Left * SprintSpeed);
                }
                else
                {
                    Controller.SimpleMove(Directions.Left * Speed);
                }

                break;
            }

            case MovementDirection.Right:
            {
                if (Sprinting)
                {
                    Controller.SimpleMove(Directions.Right * SprintSpeed);
                }
                else
                {
                    Controller.SimpleMove(Directions.Right * Speed);
                }

                break;
            }

            case MovementDirection.Foreward:
            {
                if (Sprinting)
                {
                    Controller.SimpleMove(Directions.Foreward * SprintSpeed);
                }
                else
                {
                    Controller.SimpleMove(Directions.Foreward * Speed);
                }

                break;
            }

            case MovementDirection.Backward:
            {
                if (Sprinting)
                {
                    Controller.SimpleMove(Directions.Backward * SprintSpeed);
                }
                else
                {
                    Controller.SimpleMove(Directions.Backward * Speed);
                }
                break;
            }
            }
        }
Esempio n. 32
0
        public static FerryMovementDirection GetHeadingFromMovementDirection(MovementDirection direction)
        {
            FerryMovementDirection heading;

            if (MovementDirection.Right.Equals(direction))
            {
                heading = FerryMovementDirection.East;
            }
            else if (MovementDirection.Up.Equals(direction))
            {
                heading = FerryMovementDirection.North;
            }
            else if (MovementDirection.Left.Equals(direction))
            {
                heading = FerryMovementDirection.West;
            }
            else if (MovementDirection.Down.Equals(direction))
            {
                heading = FerryMovementDirection.South;
            }
            else
            {
                throw new Exception($"Invalid direction: {direction}");
            }
            return(heading);
        }
Esempio n. 33
0
 /// <summary>
 /// Constructor
 /// </summary>
 public Sokoban(View.GameDeskView form, Player player, int objectID, string description,
                   int pozX, int pozY, MovementDirection direction, EventType InitialEvent, int speed)
     : base(form, player, objectID, description, pozX, pozY, direction, InitialEvent, speed)
 {
     isDeathAnimationStarted = false;
     sokobanState = SokobanState.alive;
     stepsNo = 0;
 }
Esempio n. 34
0
 void OrderMove(MovementDirection direction)
 {
     var scene = Scene as GameScene;
     scene.Hero.IssueOrder(UnitOrder.Move, direction);
     UnitManager.ProceedTurn();
     if (scene.Hero.X == scene.Exit.X && scene.Hero.Y == scene.Exit.Y)
         scene.GenerateNew();
 }
Esempio n. 35
0
        private static void HandleMovementDir(ref Point coordinate, MovementDirection state)
        {
            switch (state)
            {
                case MovementDirection.Down:
                    {
                        coordinate.Y++;
                        break;
                    }

                case MovementDirection.Up:
                    {
                        coordinate.Y--;
                        break;
                    }

                case MovementDirection.Left:
                    {
                        coordinate.X--;
                        break;
                    }

                case MovementDirection.Right:
                    {
                        coordinate.X++;
                        break;
                    }

                case MovementDirection.DownRight:
                    {
                        coordinate.X++;
                        coordinate.Y++;
                        break;
                    }

                case MovementDirection.DownLeft:
                    {
                        coordinate.X--;
                        coordinate.Y++;
                        break;
                    }

                case MovementDirection.UpRight:
                    {
                        coordinate.X++;
                        coordinate.Y--;
                        break;
                    }

                case MovementDirection.UpLeft:
                    {
                        coordinate.X--;
                        coordinate.Y--;
                        break;
                    }
            }
        }
Esempio n. 36
0
        public BlockMovement(IGameBlockParent sourceBlock, MovementDirection direction)
        {
            this.sourceBlock = sourceBlock;
            this.destinationBlock = null;
            this.direction = direction;
            this.intermediateBlocks = new List<IGameBlockDestination>();

            this.originalAvailableMoves = sourceBlock == null ? 0 : sourceBlock.AvailableMoves;
        }
Esempio n. 37
0
 public LogEvent(GameObject obj, int posX, int posY, MovementDirection movementDirection, string time, bool importantEvent)
 {
     Obj = obj;
     PosX = posX;
     PosY = posY;
     Time = time;
     MovementDirection = movementDirection;
     ImportantEvent = importantEvent;
 }
Esempio n. 38
0
	    private void MoveDesk(MovementDirection direction, int movementDuration)
	    {
		    var commandString = direction.ToString();

		    if (movementDuration > 0)
			    commandString += " " + movementDuration;

		    var command = Encoding.UTF8.GetBytes(commandString);

		    _deskSocket.Send(command);
	    }
Esempio n. 39
0
        public PID(float Input, float Output, float Setpoint, float Kp, float Ki, float Kd, MovementDirection Direction)
        {
            this.Input = Input;
            this.Output = Output;
            this.Setpoint = Setpoint;
            this.Kp = Kp;
            this.Ki = Ki;
            this.Kd = Kd;
            this.Direction = Direction;

            Initialize();
        }
Esempio n. 40
0
 private byte[] ToByte(MovementDirection direction)
 {
     switch (direction)
     {
         case MovementDirection.Up:
             return new[] { (byte)'u' };
         case MovementDirection.Down:
             return new[] { (byte)'d' };
         case MovementDirection.Left:
             return new[] { (byte)'l' };
         case MovementDirection.Right:
             return new[] { (byte)'r' };
         default:
             throw new ArgumentOutOfRangeException("direction");
     }
 }
Esempio n. 41
0
 private static MovementDirection Reverse(MovementDirection direction)
 {
     switch (direction)
     {
         case MovementDirection.Up:
             return MovementDirection.Down;
         case MovementDirection.Down:
             return MovementDirection.Up;
         case MovementDirection.Left:
             return MovementDirection.Right;
         case MovementDirection.Right:
             return MovementDirection.Left;
         default:
             throw new ArgumentOutOfRangeException("direction");
     }
 }
Esempio n. 42
0
        /// <summary>
        /// Moves GameObject on game desk
        /// </summary>
        /// <param name="whereTo">which direction should GameObject move </param>
        public void MakeMove(MovementDirection whereTo)
        {
            movementStopWatch = Stopwatch.StartNew();
            lastPosX = posX;
            lastPosY = posY;

            if (whereTo == MovementDirection.goLeft)
            {
                posX--;
            }
            else if (whereTo == MovementDirection.goRight)
            {
                posX++;
            }
            else if (whereTo == MovementDirection.goUp)
            {
                posY--;
            }
            else if (whereTo == MovementDirection.goDown)
            {
                posY++;
            }

            if (form.cbRecord.Checked == true)
            {
                string name;
                bool importantEvent = false;

                if (this.Description == "S")
                {
                    name = this.Description;
                    importantEvent = true;
                }
                else
                {
                    name = this.Description + this.objectID.ToString();
                }

                player.gameDesk.logList.AddEvent(this, this.posX, this.posY, form.lTime.Text, whereTo, importantEvent);
            }
        }
Esempio n. 43
0
        // Add a point to the end of the path in the direction specified.
        public void AddPoint(MovementDirection directionOfPoint)
        {
            Point lastPoint = this.nodes[this.nodes.Count - 1];

            if (directionOfPoint == MovementDirection.Left)
            {
                this.nodes.Add(new Point(lastPoint.x - 1, lastPoint.y));
            }
            else if (directionOfPoint == MovementDirection.Right)
            {
                this.nodes.Add(new Point(lastPoint.x + 1, lastPoint.y));
            }
            else if (directionOfPoint == MovementDirection.Down)
            {
                this.nodes.Add(new Point(lastPoint.x, lastPoint.y - 1));
            }
            else if (directionOfPoint == MovementDirection.Up)
            {
                this.nodes.Add(new Point(lastPoint.x, lastPoint.y + 1));
            }
        }
Esempio n. 44
0
        public void ForceMove(MovementDirection direction)
        {
            switch (direction)
            {
                case MovementDirection.Up:
                    ForceMove(currentPosition.Up);
                    break;
                case MovementDirection.Down:
                    ForceMove(currentPosition.Down);
                    break;
                case MovementDirection.Left:
                    ForceMove(currentPosition.Left);
                    break;
                case MovementDirection.Right:
                    ForceMove(currentPosition.Right);
                    break;
                default:
                    throw new ArgumentOutOfRangeException("direction");
            }

            LastMove = direction;
        }
Esempio n. 45
0
    void InputDrag(Vector3 touchedPosition)
    {
        if (_trackedTile == null)
            return;

        _trackedTile.layer = Physics2D.IgnoreRaycastLayer;

        //only change position if input movement is beyond a set threshold
        var threshold = new Vector3(0.15f, 0.15f, 0);
        var offSetX = Math.Abs(touchedPosition.x - _inputStartPosition.x);
        var offSetY = Math.Abs(touchedPosition.y - _inputStartPosition.y);

        if (!_isDragging && offSetY > threshold.y)
            _movementDirection = MovementDirection.Vertical;
        if (!_isDragging && offSetX > threshold.x)
            _movementDirection = MovementDirection.Horizontal;

        if (_movementDirection != MovementDirection.None)
            MoveInTouchedDirection(touchedPosition);

        _inputLastKnownPosition = touchedPosition;
    }
Esempio n. 46
0
    void Update()
    {
        //Checks if the rigidbody is awake
        if (!transform.rigidbody.IsSleeping() && transform.rigidbody.isKinematic == true)
        {
            transform.rigidbody.isKinematic = false;
            //sets movement vector
            Vector3 movementVect = transform.position - startVect;
            //Debug.Log("Movement Vect: " + movementVect);

            //checks which direction object is moving
            if (movementVect.x > movementCheck)
            {
                XMovementDirection = MovementDirection.Right;
            }
            if (movementVect.x < -movementCheck)
            {
                XMovementDirection = MovementDirection.Left;
            }
            if (movementVect.y > movementCheck)
            {
                ZMovementDirection = MovementDirection.Up;
            }
            if (movementVect.y < -movementCheck)
            {
                ZMovementDirection = MovementDirection.Down;
            }
        }
        else
        {
            //Reset values
            transform.rigidbody.isKinematic = true;
            startVect = transform.position;
            XMovementDirection = MovementDirection.None;
            ZMovementDirection = MovementDirection.None;
        }
    }
Esempio n. 47
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="ID">Unique number for GameObject</param>
        /// <param name="description">See "description" member of GameObject</param>
        /// <param name="pozX">See "pozX" member of GameObject</param>
        /// <param name="pozY">See "pozY" member of GameObject</param>
        /// <param name="direction">See "direction" member of GameObject</param>
        /// <param name="InitialEvent">First event of GameObject</param>
        /// <param name="speed">Speed of GameObject - typically for monsters</param>
        public GameObject(int ID, string description, int posX, int posY, MovementDirection direction, int speed)
        {
            this.ID = ID;
            this.Speed = speed;
            this.posX = posX;
            this.posY = posY;
            this.lastPosX = posX;
            this.lastPosY = posY;
            this.Description = description;

            UI = new GameObjectUI();
            UI.Direction = direction;
            UI.LastMovementEvent = EventType.none;
            UI.MovementNumberOfFields = 0;

            UI.Image = new System.Windows.Controls.Image();

            BitmapImage bi = new BitmapImage();
            bi.BeginInit();

            bi.UriSource = new Uri("pack://application:,,,/GameDocs;component/Resources/StaticObj/obj_" + this.Description + ".png");
            bi.EndInit();
            UI.Image.Source = bi;
        }
Esempio n. 48
0
 public static int CoordinationOfMovementDirectionY(int posY, MovementDirection movementDirection)
 {
     return posY + moves[(-1 + (int)movementDirection) * 2 + 1];
 }
Esempio n. 49
0
        protected virtual void Move(MovementDirection direction)
        {
            var CanMove = MovementManager.Resolve(this, direction, out MovementManager.LastResolveResult);

            if (CanMove || IgnorePaths)
            {
                MovementManager.RemapUnitToUnitMap(this, direction);
                switch (direction)
                {
                    case MovementDirection.Left:
                        X -= 16;
                        break;
                    case MovementDirection.Right:
                        X += 16;
                        break;
                    case MovementDirection.Up:
                        Y -= 16;
                        break;
                    case MovementDirection.Down:
                        Y += 16;
                        break;
                    default:
                        break;
                }
            }
        }
Esempio n. 50
0
 // Use this for initialization
 void Start()
 {
     blood = GameObjectHelper.findChildBySubstringInName(gameObject, "blood");
     direction = GetComponent<MovementDirection>();
     player = GetComponent<Player>();
 }
Esempio n. 51
0
        /// <summary>
        /// Moves GameObject on game desk
        /// </summary>
        /// <param name="whereTo">which direction should GameObject move</param>
        public void InitializeMove(MovementDirection whereTo)
        {
            lastPosX = posX;
            lastPosY = posY;
            newPosX = posX;
            newPosY = posY;
            char direction = ' ';

            if (whereTo == MovementDirection.goLeft)
            {
                newPosX = posX - 1;
                direction = 'l';
            }
            else if (whereTo == MovementDirection.goRight)
            {
                newPosX = posX + 1;
                direction = 'r';
            }
            else if (whereTo == MovementDirection.goUp)
            {
                newPosY = posY - 1;
                direction = 'u';
            }
            else if (whereTo == MovementDirection.goDown)
            {
                newPosY = posY + 1;
                direction = 'd';
            }
                       
            if (this.immediatelyOccupyNewField == true)
            {
                StepsCount++;
                lastPositionChange = DateTime.Now;

                // Fire event
                if (ElementMoved != null)
                {
                    ElementMoved(posX, posY, direction);
                }
            }
        }
Esempio n. 52
0
 public static int CoordinationOfMovementDirectionX(int posX, MovementDirection movementDirection)
 {
     return posX + moves[(-1 + (int)movementDirection) * 2];
 }
Esempio n. 53
0
 /// <summary>
 /// Creates a new MovementInstruction
 /// </summary>
 /// <param name="direction">The direction of movement.</param>
 /// <param name="distance">The distance to move in milimeters.</param>
 public MovementInstruction(MovementDirection direction, double distance)
     : this()
 {
     this.Direction = direction;
     this.Distance = distance;
 }
Esempio n. 54
0
        public override bool ApplyReverseMoveForLoop(
            IGameBlockDestination destinationBlock,
            MovementDirection directionInReverse,
            int numberOfBlocksToMove,
            out BlockMovement move,
            IGameBlock previousBlock,
            IGameBlockDestination previousDestination,
            Queue<IGameBlock> blockHistory)
        {
            move = null;

            // Starting with a non-filled block isn't valid
            if (destinationBlock != null && this.numberOfMovesApplied == 0)
            {
                return false;
            }

            // If this is the destination
            bool thisIsFinalMove = destinationBlock == null;
            int availableBlocksToUse = this.CountUsedBlocks(directionInReverse, new Dictionary<IGameBlock, IGameBlock>());

            // See if there are enough blocks to do this move
            if (thisIsFinalMove && availableBlocksToUse < numberOfBlocksToMove)
            {
                return false;
            }

            // Use this block as the destination block if destinationBlock is null
            IGameBlockDestination destination = destinationBlock ?? this;

            blockHistory.Enqueue(this);

            bool moveApplied;
            switch (directionInReverse)
            {
                default:
                case MovementDirection.Up:
                    if (this.Top == null)
                    {
                        moveApplied = false;
                    }
                    else
                    {
                        moveApplied = this.Top.ApplyReverseMoveForLoop(
                            destination, directionInReverse, numberOfBlocksToMove, out move, this, this, blockHistory);
                    }
                    break;

                case MovementDirection.Down:
                    if (this.Bottom == null)
                    {
                        moveApplied = false;
                    }
                    else
                    {
                        moveApplied = this.Bottom.ApplyReverseMoveForLoop(
                            destination, directionInReverse, numberOfBlocksToMove, out move, this, this, blockHistory);
                    }
                    break;

                case MovementDirection.Left:
                    if (this.Left == null)
                    {
                        moveApplied = false;
                    }
                    else
                    {
                        moveApplied = this.Left.ApplyReverseMoveForLoop(
                            destination, directionInReverse, numberOfBlocksToMove, out move, this, this, blockHistory);
                    }
                    break;

                case MovementDirection.Right:
                    if (this.Right == null)
                    {
                        moveApplied = false;
                    }
                    else
                    {
                        moveApplied = this.Right.ApplyReverseMoveForLoop(
                            destination, directionInReverse, numberOfBlocksToMove, out move, this, this, blockHistory);
                    }
                    break;
            }

            if (moveApplied && !this.IsFullyAvailable && move != null)
            {
                this.SetAvailability(true);
                move.InsertDestinationBlock(this);
                move.SourceBlock.AvailableMoves++;
            }

            return moveApplied;
        }
Esempio n. 55
0
    void updatePosition()
    {
        float axisHorizontal;
        float axisVertical;
        if (GameProperties.IsTactil())
        {
            Vector2 joystickInput = this.moveJoystick.position;
            axisHorizontal = (Mathf.Abs(joystickInput.x) > 0.3f ? joystickInput.x*0.9f : 0.0f);
            axisVertical = (Mathf.Abs(joystickInput.y) > 0.3f ? joystickInput.y*0.65f : 0.0f);
        } else
        {
            axisHorizontal = Input.GetAxis("Horizontal");
            axisVertical = Input.GetAxis("Vertical");
        }

        if (axisVertical > 0.001f && Time.deltaTime > 0.0f)
        {
            this.movingDirection = MovementDirection.kMovementForwards;
        } else if (axisVertical < -0.001f && Time.deltaTime > 0.0f)
        {
            this.movingDirection = MovementDirection.kMovementBackwards;
        } else
        {
            this.movingDirection = MovementDirection.kMovementStopped;
        }

        float horizontal = axisHorizontal * turningSpeed * Time.deltaTime;
        this.transform.Rotate(0, horizontal, 0);
        float vertical = axisVertical * movementSpeed * Time.deltaTime;
        this.transform.Translate(0, 0, vertical);

        if (GameProperties.editMode != EditMode.kEditModePrefabs)
        {
            float currY = this.transform.position.y;
            float finalY = (this.currFloor.transform.position.y + this.currFloor.transform.localScale.y * 0.5f + this.transform.localScale.y * 0.5f);

            float nextY;
            if (finalY > currY)
            {
                nextY = finalY;
            } else
            {
                nextY = Mathf.Lerp(currY, finalY, 0.15f);
            }

            Vector3 position = this.transform.position;
            position.y = nextY;
            this.transform.position = position;
        }
    }
Esempio n. 56
0
        private void CheckDirectionalMovementAndUpdateActiveButton(InputProcessorBase inputSource, int millisecondsSinceLastUpdate)
        {
            _millisecondsSinceLastMovement = Math.Min(_millisecondsSinceLastMovement + millisecondsSinceLastUpdate, Movement_Repeat_Time_In_Milliseconds);

            MovementDirection direction = MovementDirection.None;
            if (inputSource.MoveUp) { direction = MovementDirection.Up; }
            else if (inputSource.MoveDown) { direction = MovementDirection.Down; }
            else if (inputSource.MoveLeft) { direction = MovementDirection.Left; }
            else if (inputSource.MoveRight) { direction = MovementDirection.Right; }

            if ((direction == _lastMovementDirection) && (_millisecondsSinceLastMovement < Movement_Repeat_Time_In_Milliseconds))
            {
                direction = MovementDirection.None;
            }

            if (direction != MovementDirection.None)
            {
                switch (direction)
                {
                    case MovementDirection.Up: AttemptToActivateButton(_buttons[_activeButtonCaption].CaptionOfButtonActivatedByMovingUp); break;
                    case MovementDirection.Down: AttemptToActivateButton(_buttons[_activeButtonCaption].CaptionOfButtonActivatedByMovingDown); break;
                    case MovementDirection.Left: AttemptToActivateButton(_buttons[_activeButtonCaption].CaptionOfButtonActivatedByMovingLeft); break;
                    case MovementDirection.Right: AttemptToActivateButton(_buttons[_activeButtonCaption].CaptionOfButtonActivatedByMovingRight); break;
                }

                _lastMovementDirection = direction;
                _millisecondsSinceLastMovement = 0;
            }
        }
Esempio n. 57
0
        public virtual void Reset()
        {
            WorldPosition = new Vector2(0.0f, Definitions.Back_Buffer_Height + Entry_Margin);

            ActivateButton(_defaultButtonCaption);

            _activeButtonCaption = _defaultButtonCaption;
            _lastMovementDirection = MovementDirection.None;
            _millisecondsSinceLastMovement = 0;

            Active = false;
        }
Esempio n. 58
0
        public override bool ApplyMove(IGameBlockParent parentBlock, MovementDirection direction, BlockMovement move)
        {
            // No moves available, so return false (it shouldn't even reach here under normal circumstances)
            if (parentBlock.AvailableMoves == 0)
            {
                return false;
            }

            // If it's trying to do the same move again on this block, it's probably stuck in a loop.
            if (this.lastApplyMoveParentBlock == parentBlock && this.lastApplyMoveDirection == direction)
            {
                return false;
            }

            this.lastApplyMoveParentBlock = parentBlock;
            this.lastApplyMoveDirection = direction;

            bool usedThisBlock = false;

            // This block is available, so fill it
            if (this.IsAvailable)
            {
                this.NotifySetAnimation(this.GetCurrentMoveStartedAnimation(), true, false);

                this.SetAvailability(false);
                parentBlock.AvailableMoves--;
                usedThisBlock = true;

                // No more moves left, so we're done
                if (parentBlock.AvailableMoves == 0)
                {
                    this.NotifySetAnimation(this.GetCurrentMoveAppliedAnimation(), false, false);
                    this.lastApplyMoveParentBlock = null;
                    move.DestinationBlock = this;
                    return true;
                }
            }

            // Otherwise, move to the next block
            bool moveApplied;

            switch (direction)
            {
                default:
                case MovementDirection.Up:
                    if (!usedThisBlock)
                    {
                        this.NotifySetAnimation(SmashUpAnimation, true, false);
                    }

                    if (this.Top == null)
                    {
                        moveApplied = false;
                    }
                    else
                    {
                        moveApplied = this.Top.ApplyMove(parentBlock, direction, move);
                    }
                    break;

                case MovementDirection.Down:
                    if (!usedThisBlock)
                    {
                        this.NotifySetAnimation(SmashDownAnimation, true, false);
                    }

                    if (this.Bottom == null)
                    {
                        moveApplied = false;
                    }
                    else
                    {
                        moveApplied = this.Bottom.ApplyMove(parentBlock, direction, move);
                    }
                    break;

                case MovementDirection.Left:
                    if (!usedThisBlock)
                    {
                        this.NotifySetAnimation(SmashLeftAnimation, true, false);
                    }

                    if (this.Left == null)
                    {
                        moveApplied = false;
                    }
                    else
                    {
                        moveApplied = this.Left.ApplyMove(parentBlock, direction, move);
                    }
                    break;

                case MovementDirection.Right:
                    if (!usedThisBlock)
                    {
                        this.NotifySetAnimation(SmashRightAnimation, true, false);
                    }

                    if (this.Right == null)
                    {
                        moveApplied = false;
                    }
                    else
                    {
                        moveApplied = this.Right.ApplyMove(parentBlock, direction, move);
                    }
                    break;
            }

            // Used this block, but failed the child blocks, so undo the move
            if (usedThisBlock && !moveApplied)
            {
                this.SetAvailability(true);
                parentBlock.AvailableMoves++;
            }

            if (usedThisBlock)
            {
                // If it used this block, either show the block as applied, or as canceled
                if (moveApplied)
                {
                    move.IntermediateBlocks.Insert(0, this);

                    // Applied, so show the block as applied
                    this.NotifySetAnimation(this.GetCurrentMoveAppliedAnimation(), false, false);
                }
                else
                {
                    // If it was canceled, show the canceled animation, then back to the previous animation
                    this.NotifySetAnimation(MoveCanceledAnimation, false, false);
                    this.NotifySetAnimation(this.GetCurrentMoveAppliedAnimation(), false, true);
                }
            }
            else
            {
                this.NotifySetAnimation(this.GetCurrentMoveAppliedAnimation(), false, true);
            }

            this.lastApplyMoveParentBlock = null;
            return moveApplied;
        }
 // TODONE rm useless param "millisecond"
 public void move(MovementDirection direction)
 {
     //Console.Out.WriteLine("moving ! " + direction.ToString() );
     Vector2 movement;
     Single cos = (Single)Math.Cos (rotation);
     switch (direction) {
     case MovementDirection.Up:
         movement.X = 0;
         movement.Y = -1;
         break;
     case MovementDirection.Down:
         movement.X = 0;
         movement.Y = 1;
         break;
     case MovementDirection.Left:
         movement.X = -1;
         movement.Y = 0;
         break;
     case MovementDirection.Right:
         movement.X = 1;
         movement.Y = 0;
         break;
     case MovementDirection.DownLeft:
         movement.X = -0.707f; // LOL c'est quoi ça ?? pk c'est pas dans une constante ?!
         movement.Y = 0.707f;
         break;
     case MovementDirection.DownRight:
         movement.X = 0.707f;
         movement.Y = 0.707f;
         break;
     case MovementDirection.UpLeft:
         movement.X = -0.707f;
         movement.Y = -0.707f;
         break;
     case MovementDirection.UpRight:
         movement.X = 0.707f;
         movement.Y = -0.707f;
         break;
     default:
         movement.X = 0;
         movement.Y = 0;
         break;
     }
     //Console.Out.WriteLine (directionVector);
     ///movement = movement * milliseconds * speed; // ce n'est pas à Character de faire ce genre de trucs (millisecond)
     //Console.Out.WriteLine (movement);
     ///position += movement;
     body.tryMove(movement * info.speedBonus);
 }
Esempio n. 60
0
        public override int CountUsedBlocks(MovementDirection directionInReverse, Dictionary<IGameBlock, IGameBlock> previousBlocks)
        {
            int countUsed = this.numberOfMovesApplied;

            if (previousBlocks == null)
            {
                previousBlocks = new Dictionary<IGameBlock, IGameBlock>();
            }
            else if (previousBlocks.ContainsKey(this))
            {
                return 0;
            }

            previousBlocks.Add(this, this);

            switch (directionInReverse)
            {
                case MovementDirection.Up:
                    countUsed += this.Bottom == null ? 0 : this.Bottom.CountUsedBlocks(directionInReverse, previousBlocks);
                    break;
                case MovementDirection.Down:
                    countUsed += this.Top == null ? 0 : this.Top.CountUsedBlocks(directionInReverse, previousBlocks);
                    break;
                case MovementDirection.Left:
                    countUsed += this.Right == null ? 0 : this.Right.CountUsedBlocks(directionInReverse, previousBlocks);
                    break;
                case MovementDirection.Right:
                    countUsed += this.Left == null ? 0 : this.Left.CountUsedBlocks(directionInReverse, previousBlocks);
                    break;
                default:
                    throw new ArgumentOutOfRangeException("directionInReverse");
            }

            return countUsed;
        }