Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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;
        }
Ejemplo n.º 3
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;
 }
Ejemplo n.º 4
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();
 }
Ejemplo n.º 5
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;
        }
Ejemplo n.º 6
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;
                    }
            }
        }
Ejemplo n.º 7
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;
 }
Ejemplo n.º 8
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);
	    }
Ejemplo n.º 9
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();
        }
Ejemplo n.º 10
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");
     }
 }
Ejemplo n.º 11
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");
     }
 }
Ejemplo n.º 12
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);
            }
        }
Ejemplo n.º 13
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));
            }
        }
Ejemplo n.º 14
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;
    }
Ejemplo n.º 15
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;
        }
Ejemplo n.º 16
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;
        }
    }
Ejemplo n.º 17
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;
        }
Ejemplo n.º 18
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;
 }
Ejemplo n.º 19
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;
            }
        }
Ejemplo n.º 20
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;
        }
Ejemplo n.º 21
0
 public static int CoordinationOfMovementDirectionX(int posX, MovementDirection movementDirection)
 {
     return posX + moves[(-1 + (int)movementDirection) * 2];
 }
Ejemplo n.º 22
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;
        }
Ejemplo n.º 23
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;
        }
Ejemplo n.º 24
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);
 }
Ejemplo n.º 26
0
 // Use this for initialization
 void Start()
 {
     blood = GameObjectHelper.findChildBySubstringInName(gameObject, "blood");
     direction = GetComponent<MovementDirection>();
     player = GetComponent<Player>();
 }
Ejemplo n.º 27
0
 public static int CoordinationOfMovementDirectionY(int posY, MovementDirection movementDirection)
 {
     return posY + moves[(-1 + (int)movementDirection) * 2 + 1];
 }
Ejemplo n.º 28
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;
                }
            }
        }
Ejemplo n.º 29
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;
        }
    }
Ejemplo n.º 30
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);
                }
            }
        }