Example #1
0
        public override void activate(Sprite collider)
        {
            if (collider.GetType() == typeof(Clyde))
            {
                if (collider.state == State.Airbourne)
                {
                    soundeffect.Play();
                }

                collider.Velocity = Vector2.Zero;

                collider.state = State.Swimming;
            }
            else if (collider.GetType() == typeof(Bunny))
            {
                if (collider.state == State.Airbourne || collider.state == State.Default)
                {
                    soundeffect.Play();
                }
                Bunny bunny = (Bunny)collider;
                level.bunnydead = true;

                //    bunny.Position = bunny.SpawnPoint;
                //   bunny.die.Width = bunny.mapwidth;
                //   bunny.Velocity = Vector2.Zero;
            }
        }
        public void Update(GameTime gameTime)
        {
            sum += gameTime.ElapsedGameTime;
            //Left Right Direction check
            currentKeyboard = Keyboard.GetState();
            Vector2 direction;

            InactiveCharacter.Velocity -= new Vector2(InactiveCharacter.Velocity.X, 0);
            if (currentKeyboard.IsKeyDown(Keys.Enter) || GamePad.GetState(PlayerIndex.One).Buttons.Start == ButtonState.Pressed)
            {
                worldSprites[worldSprites.Count - 2].Width = 0;
            }
            if (currentKeyboard.IsKeyDown(Keys.S))
            {
                if (bunny)
                {
                    Bunny b = (Bunny)ActiveCharacter;
                    b.SavePoint = b.Position;
                }
                else
                {
                    Bunny b = (Bunny)InactiveCharacter;
                    b.SavePoint = b.Position;
                }
            }
            if (!rKeyEdge && (currentKeyboard.IsKeyDown(Keys.R) || GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed))
            {
                rKeyEdge = true;
                this.level.restart();
            }
            else if (currentKeyboard.IsKeyUp(Keys.R) && GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Released)
            {
                rKeyEdge = false;
            }
            if (worldSprites[worldSprites.Count - 2].Width == 0)
            {
                if (currentKeyboard.IsKeyDown(Keys.Left) || GamePad.GetState(PlayerIndex.One).DPad.Left == ButtonState.Pressed)
                {
                    worldSprites[worldSprites.Count - 1].Width = 0;


                    ActiveCharacter.Velocity = new Vector2(-ActiveCharacter.Speed, ActiveCharacter.Velocity.Y);
                    if (InactiveCharacter.state == Sprite.State.Riding)
                    {
                        InactiveCharacter.Velocity = new Vector2(-ActiveCharacter.Speed, ActiveCharacter.Velocity.Y);
                    }
                }
                else if (currentKeyboard.IsKeyDown(Keys.Right) || GamePad.GetState(PlayerIndex.One).DPad.Right == ButtonState.Pressed)
                {
                    worldSprites[worldSprites.Count - 1].Width = 0;

                    ActiveCharacter.Velocity = new Vector2(ActiveCharacter.Speed, ActiveCharacter.Velocity.Y);

                    if (InactiveCharacter.state == Sprite.State.Riding)
                    {
                        InactiveCharacter.Velocity = new Vector2(ActiveCharacter.Speed, ActiveCharacter.Velocity.Y);
                    }
                }
                else
                {
                    ActiveCharacter.Velocity = new Vector2(0, ActiveCharacter.Velocity.Y);
                }

                //Switch active characters
                if ((currentKeyboard.IsKeyDown(Keys.RightShift) || currentKeyboard.IsKeyDown(Keys.LeftShift) || GamePad.GetState(PlayerIndex.One).Buttons.X == ButtonState.Pressed) && !check)
                {
                    worldSprites[worldSprites.Count - 1].Width = 0;
                    //InactiveCharacter.state = previousState;
                    Sprite temp = ActiveCharacter;
                    ActiveCharacter   = InactiveCharacter;
                    InactiveCharacter = temp;
                    check             = true;
                    level.PlayerIcon.ChangeImage();
                    //InactiveCharacter.state = Sprite.State.Default;
                    bunny = !bunny;
                }
                else if (currentKeyboard.IsKeyUp(Keys.RightShift) && currentKeyboard.IsKeyUp(Keys.LeftShift) && GamePad.GetState(PlayerIndex.One).Buttons.X == ButtonState.Released)
                {
                    check = false;
                }
                if ((currentKeyboard.IsKeyDown(Keys.Up) || GamePad.GetState(PlayerIndex.One).DPad.Up == ButtonState.Pressed))
                {
                    worldSprites[worldSprites.Count - 1].Width = 0;
                    if (ActiveCharacter.state == Sprite.State.Swimming)
                    {
                        ActiveCharacter.Velocity += new Vector2(0, -ActiveCharacter.Speed);
                    }
                }
                if ((currentKeyboard.IsKeyDown(Keys.Down) || GamePad.GetState(PlayerIndex.One).DPad.Down == ButtonState.Pressed))
                {
                    worldSprites[worldSprites.Count - 1].Width = 0;

                    if (ActiveCharacter.state == Sprite.State.Swimming)
                    {
                        ActiveCharacter.Velocity += new Vector2(0, ActiveCharacter.Speed);
                    }
                }
                //Vertical position change



                if ((currentKeyboard.IsKeyDown(Keys.Space) || GamePad.GetState(PlayerIndex.One).Buttons.A == ButtonState.Pressed) && (ActiveCharacter.state == Sprite.State.Default || ActiveCharacter.state == Sprite.State.Riding))
                {
                    worldSprites[worldSprites.Count - 1].Width = 0;

                    if (bunny)
                    {
                        sounds[0].Play(0.3f, 0, 0);
                    }
                    else
                    {
                        sounds[1].Play();
                    }
                    ActiveCharacter.state     = Sprite.State.Airbourne;
                    ActiveCharacter.Velocity -= new Vector2(0, ActiveCharacter.jump);
                }
                if (InactiveCharacter.state == Sprite.State.Riding)
                {
                    InactiveCharacter.Velocity = ActiveCharacter.Velocity;
                }
                if (ActiveCharacter.state == Sprite.State.Riding)
                {
                    ActiveCharacter.Velocity = new Vector2(ActiveCharacter.Velocity.X, InactiveCharacter.Velocity.Y);
                }

                // determine sprite animation
                if (currentKeyboard.IsKeyDown(Keys.Left) || GamePad.GetState(PlayerIndex.One).DPad.Left == ButtonState.Pressed)
                {
                    // turn left
                    if (bunny)
                    {
                        if (ActiveCharacter.currentFrame == 1 && sum.Milliseconds > 100)
                        {
                            ActiveCharacter.currentFrame = 2;
                            sum = TimeSpan.Zero;
                        }
                        else if (sum.Milliseconds > 100)
                        {
                            ActiveCharacter.currentFrame = 1;
                            sum = TimeSpan.Zero;
                        }
                    }
                    else
                    {
                        if (ActiveCharacter.currentFrame == 3 && sum.Milliseconds > 100)
                        {
                            ActiveCharacter.currentFrame = 2;
                            sum = TimeSpan.Zero;
                        }
                        else if (sum.Milliseconds > 100)
                        {
                            ActiveCharacter.currentFrame = 3;
                            sum = TimeSpan.Zero;
                        }
                    }
                }
                else if (currentKeyboard.IsKeyDown(Keys.Right) || GamePad.GetState(PlayerIndex.One).DPad.Right == ButtonState.Pressed)
                {
                    // turn right
                    if (bunny)
                    {
                        if (ActiveCharacter.currentFrame == 4 && sum.Milliseconds > 100)
                        {
                            ActiveCharacter.currentFrame = 3;
                            sum = TimeSpan.Zero;
                        }
                        else if (sum.Milliseconds > 100)
                        {
                            ActiveCharacter.currentFrame = 4;
                            sum = TimeSpan.Zero;
                        }
                    }
                    else
                    {
                        if (ActiveCharacter.currentFrame == 0 && sum.Milliseconds > 100)
                        {
                            ActiveCharacter.currentFrame = 1;
                            sum = TimeSpan.Zero;
                        }
                        else if (sum.Milliseconds > 100)
                        {
                            ActiveCharacter.currentFrame = 0;
                            sum = TimeSpan.Zero;
                        }
                    }
                }
                if (ActiveCharacter.state == Sprite.State.Airbourne) // jumping
                {
                    // jump
                    if (bunny)
                    {
                        if (ActiveCharacter.currentFrame == 4 || ActiveCharacter.currentFrame == 3 || ActiveCharacter.currentFrame == 5)
                        {
                            ActiveCharacter.currentFrame = 5;
                        }
                        else
                        {
                            ActiveCharacter.currentFrame = 0;
                        }
                    }
                    else
                    {
                        if (ActiveCharacter.currentFrame == 0 || ActiveCharacter.currentFrame == 1 || ActiveCharacter.currentFrame == 4)
                        {
                            ActiveCharacter.currentFrame = 4;
                        }
                        else
                        {
                            ActiveCharacter.currentFrame = 7;
                        }
                    }
                }
                if (ActiveCharacter.state != Sprite.State.Airbourne)
                {
                    // land from jump
                    if (bunny)
                    {
                        if (ActiveCharacter.currentFrame == 5)
                        {
                            ActiveCharacter.currentFrame = 3;
                        }
                        else if (ActiveCharacter.currentFrame == 0)
                        {
                            ActiveCharacter.currentFrame = 1;
                        }
                    }
                    else
                    {
                        if (ActiveCharacter.currentFrame == 4)
                        {
                            ActiveCharacter.currentFrame = 0;
                        }
                        else if (ActiveCharacter.currentFrame == 7)
                        {
                            ActiveCharacter.currentFrame = 3;
                        }
                    }
                }
            }



            /*
             * if (ActiveCharacter.HitBox.Intersects(worldSprites[0].HitBox))
             * {
             *  worldSprites[0].Position = new Vector2(12, 20);
             * }
             *
             * if (ActiveCharacter.HitBox.Intersects(worldSprites[1].HitBox) && InactiveCharacter.HitBox.Intersects(worldSprites[1].HitBox) && worldSprites[0].Position.X == 12 && worldSprites[0].Position.Y == 20)
             * {
             *  ActiveCharacter.Position = new Vector2(50, 325);
             *  InactiveCharacter.Position = new Vector2(60, 325);
             *  worldSprites[0].Position = new Vector2(352, 238);
             *
             * }
             */
            //create test positions

            /*
             * Vector2 newPosition;// = ActiveCharacter.Position + (ActiveCharacter.Speed * direction);
             * //Console.WriteLine("Inactive= " + InactiveCharacter.Velocity);
             * //Console.WriteLine("Inactive= " + ActiveCharacter.Velocity);
             * //Checks for collision and determines if position should be changed
             * if (!checkScreenEdgeCollision(newPosition) && !checkPlatformCollision(newPosition, Platforms))
             * {
             *  ActiveCharacter.Position = newPosition;
             *  if (ActiveCharacter.Velocity.Y >= 0)
             *  {
             *      ActiveCharacter.state = Sprite.State.Airbourne;
             *  }
             * }
             * else if (checkScreenEdgeCollision(newPosition) && !checkPlatformCollision(newPosition, Platforms))
             * {
             *  float newY = newPosition.Y;
             *  float currentX = ActiveCharacter.Position.X;
             *  newPosition = new Vector2(currentX, newY);
             *  ActiveCharacter.Position = newPosition;
             *  if (ActiveCharacter.Velocity.Y >= 0)
             *  {
             *      ActiveCharacter.state = Sprite.State.Airbourne;
             *  }
             * }
             */
            //checkItemCollision();
        }