Exemple #1
0
    // Start is called before the first frame update
    void Start()
    {
        _initialScale = transform.localScale;

        _boxCollider = GetComponent <BoxCollider2D>();
        if (_boxCollider == null)
        {
            Debug.LogError("MovementController2D requires BoxCollider2D");
        }

        _colliderHalfHeight = (_boxCollider.bounds.size.y / 2);

        _groundLayerMask = LayerMask.NameToLayer("Ground");
        if (_groundLayerMask == -1)
        {
            Debug.LogError("MovementController2D requires layerMask \"Ground\"");
        }

        // plant should appear fully grown in the selection screen
        Growth = 1f;

        if (UnityEngine.Random.Range(0f, 100f) < 50f)
        {
            _walkDirection = WalkDirection.Left;
        }
        else
        {
            _walkDirection = WalkDirection.Right;
        }

        _faceSpriteRender.sprite = _faceSprite_Neutral;
    }
Exemple #2
0
        private void PickRandomWalkDirection()
        {
            int           randomDirection = Random.Range(0, 5);
            WalkDirection result          = (WalkDirection)randomDirection;

            this.currentWalkDirection = result;
        }
Exemple #3
0
        public Character(System.IO.BinaryReader reader, bool sentFromServer)
            : base(reader, sentFromServer)
        {
            myHitPoints = reader.ReadInt16();
            myManaLevel = reader.ReadInt16();

            ushort attribCount = reader.ReadUInt16();

            for (int i = 0; i < attribCount; ++i)
            {
                myBaseAttributes.Add(CharAttribute.GetByID(reader.ReadUInt16()), reader.ReadByte());
            }

            ushort skillCount = reader.ReadUInt16();

            for (int i = 0; i < skillCount; ++i)
            {
                myBaseSkills.Add(CharSkill.GetByID(reader.ReadUInt16()), reader.ReadByte());
            }

            myCurrentWalkDirection = myFacingDirection = (WalkDirection)reader.ReadByte();

            if (!sentFromServer)
            {
                Inventory = new Inventory(this, reader);
            }
        }
Exemple #4
0
        public virtual void StartWalking(WalkDirection dir, ulong startTime, Vector2d startPos)
        {
            if (!IsAlive || Tools.TicksToSeconds(Map.TimeTicks - myLastCastTime) < CastAnimationDuration)
            {
                return;
            }

            myNextWalkDirection = dir;

            myWalkStartTime = startTime;
            myWalkStartPos  = startPos;

            if (dir == WalkDirection.Up || dir == WalkDirection.Down)
            {
                OriginX = startPos.X;
            }
            else
            {
                OriginY = startPos.Y;
            }

            if (IsServer)
            {
                System.IO.MemoryStream stream = new System.IO.MemoryStream();
                stream.WriteByte((byte)myNextWalkDirection);
                stream.Write(BitConverter.GetBytes(myWalkStartTime), 0, sizeof(UInt64));
                stream.Write(BitConverter.GetBytes(myWalkStartPos.X), 0, sizeof(Double));
                stream.Write(BitConverter.GetBytes(myWalkStartPos.Y), 0, sizeof(Double));
                SendStateUpdate("StartWalking", stream);
                stream.Close();

                myLastWalkStateSent = Map.TimeTicks;
            }
        }
Exemple #5
0
    public void SetWalkDirectionType(WalkDirection type)
    {
        switch (type)
        {
        case WalkDirection.Up:
            moveDirection += new Vector3(0, 0.2f, 0);
            break;

        case WalkDirection.Down:
            moveDirection += new Vector3(0, -0.2f, 0);
            break;

        case WalkDirection.Left:
            moveDirection += new Vector3(-0.2f, 0, 0);
            break;

        case WalkDirection.Right:
            moveDirection += new Vector3(0.2f, 0, 0);
            break;

        case WalkDirection.None:
            moveDirection += new Vector3(0, 0, 0);
            break;
        }
    }
Exemple #6
0
 // Use this for initialization
 void Start()
 {
     onGround      = true;
     isIdle        = true;
     walkDirection = WalkDirection.Right;
     walkSpeed     = 0.05f;
 }
Exemple #7
0
        public bool IsInBoard(int x, int y, WalkDirection randomDirection, int stepSize)
        {
            switch (randomDirection)
            {
            case WalkDirection.None:
                break;

            case WalkDirection.North:
                y += stepSize;
                break;

            case WalkDirection.South:
                y -= stepSize;
                break;

            case WalkDirection.East:
                x += stepSize;
                break;

            case WalkDirection.West:
                x -= stepSize;
                break;
            }

            return((x >= 0) && (x < _columns) && (y >= 0) && (y < _rows));
        }
        /// <summary>
        /// Determines whether the bot can walk to the specified direction.
        /// </summary>
        /// <param name="direction">The direction.</param>
        /// <returns>
        ///   <c>true</c> if the bot can walk to the specified direction; otherwise, <c>false</c>.
        /// </returns>
        public bool CanWalkTo(WalkDirection direction)
        {
            var cell = m_map[MyCell.Y, MyCell.X];

            switch (direction)
            {
            case WalkDirection.Up:
                return(cell.TopSide == CellSideType.Free);

            case WalkDirection.Left:
                return(cell.LeftSide == CellSideType.Free);

            case WalkDirection.Right:
                if (cell.X == m_map.GetUpperBound(1))
                {
                    return(false);
                }
                return(GetMyNextCellFrom(direction).LeftSide == CellSideType.Free);

            case WalkDirection.Down:
                if (cell.Y == m_map.GetUpperBound(0))
                {
                    return(false);
                }

                return(GetMyNextCellFrom(direction).TopSide == CellSideType.Free);
            }

            return(false);
        }
Exemple #9
0
	private void UpdateAnimation(bool moving, WalkDirection direction) {
		OTAnimatingSprite sprite = GetComponent<OTAnimatingSprite>();

		if(isCurrentlySwinging) {
			return;
		}
				
		if(moving && currentWalkDirection != direction) {
			if(direction == WalkDirection.LEFT) {
				sprite.PlayLoop("walkLeft");
			} else {
				sprite.PlayLoop("walkRight");
			}
		}
		
		if(moving) {
			if(!sprite.isPlaying) {
				sprite.Play();
			}
		} else {
			sprite.Pauze();
			sprite.frameIndex = 1;
			if (direction == WalkDirection.LEFT) {
				sprite.frameIndex += 4;
			}
		}
		
		if(falling) {
			sprite.Pauze();
			sprite.frameIndex = 0;
			if (direction == WalkDirection.LEFT) {
				sprite.frameIndex += 4;
			}
		}
	}
Exemple #10
0
        private MazeCell GetNewAroundCell(WalkDirection direction)
        {
            var aroundCell = new MazeCell(m_myCell.X, m_myCell.Y);

            switch (direction)
            {
            case WalkDirection.Down:
                aroundCell.Y++;
                break;

            case WalkDirection.Left:
                aroundCell.X--;
                break;

            case WalkDirection.Right:
                aroundCell.X++;
                break;

            case WalkDirection.Up:
                aroundCell.Y--;
                break;
            }

            return(aroundCell);
        }
    protected void FindDirectionToTarget(Vector2 targetPosition)
    {
        //print ("finding direction to blockzilla");
        Vector2 heading = targetPosition - (Vector2)transform.localPosition;
        var     dirNum  = AngleDir(transform.forward, heading, transform.up);

        var rotation = gameObject.transform.GetChild(0).localRotation;

        //print (dirNum);
        if (dirNum > 0)
        {
            //print ("going right");
            rotation.eulerAngles = new Vector2(0, 0);
            walkDirection        = WalkDirection.Right;
        }
        else if (dirNum < 0)
        {
//			print ("going left");
            rotation.eulerAngles = new Vector2(0, 180);
            walkDirection        = WalkDirection.Left;
        }

        //no need to get child every frame?
        gameObject.transform.GetChild(0).localRotation = rotation;
    }
Exemple #12
0
        void SetupRunAnimation()
        {
            NSString runKey      = KeyForAnimationType(CharacterAnimation.Run);
            NSString runStartKey = KeyForAnimationType(CharacterAnimation.RunStart);
            NSString runStopKey  = KeyForAnimationType(CharacterAnimation.RunStop);

            CAAnimation runAnim      = LoadAndCacheAnimation("art.scnassets/characters/explorer/run", runKey);
            CAAnimation runStartAnim = LoadAndCacheAnimation("art.scnassets/characters/explorer/run_start", runStartKey);
            CAAnimation runStopAnim  = LoadAndCacheAnimation("art.scnassets/characters/explorer/run_stop", runStopKey);

            runAnim.RepeatCount      = float.MaxValue;
            runStartAnim.RepeatCount = 0;
            runStopAnim.RepeatCount  = 0;

            runAnim.FadeInDuration       = 0.05f;
            runAnim.FadeOutDuration      = 0.05f;
            runStartAnim.FadeInDuration  = 0.05f;
            runStartAnim.FadeOutDuration = 0.05f;
            runStopAnim.FadeInDuration   = 0.05f;
            runStopAnim.FadeOutDuration  = 0.05f;

            SCNAnimationEventHandler stepLeftBlock = (animation, animatedObject, playingBackward) => {
                GameSimulation.Sim.PlaySound("leftstep.caf");
            };

            SCNAnimationEventHandler stepRightBlock = (animation, animatedObject, playingBackward) => {
                GameSimulation.Sim.PlaySound("rightstep.caf");
            };

            SCNAnimationEventHandler startWalkStateBlock = (animation, animatedObject, playingBackward) => {
                if (InRunAnimation)
                {
                    IsWalking = true;
                }
                else
                {
                    mainSkeleton.RemoveAnimation(runKey, 0.15f);
                }
            };

            SCNAnimationEventHandler stopWalkStateBlock = (animation, animatedObject, playingBackward) => {
                IsWalking = false;
                TurnOffWalkingDust();
                if (changingDirection)
                {
                    inRunAnimation      = false;
                    InRunAnimation      = true;
                    changingDirection   = false;
                    playerWalkDirection = playerWalkDirection == WalkDirection.Left ? WalkDirection.Right : WalkDirection.Left;
                }
            };

            runStopAnim.AnimationEvents = new SCNAnimationEvent[] { SCNAnimationEvent.Create(1f, stopWalkStateBlock) };
            runAnim.AnimationEvents     = new SCNAnimationEvent[] {
                SCNAnimationEvent.Create(0.0f, startWalkStateBlock),
                SCNAnimationEvent.Create(0.25f, stepRightBlock),
                SCNAnimationEvent.Create(0.75f, stepLeftBlock)
            };
        }
Exemple #13
0
 //---------------------//
 public void StartWalk1(WalkDirection dir = WalkDirection.Up, int duration = Config.STD_MOVETIME)
 {
     Task.Factory.StartNew(() =>
     {
         isUserStop      = false;
         DateTime sttime = DateTime.Now;
         int ud          = (dir == WalkDirection.Up || dir == WalkDirection.Left) ? -1 :  1;
         string lr       = (dir == WalkDirection.Left || dir == WalkDirection.Right) ? "X" : "Z";
         //int lr = (dir == WalkDirection.Left) ? "X" : ((dir == WalkDirection.Right) ? "Z" : 1);
         //---- pre ----//
         model.HexModel.UpdateLeg(Config.LEGUP, 3, "Y", 1, 3, 5);
         model.HexModel.UpdateLeg(ud * Config.GAIT_DISTANCE / 2, 3, lr, 1, 3, 5);
         model.HexModel.UpdateLeg(-(ud * Config.GAIT_DISTANCE / 2), 3, lr, 2, 4, 6);
         control.ExecuteOnce(new Command(model.HexModel.generate(duration)));
         //Thread.Sleep(1000);
         model.HexModel.UpdateLeg(-Config.LEGUP, 3, "Y", 1, 3, 5);
         model.HexModel.UpdateLeg(ud * Config.GAIT_DISTANCE / 2, 3, lr, 1, 3, 5);
         model.HexModel.UpdateLeg(-(ud * Config.GAIT_DISTANCE / 2), 3, lr, 2, 4, 6);
         control.ExecuteOnce(new Command(model.HexModel.generate(duration)));
         //Thread.Sleep(1000);
         while (!isUserStop)
         {
             if (DateTime.Now - sttime > USRTIMEOUT)
             {
                 return;
             }
             model.HexModel.UpdateLeg(Config.LEGUP, 3, "Y", 2, 4, 6);
             model.HexModel.UpdateLeg(ud * Config.GAIT_DISTANCE, 3, lr, 2, 4, 6);
             model.HexModel.UpdateLeg(-(ud * Config.GAIT_DISTANCE), 3, lr, 1, 3, 5);
             control.ExecuteOnce(new Command(model.HexModel.generate(duration)));
             //Thread.Sleep(1000);
             model.HexModel.UpdateLeg(-Config.LEGUP, 3, "Y", 2, 4, 6);
             model.HexModel.UpdateLeg(ud * Config.GAIT_DISTANCE, 3, lr, 2, 4, 6);
             model.HexModel.UpdateLeg(-(ud * Config.GAIT_DISTANCE), 3, lr, 1, 3, 5);
             control.ExecuteOnce(new Command(model.HexModel.generate(duration)));
             //Thread.Sleep(1000);
             model.HexModel.UpdateLeg(Config.LEGUP, 3, "Y", 1, 3, 5);
             model.HexModel.UpdateLeg(ud * Config.GAIT_DISTANCE, 3, lr, 1, 3, 5);
             model.HexModel.UpdateLeg(-(ud * Config.GAIT_DISTANCE), 3, lr, 2, 4, 6);
             control.ExecuteOnce(new Command(model.HexModel.generate(duration)));
             //Thread.Sleep(1000);
             model.HexModel.UpdateLeg(-Config.LEGUP, 3, "Y", 1, 3, 5);
             model.HexModel.UpdateLeg(ud * Config.GAIT_DISTANCE, 3, lr, 1, 3, 5);
             model.HexModel.UpdateLeg(-(ud * Config.GAIT_DISTANCE), 3, lr, 2, 4, 6);
             control.ExecuteOnce(new Command(model.HexModel.generate(duration)));
             //Thread.Sleep(1000);
         }
         model.HexModel.UpdateLeg(Config.LEGUP, 3, "Y", 2, 4, 6);
         model.HexModel.UpdateLeg(ud * Config.GAIT_DISTANCE / 2, 3, lr, 2, 4, 6);
         model.HexModel.UpdateLeg(-(ud * Config.GAIT_DISTANCE / 2), 3, lr, 1, 3, 5);
         control.ExecuteOnce(new Command(model.HexModel.generate(duration)));
         //Thread.Sleep(1000);
         model.HexModel.UpdateLeg(-Config.LEGUP, 3, "Y", 2, 4, 6);
         model.HexModel.UpdateLeg(ud * Config.GAIT_DISTANCE / 2, 3, lr, 2, 4, 6);
         model.HexModel.UpdateLeg(-(ud * Config.GAIT_DISTANCE / 2), 3, lr, 1, 3, 5);
         control.ExecuteOnce(new Command(model.HexModel.generate(duration)));
         //Thread.Sleep(1000);
     });
 }
Exemple #14
0
        public static void Send(Client client, WalkDirection direction)
        {
            NetworkMessage packet = new NetworkMessage();

            packet.Position = 0;
            packet.AddByte((byte)direction);
            client.HookProxy.SendPacketToServer(packet.Data);
        }
Exemple #15
0
 public RectangleWalkEffect(IRectangleLocator rectangleLocator, IPointLocator alignmentPointLocator,
                            WalkDirection direction, IPointLocator startPoint)
 {
     this.RectangleLocator      = rectangleLocator;
     this.AlignmentPointLocator = alignmentPointLocator;
     this.WalkDirection         = direction;
     this.StartPointLocator     = startPoint;
 }
Exemple #16
0
        private WalkDirection GetInvertedDirection(WalkDirection walkDirection)
        {
            int index = (int)walkDirection;

            index  = (index + 1) % 4;
            index += 1;
            return((WalkDirection)index);
        }
Exemple #17
0
        private void ReceiveCharacterMove(BinaryReader reader)
        {
            WalkDirection dir       = (WalkDirection)reader.ReadByte();
            ulong         startTime = reader.ReadUInt64();

            OpenTK.Vector2d startPos = new OpenTK.Vector2d(reader.ReadDouble(), reader.ReadDouble());

            PlayerEntity.StartWalking(dir, startTime, startPos);
        }
    private void Start()
    {
        enemyRB        = GetComponent <Rigidbody>();
        player         = GameObject.Find("Player");
        playerFSM      = GameObject.FindObjectOfType <PlayerFSM>();
        dungeonCreator = GameObject.FindObjectOfType <DungeonCreator>();

        direction = (WalkDirection)Random.Range(0, 4);
    }
    private void OnCollisionStay(Collision collision)
    {
        var normal = collision.contacts[0].normal;

        if (normal.y <= 0)
        {
            // This only happens when the enemy does not collide with the player and not with the floor.
            direction = (WalkDirection)((int)(direction + Random.Range(1, 4)) % 4);
        }
    }
Exemple #20
0
        public Character()
        {
            CollideWithEntities    = true;
            myCurrentWalkDirection = myFacingDirection = WalkDirection.Down;

            myHitPoints = MaxHitPoints;
            myManaLevel = MaxManaLevel;

            Inventory = new Inventory(this, 0);
        }
Exemple #21
0
        private KeyValuePair <MazeCell, long> GetVisitedAroundCell(WalkDirection direction)
        {
            var aroundCell = GetNewAroundCell(direction);

            var query = from vs in m_visitedCells
                        where vs.Key.Equals(aroundCell)
                        select vs;

            return(query.FirstOrDefault());
        }
Exemple #22
0
        public PlayerCharacter(SCNNode characterNode) : base(characterNode)
        {
            CategoryBitMask   = NodeCategory.Lava;
            velocity          = SCNVector3.Zero;
            IsWalking         = false;
            changingDirection = false;
            baseWalkSpeed     = 0.0167f;
            JumpBoost         = 0.0f;

            WalkSpeed           = baseWalkSpeed * 2;
            Jumping             = false;
            groundPlaneHeight   = 0.0f;
            playerWalkDirection = WalkDirection.Right;

            cameraHelper = new SCNNode {
                Position = new SCNVector3(1000f, 200f, 0f)
            };

            AddChildNode(cameraHelper);

            CollideSphere = new SCNNode {
                Position = new SCNVector3(0f, 80f, 0f)
            };

            SCNGeometry     geo    = SCNCapsule.Create(90f, 160f);
            SCNPhysicsShape shape2 = SCNPhysicsShape.Create(geo, (NSDictionary)null);

            CollideSphere.PhysicsBody = SCNPhysicsBody.CreateBody(SCNPhysicsBodyType.Kinematic, shape2);

            CollideSphere.PhysicsBody.CollisionBitMask =
                GameCollisionCategory.Banana |
                GameCollisionCategory.Coin |
                GameCollisionCategory.Coconut |
                GameCollisionCategory.Lava;

            CollideSphere.PhysicsBody.CategoryBitMask = GameCollisionCategory.Player;
            AddChildNode(CollideSphere);

            DustPoof = GameSimulation.LoadParticleSystemWithName("dust");
            NSString artResourcePath = (NSString)GameSimulation.PathForArtResource("level/effects/effects_transparent.png");

            DustPoof.ParticleImage    = artResourcePath;
            DustWalking               = GameSimulation.LoadParticleSystemWithName("dustWalking");
            DustWalking.ParticleImage = artResourcePath;
            dustWalkingBirthRate      = DustWalking.BirthRate;

            // Load the animations and store via a lookup table.
            SetupIdleAnimation();
            SetupRunAnimation();
            SetupJumpAnimation();
            SetupBoredAnimation();
            SetupHitAnimation();

            PlayIdle();
        }
Exemple #23
0
        public void SendCharacterMove(Player player, WalkDirection dir)
        {
            BinaryWriter writer = GetWriter();

            writer.Write((byte)PacketID.CharacterMove);
            writer.Write((byte)dir);
            writer.Write(Map.TimeTicks);
            writer.Write(player.OriginX);
            writer.Write(player.OriginY);
            SendPacket();
        }
Exemple #24
0
 public void Stop()
 {
     if (body != null)
     {
         body.drag = stopDeceleration;
     }
     direction = WalkDirection.None;
     if (animation != null)
     {
         StopCoroutine(animation);
     }
 }
Exemple #25
0
    private void ReverseDirectionIfAtEnd()
    {
        float camPosX = GameObject.FindGameObjectWithTag("MainCamera").transform.position.x;

        if (_direction == WalkDirection.Left && transform.position.x < -3.5f + camPosX)
        {
            _direction = WalkDirection.Right;
        }
        else if (_direction == WalkDirection.Right && transform.position.x > 4f + camPosX)
        {
            _direction = WalkDirection.Left;
        }
    }
        protected bool ReachedTarget(GameObject self, Vector2 targetDestination)
        {
            var dist = Vector2.Distance(self.transform.position, targetDestination);

            //Find threshold such that it fits with the target
            if (dist < ObjectiveRange)
            {
                direction = 0;
                return(true);
            }

            return(false);
        }
Exemple #27
0
        private void ProcessRandomWalkDirection()
        {
            float changeDirection = Random.RandomRange(0f, 1f);

            if (changeDirection * 2 < this.directionChangeFrequency)
            {
                this.currentWalkDirection = WalkDirection.Idle;
            }
            else if (changeDirection < this.directionChangeFrequency)
            {
                PickRandomWalkDirection();
            }
        }
Exemple #28
0
 private void DecideLocationToMove(float chanceFactor, WalkDirection direction)
 {
     direction = GetInvertedDirection(direction);
     if (chanceFactor <= maxFactorToPassLevel)
     {
         // Move to the next level!
         CurrentLevel = new Level(CurrentLevel.Id + 1, (CurrentLevel.Difficulty + 1) * DifficultyFactor, direction, CurrentLevel.CurrentChamber.Entities);
     }
     else
     {
         // Generate a new chamber in the same level.
         CurrentLevel.CurrentChamber = new Chamber(CurrentLevel.CurrentChamber.Id + 1, direction, CurrentLevel, CurrentLevel.CurrentChamber.Entities);
     }
 }
Exemple #29
0
        private void ProcessFollowWalkDirection()
        {
            float distance = Vector2.Distance(this.transform.position, Player.Get().transform.position);

            if (distance > this.minimumFollowDistance)
            {
                ProcessRandomWalkDirection();
                return;
            }

            if (distance < this.followStopThreshold)
            {
                this.currentWalkDirection = WalkDirection.Idle;
                return;
            }

            Vector2 distances = Player.Get().transform.position - this.transform.position;

            if (Mathf.Abs(distances.x) > Mathf.Abs(distances.y))
            {
                if (distances.x < 0)
                {
                    this.currentWalkDirection = WalkDirection.Left;
                }
                else if (distances.x > 0)
                {
                    this.currentWalkDirection = WalkDirection.Right;
                }
                else
                {
                    this.currentWalkDirection = WalkDirection.Idle;
                }
            }
            else
            {
                if (distances.y < 0)
                {
                    this.currentWalkDirection = WalkDirection.Down;
                }
                else if (distances.y > 0)
                {
                    this.currentWalkDirection = WalkDirection.Up;
                }
                else
                {
                    this.currentWalkDirection = WalkDirection.Idle;
                }
            }
        }
Exemple #30
0
 private void FixedUpdate()
 {
     if (Behaviour == BehaviourType.Walk && UnityEngine.Random.Range(0f, 100f) < PercChanceOfChangingWalkDirection)
     {
         // change direction
         if (_walkDirection == WalkDirection.Right)
         {
             _walkDirection = WalkDirection.Left;
         }
         else
         {
             _walkDirection = WalkDirection.Right;
         }
     }
 }
 private void moveOneStep(WalkDirection dir)
 {
     isMoving = true;
     acceptMovement = false;
     switch (dir)
     {
         case WalkDirection.DOWN:
             _gridY += 1;
             break;
         case WalkDirection.LEFT:
             _gridX -= 1;
             break;
         case WalkDirection.RIGHT:
             _gridX += 1;
             break;
         case WalkDirection.UP:
             _gridY -= 1;
             break;
     }
     currAnimation = moveStbs[dir];
     walkStbs[dir].Begin();
 }
 private void stand(WalkDirection dir)
 {
     foreach (KeyValuePair<WalkDirection, Storyboard> entry in moveStbs)
     {
         if (entry.Value == currAnimation)
         {
             entry.Value.Stop();
         }
     }
     currDir = dir;
 }
        private DoubleAnimation createBoxMoveAni(Box box,WalkDirection dir,double walkSpped, double by)
        {
            DoubleAnimation retVal = new DoubleAnimation();
            Storyboard.SetTarget(retVal, box);
            switch (dir)
            {
                case WalkDirection.DOWN:
                    retVal.By = scene.tileHeight;
                    Storyboard.SetTargetProperty(retVal, new PropertyPath("RenderTransform.(TranslateTransform.Y)"));

                    break;
                case WalkDirection.RIGHT:
                    retVal.By = scene.tileWidth;
                    Storyboard.SetTargetProperty(retVal, new PropertyPath("RenderTransform.(TranslateTransform.X)"));
                    break;
                case WalkDirection.LEFT:
                    retVal.By = -scene.tileWidth;
                    Storyboard.SetTargetProperty(retVal, new PropertyPath("RenderTransform.(TranslateTransform.X)"));
                    break;

                case WalkDirection.UP:
                    retVal.By = -scene.tileHeight;
                    Storyboard.SetTargetProperty(retVal, new PropertyPath("RenderTransform.(TranslateTransform.Y)"));
                    break;

            }
            retVal.Duration = TimeSpan.FromSeconds(1 / walkSpped);
            retVal.FillBehavior = FillBehavior.HoldEnd;
            return retVal;
        }
		void SetupRunAnimation ()
		{
			NSString runKey = KeyForAnimationType (CharacterAnimation.Run);
			NSString runStartKey = KeyForAnimationType (CharacterAnimation.RunStart);
			NSString runStopKey = KeyForAnimationType (CharacterAnimation.RunStop);

			CAAnimation runAnim = LoadAndCacheAnimation ("art.scnassets/characters/explorer/run", runKey);
			CAAnimation runStartAnim = LoadAndCacheAnimation ("art.scnassets/characters/explorer/run_start", runStartKey);
			CAAnimation runStopAnim = LoadAndCacheAnimation ("art.scnassets/characters/explorer/run_stop", runStopKey);

			runAnim.RepeatCount = float.MaxValue;
			runStartAnim.RepeatCount = 0;
			runStopAnim.RepeatCount = 0;

			runAnim.FadeInDuration = 0.05f;
			runAnim.FadeOutDuration = 0.05f;
			runStartAnim.FadeInDuration = 0.05f;
			runStartAnim.FadeOutDuration = 0.05f;
			runStopAnim.FadeInDuration = 0.05f;
			runStopAnim.FadeOutDuration = 0.05f;

			SCNAnimationEventHandler stepLeftBlock = (animation, animatedObject, playingBackward) => {
				GameSimulation.Sim.PlaySound ("leftstep.caf");
			};

			SCNAnimationEventHandler stepRightBlock = (animation, animatedObject, playingBackward) => {
				GameSimulation.Sim.PlaySound ("rightstep.caf");
			};

			SCNAnimationEventHandler startWalkStateBlock = (animation, animatedObject, playingBackward) => {
				if (InRunAnimation)
					IsWalking = true;
				else
					mainSkeleton.RemoveAnimation (runKey, 0.15f);
			};

			SCNAnimationEventHandler stopWalkStateBlock = (animation, animatedObject, playingBackward) => {
				IsWalking = false;
				TurnOffWalkingDust ();
				if (changingDirection) {
					inRunAnimation = false;
					InRunAnimation = true;
					changingDirection = false;
					playerWalkDirection = playerWalkDirection == WalkDirection.Left ? WalkDirection.Right : WalkDirection.Left;
				}
			};

			runStopAnim.AnimationEvents = new SCNAnimationEvent[] { SCNAnimationEvent.Create (1f, stopWalkStateBlock) };
			runAnim.AnimationEvents = new SCNAnimationEvent[] { 
				SCNAnimationEvent.Create (0.0f, startWalkStateBlock),
				SCNAnimationEvent.Create (0.25f, stepRightBlock),
				SCNAnimationEvent.Create (0.75f, stepLeftBlock)
			};
		}
		public PlayerCharacter (SCNNode characterNode) : base (characterNode)
		{
			CategoryBitMask = NodeCategory.Lava;
			velocity = SCNVector3.Zero;
			IsWalking = false;
			changingDirection = false;
			baseWalkSpeed = 0.0167f;
			JumpBoost = 0.0f;

			WalkSpeed = baseWalkSpeed * 2;
			Jumping = false;
			groundPlaneHeight = 0.0f;
			playerWalkDirection = WalkDirection.Right;

			cameraHelper = new SCNNode {
				Position = new SCNVector3 (1000f, 200f, 0f)
			};

			AddChildNode (cameraHelper);

			CollideSphere = new SCNNode {
				Position = new SCNVector3 (0f, 80f, 0f)
			};

			SCNGeometry geo = SCNCapsule.Create (90f, 160f);
			SCNPhysicsShape shape2 = SCNPhysicsShape.Create (geo, (NSDictionary)null);
			CollideSphere.PhysicsBody = SCNPhysicsBody.CreateBody (SCNPhysicsBodyType.Kinematic, shape2);

			CollideSphere.PhysicsBody.CollisionBitMask = 
				GameCollisionCategory.Banana |
			GameCollisionCategory.Coin |
			GameCollisionCategory.Coconut |
			GameCollisionCategory.Lava;

			CollideSphere.PhysicsBody.CategoryBitMask = GameCollisionCategory.Player;
			AddChildNode (CollideSphere);

			DustPoof = GameSimulation.LoadParticleSystemWithName ("dust");
			NSString artResourcePath = (NSString)GameSimulation.PathForArtResource ("level/effects/effects_transparent.png");
			DustPoof.ParticleImage = artResourcePath;
			DustWalking = GameSimulation.LoadParticleSystemWithName ("dustWalking");
			DustWalking.ParticleImage = artResourcePath;
			dustWalkingBirthRate = DustWalking.BirthRate;

			// Load the animations and store via a lookup table.
			SetupIdleAnimation ();
			SetupRunAnimation ();
			SetupJumpAnimation ();
			SetupBoredAnimation ();
			SetupHitAnimation ();

			PlayIdle ();
		}
        private RectAnimation createDetonateViewportAni(WalkDirection dir,int power)
        {
            RectAnimation retVal = new RectAnimation();
            retVal.From = new Rect(0, 0, scene.tileWidth, scene.tileHeight);
            switch (dir)
            {
                case WalkDirection.DOWN:
                    retVal.To = new Rect(0, power * scene.tileHeight, scene.tileWidth, scene.tileHeight);
                    break;
                case WalkDirection.LEFT:
                    retVal.To = new Rect(power * -scene.tileWidth, 0, scene.tileWidth, scene.tileHeight);
                    break;
                case WalkDirection.RIGHT:
                    retVal.To = new Rect(power * scene.tileWidth, 0, scene.tileWidth, scene.tileHeight);
                    break;
                case WalkDirection.UP:
                    retVal.To = new Rect(0, power * -scene.tileHeight, scene.tileWidth, scene.tileHeight);
                    break;

            }
            retVal.Duration = TimeSpan.FromSeconds((double)power / detonateSpeed);

            retVal.EasingFunction = new CubicEase() { EasingMode = EasingMode.EaseInOut };
            Storyboard.SetTarget(retVal, detonateRects[dir]);
            //detonateBrushes[dir].Viewport
            Storyboard.SetTargetProperty(retVal, new PropertyPath("Fill.(ImageBrush.Viewport)"));
            return retVal;
        }
        private void editDetonateStretchAni(WalkDirection dir, int power)
        {
            DoubleAnimation ani = detonateStb[dir].Children[0] as DoubleAnimation;

            switch (dir)
            {
                case WalkDirection.DOWN:
                case WalkDirection.UP:
                    ani.To = power * scene.tileHeight;
                    break;
                case WalkDirection.LEFT:
                case WalkDirection.RIGHT:
                    ani.To = power * scene.tileWidth;
                    break;

            }
            ani.Duration = TimeSpan.FromSeconds((double)power / detonateSpeed);
        }
        private DoubleAnimation createDetonateOffsetAni(WalkDirection dir, int power)
        {
            DoubleAnimation retVal = new DoubleAnimation();
            switch (dir)
            {
                case WalkDirection.DOWN:
                case WalkDirection.RIGHT:
                    throw new Exception("Direction DOWN and RIGHT does not need this animation");
                    break;
                case WalkDirection.LEFT:
                    retVal.By = -power * scene.tileWidth;
                    break;

                case WalkDirection.UP:
                    retVal.By = -power * scene.tileHeight;
                    break;

            }
            retVal.Duration = TimeSpan.FromSeconds((double)power / detonateSpeed);
            retVal.FillBehavior = FillBehavior.Stop;
            retVal.AutoReverse = true;
            retVal.EasingFunction = new CubicEase() { EasingMode = EasingMode.EaseInOut };
            Storyboard.SetTarget(retVal, detonateRects[dir]);
            switch (dir)
            {

                case WalkDirection.UP:
                    Storyboard.SetTargetProperty(retVal, new PropertyPath(Canvas.TopProperty));
                    break;
                case WalkDirection.LEFT:

                    Storyboard.SetTargetProperty(retVal, new PropertyPath(Canvas.LeftProperty));
                    break;

            }
            return retVal;
        }
        private bool validateOneStep(WalkDirection dir)
        {
            bool retVal = true;
            Box neighborBox = null;
            switch (dir)
            {
                case WalkDirection.DOWN:
                    if(gridY+1 < scene.height)
                    {
                        neighborBox = scene.boxLayer.boxOnGrid(gridX, gridY + 1);
                        retVal &= scene.obstacleLayer.obstacles[gridY + 1,gridX] == null;
                    }
                    else
                    {
                        return false;
                    }

                    break;
                case WalkDirection.LEFT:
                    if (gridX - 1 >= 0)
                    {
                        neighborBox = scene.boxLayer.boxOnGrid(gridX - 1, gridY);
                        retVal &= scene.obstacleLayer.obstacles[gridY, gridX - 1] == null;
                    }
                    else
                    {
                        return false;
                    }
                    break;
                case WalkDirection.RIGHT:
                    if (gridX + 1 < scene.width)
                    {
                        neighborBox = scene.boxLayer.boxOnGrid(gridX + 1, gridY);
                        retVal &=  scene.obstacleLayer.obstacles[gridY, gridX + 1] == null;
                    }
                    else
                    {
                        return false;
                    }

                    break;
                case WalkDirection.UP:
                    if (gridY - 1 >= 0)
                    {
                        neighborBox = scene.boxLayer.boxOnGrid(gridX, gridY - 1);
                        retVal &= gridY - 1 >= 0 && scene.obstacleLayer.obstacles[gridY - 1, gridX] == null;
                    }
                    else
                    {
                        return false;
                    }

                    break;
            }
            if (!retVal)
            {
                //fastern
                return retVal;
            }
            if (neighborBox!= null)
            {
                retVal &= scene.boxLayer.moveBoxOne(neighborBox, dir, this);
            }
            return retVal;
        }
        private DoubleAnimation createDetonateStretchAni(WalkDirection dir, int power)
        {
            DoubleAnimation retVal = new DoubleAnimation();
            retVal.Name = dir.ToString();
            retVal.From = 0;
            switch (dir)
            {
                case WalkDirection.DOWN:
                case WalkDirection.UP:
                    retVal.To = power * scene.tileHeight;
                    break;
                case WalkDirection.LEFT:
                case WalkDirection.RIGHT:
                    retVal.To = power * scene.tileWidth;
                    break;

            }
            retVal.Duration = TimeSpan.FromSeconds((double)power / detonateSpeed);
            retVal.FillBehavior = FillBehavior.Stop;
            retVal.AutoReverse = true;
            retVal.EasingFunction = new CubicEase() {  EasingMode= EasingMode.EaseInOut};
            Storyboard.SetTarget(retVal, detonateRects[dir]);
            switch (dir)
            {
                case WalkDirection.DOWN:
                case WalkDirection.UP:
                    Storyboard.SetTargetProperty(retVal, new PropertyPath(Shape.HeightProperty));
                    break;
                case WalkDirection.LEFT:
                case WalkDirection.RIGHT:
                    Storyboard.SetTargetProperty(retVal, new PropertyPath(Shape.WidthProperty));
                    break;

            }

            switch (dir)
            {
                case WalkDirection.DOWN:
                    retVal.CurrentTimeInvalidated += detonateStretchAni_TimeInvalidated;
                    break;
                case WalkDirection.UP:
                    retVal.CurrentTimeInvalidated += detonateStretchAni_TimeInvalidated;
                    break;
                case WalkDirection.LEFT:
                    retVal.CurrentTimeInvalidated += detonateStretchAni_TimeInvalidated;
                    break;
                case WalkDirection.RIGHT:
                    retVal.CurrentTimeInvalidated += detonateStretchAni_TimeInvalidated;
                    break;

            }

            return retVal;
        }
        private int getActualPower(WalkDirection dir)
        {
            int retVal = 0;
            for (int i = 0; i < owner.power; i++)
            {
                retVal = i;
                int x = 0;
                int y = 0;
                switch (dir)
                {
                    case WalkDirection.DOWN:
                        x = laidGridX;
                        y = laidGridY + i + 1;
                        break;
                    case WalkDirection.LEFT:
                        x = laidGridX - i - 1;
                        y = laidGridY;
                        break;
                    case WalkDirection.RIGHT:
                        x = laidGridX + i + 1;
                        y = laidGridY;
                        break;
                    case WalkDirection.UP:
                        x = laidGridX;
                        y = laidGridY - i - 1;
                        break;

                }
                if (x < 0 || x >= scene.width || y <0 || y >= scene.height)
                {
                    //out of bound
                    break;
                }
                if (scene.obstacleLayer.obstacles[y, x] != null)
                {
                    //obstacle
                    break;
                }
                if (i == owner.power - 1)
                {
                    retVal++;
                }
            }
            return retVal;
        }
        private void editDetonateOffsetAni(WalkDirection dir, int power)
        {
            if (dir == WalkDirection.DOWN || dir == WalkDirection.RIGHT)
            {
                throw new Exception("Direction DOWN and RIGHT does not need this animation");
            }
            DoubleAnimation ani = detonateStb[dir].Children[2] as DoubleAnimation;
            switch (dir)
            {
                case WalkDirection.LEFT:
                    ani.By = -power * scene.tileWidth;
                    break;

                case WalkDirection.UP:
                    ani.By = -power * scene.tileHeight;
                    break;

            }
            ani.Duration = TimeSpan.FromSeconds((double)power / detonateSpeed);
        }
        public RectangleWalker(IRectangleLocator rectangleLocator, WalkDirection direction)
            : this(rectangleLocator, direction, null) {

        }
        private void editDetonateViewportAni(WalkDirection dir, int power)
        {
            RectAnimation ani = detonateStb[dir].Children[1] as RectAnimation;

            switch (dir)
            {
                case WalkDirection.DOWN:
                    ani.To = new Rect(0, power * scene.tileHeight*10, scene.tileWidth, scene.tileHeight);
                    break;
                case WalkDirection.LEFT:
                    ani.To = new Rect(power * -scene.tileWidth, 0, scene.tileWidth, scene.tileHeight);
                    break;
                case WalkDirection.RIGHT:
                    ani.To = new Rect(power * scene.tileWidth, 0, scene.tileWidth, scene.tileHeight);
                    break;
                case WalkDirection.UP:
                    ani.To = new Rect(0, power * -scene.tileHeight, scene.tileWidth, scene.tileHeight);
                    break;

            }
            ani.Duration = TimeSpan.FromSeconds((double)power / detonateSpeed);
        }
 public RectangleWalker(IRectangleLocator rectangleLocator, WalkDirection direction, IPointLocator startPointLocator) {
     this.RectangleLocator = rectangleLocator;
     this.Direction = direction;
     this.StartPointLocator = startPointLocator;
 }
 public void onKick(WalkDirection dir)
 {
 }
 public static RectangleWalkEffect Walk(IRectangleLocator rl, WalkDirection direction) {
     return new RectangleWalkEffect(rl, null, direction);
 }
 public static RectangleWalkEffect Walk(IRectangleLocator rl, Corner start, WalkDirection direction) {
     return new RectangleWalkEffect(rl, null, direction, new PointOnRectangleLocator(rl, start));
 }
        public bool moveBoxOne(Box box,WalkDirection dir,Player player)
        {
            Int32Point boxPos = boxPositions[box];
            if (boxPos == null)
            {
                return false;
            }
            Int32Point newBoxPos = new Int32Point(boxPos.x, boxPos.y);
            Box neighborBox = null;
            switch (dir)
            {
                case WalkDirection.DOWN:
                    if (boxPos.y + 1 < boxes.GetLength(0) && scene.obstacleLayer.obstacles[boxPos.y+1,boxPos.x]==null)
                    {
                        if (boxes[boxPos.y + 1, boxPos.x] != null && boxes[boxPos.y + 1, boxPos.x].canKick)
                        {
                            neighborBox = boxes[boxPos.y + 1, boxPos.x];

                        }
                    }
                    else
                    {
                        return false;
                    }

                    break;
                case WalkDirection.UP:

                    if (boxPos.y - 1 >= 0 && scene.obstacleLayer.obstacles[boxPos.y - 1, boxPos.x] == null)
                    {
                        if (boxes[boxPos.y - 1, boxPos.x] != null && boxes[boxPos.y - 1, boxPos.x].canKick)
                        {
                            neighborBox = boxes[boxPos.y - 1, boxPos.x];

                        }
                    }
                    else
                    {
                        return false;
                    }

                    break;
                case WalkDirection.LEFT:
                    if (boxPos.x - 1 >= 0 && scene.obstacleLayer.obstacles[boxPos.y,boxPos.x-1]==null)
                    {
                        if (boxes[boxPos.y, boxPos.x - 1] != null && boxes[boxPos.y, boxPos.x - 1].canKick)
                        {
                            neighborBox = boxes[boxPos.y, boxPos.x - 1];
                        }
                    }
                    else
                    {
                        return false;
                    }

                    break;
                case WalkDirection.RIGHT:
                    if (boxPos.x + 1 < boxes.GetLength(1) &&  scene.obstacleLayer.obstacles[boxPos.y,boxPos.x+1]==null)
                    {
                        if (boxes[boxPos.y, boxPos.x + 1] != null && boxes[boxPos.y, boxPos.x + 1].canKick)
                        {
                            neighborBox = boxes[boxPos.y, boxPos.x + 1];
                        }
                    }
                    else
                    {
                        return false;
                    }

                    break;

            }

            if (neighborBox != null )
            {
                if (!moveBoxOne(neighborBox, dir, player))
                {
                    return false;
                }

            }

            box.canKick = false;
            DoubleAnimation ani = null;
            switch (dir)
            {
                case WalkDirection.DOWN:
                case WalkDirection.UP:
                    ani = createBoxMoveAni(box, dir, player.speed, scene.tileHeight);
                    break;
                case WalkDirection.RIGHT:
                case WalkDirection.LEFT:
                    ani = createBoxMoveAni(box, dir, player.speed, scene.tileWidth);
                    break;

            }
            Storyboard stb = new Storyboard();
            stb.Children.Add(ani);
            ani.Completed+=delegate(object sender,EventArgs e)
                {
                    switch (dir)
                    {
                        case WalkDirection.DOWN:
                            newBoxPos.y += 1;

                            break;
                        case WalkDirection.UP:
                            newBoxPos.y -= 1;

                            break;
                        case WalkDirection.LEFT:
                            newBoxPos.x -= 1;

                            break;
                        case WalkDirection.RIGHT:
                            newBoxPos.x += 1;
                            break;

                    }
                    box.RenderTransform = new TranslateTransform(0, 0);
                    box.SetValue(Grid.RowProperty,newBoxPos.y);
                    box.SetValue(Grid.ColumnProperty, newBoxPos.x);
                    boxes[boxPos.y, boxPos.x] = null;
                    boxes[newBoxPos.y, newBoxPos.x] = box;
                    boxPositions[box] = newBoxPos;
                    box.canKick = true;

                };

            stb.Begin();
            return true;
        }