Пример #1
0
        public override void Update(GameTime gameTime, InputManager inputmanager, Collision col, Layers layer)
        {
            if (location != null)
            {
                moveAnimation.IsActive = true;
            }

            ////down
            //moveAnimation.CurrentFrame = new Vector2(moveAnimation.CurrentFrame.X, 0);
            //position.Y += moveSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
            ////up
            //moveAnimation.CurrentFrame = new Vector2(moveAnimation.CurrentFrame.X, 3);
            //position.Y -= moveSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
            ////left
            //moveAnimation.CurrentFrame = new Vector2(moveAnimation.CurrentFrame.X, 1);
            //position.X -= moveSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
            ////right
            //moveAnimation.CurrentFrame = new Vector2(moveAnimation.CurrentFrame.X, 2);
            //position.X += moveSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;

            //Auto Motion Planning - make input avaliable to go anywhere from last node to next node
            if (location != null)
            {
                //if (inputmanager.KeyReleased())
                //{
                if (goal.y < location.y)
                {
                    moveAnimation.CurrentFrame = new Vector2(moveAnimation.CurrentFrame.X, 3);
                    position.Y -= moveSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
                    if (goal.y == location.y)
                    {
                        moveAnimation.IsActive = false;
                    }
                }
                else if (goal.y > location.y)
                {
                    moveAnimation.CurrentFrame = new Vector2(moveAnimation.CurrentFrame.X, 0);
                    position.Y += moveSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
                    if (goal.y == location.y)
                    {
                        moveAnimation.IsActive = false;
                    }
                }

                else if (goal.x < location.x)
                {
                    moveAnimation.CurrentFrame = new Vector2(moveAnimation.CurrentFrame.X, 1);
                    position.X -= moveSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
                    if (goal.x == location.x)
                    {
                        moveAnimation.IsActive = false;
                    }
                }
                else if (goal.x > location.x)
                {
                    moveAnimation.CurrentFrame = new Vector2(moveAnimation.CurrentFrame.X, 2);
                    position.X += moveSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
                    if (goal.x == location.x)
                    {
                        moveAnimation.IsActive = false;
                    }
                }
                else if (goal.x == location.x && goal.y == location.y)
                {
                    moveAnimation.CurrentFrame = new Vector2(0, 0);
                    position.X             = position.X;
                    position.Y             = position.Y;
                    moveAnimation.IsActive = false;
                }
                //}
                if (moveAnimation.IsActive)
                {
                    // Update step and setup for next
                    moveAnimation.Position = position;
                    moveAnimation.Update(gameTime);
                }
            }

            //position updating
            {
                if (!(position.X == 160 && position.Y == 1120) && health > 0)
                {
                    tracker++;

                    if ((tracker / 32) + 1 == Steps[n].Count)
                    {
                        n++;
                        health--;
                        tracker = 0;

                        if (n < 4)
                        {
                            Waypoint(notes[n], notes[n + 1]);
                        }
                        else
                        {
                            moveAnimation.IsActive = false;
                            goal     = null;
                            location = null;
                        }

                        Steps[n - 1] = null;
                    }
                    if (health > 0)
                    {
                        location = (Node)Steps[n][tracker / 32];
                        //if (inputmanager.KeyPressed(Keys.Left))
                        //    goal = (Node)Steps[n][(tracker / 32) - 1];
                        //else
                        goal = (Node)Steps[n][(tracker / 32) + 1];
                    }
                    else
                    {
                        location = null;
                        goal     = null;
                        //throw new ArgumentOutOfRangeException("",e);
                    }
                }
            }

            ////Collision
            //for (int i = 0; i < col.CollisionMap.Count; i++)
            //{
            //    for (int j = 0; j < col.CollisionMap[i].Count; j++)
            //    {
            //        if (col.CollisionMap[i][j] == "b")
            //        {
            //            if (position.X + moveAnimation.FrameWidth < j * layer.TileDimensions.X ||
            //                position.X > j * layer.TileDimensions.X + layer.TileDimensions.X ||
            //                position.Y + moveAnimation.FrameHeight < i * layer.TileDimensions.Y ||
            //                position.Y > i * layer.TileDimensions.Y + layer.TileDimensions.Y)
            //            {
            //                // no collision
            //                drop = false;
            //                nodeTouch = false;
            //            }
            //            else
            //            {
            //                if (((location.x == A.x) || (location.x == B.x) || (location.x == C.x) || (location.x == D.x))
            //                    && ((location.y == A.y) || (location.y == B.y) || (location.y == C.y) || (location.y == D.y)))
            //                {
            //                    nodeTouch = true;
            //                    //health = health - 1;

            //                    if (nodeTouch && !drop)
            //                    {
            //                        drop = true;
            //                        health = health - 1;
            //                        nodeTouch = false;


            //                    }
            //                }
            //                else
            //                    drop = false;
            //            }
            //        }

            // if (col.CollisionMap[i][j] == "n")
            //{
            //    if (position.X + moveAnimation.FrameWidth < j * layer.TileDimensions.X ||
            //        position.X > j * layer.TileDimensions.X + layer.TileDimensions.X ||
            //        position.Y + moveAnimation.FrameHeight < i * layer.TileDimensions.Y ||
            //        position.Y > i * layer.TileDimensions.Y + layer.TileDimensions.Y)
            //    {
            //        // no collision
            //        drop = false;
            //        nodeTouch = false;
            //    }
            //    else
            //    {

            //    }

            //    }
            //}
        }
Пример #2
0
 public override void Update(GameTime gameTime, InputManager inputmanager, Collision col, Layers layer)
 {
     base.Update(gameTime, inputmanager, col, layer);
     moveAnimation.IsActive = true;
     if (inputmanager.KeyDown(Keys.Left, Keys.A))
     {
         //moveAnimation.CurrentFrame = new Vector2(moveAnimation.CurrentFrame.X, 1);
         position.X -= moveSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
     }
     else if (inputmanager.KeyDown(Keys.Right, Keys.D))
     {
         //moveAnimation.CurrentFrame = new Vector2(moveAnimation.CurrentFrame.X, 1);
         position.X += moveSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
     }
     else
     {
         moveAnimation.IsActive = false;
     }
     moveAnimation.Position = position;
     moveAnimation.Update(gameTime);
 }