Example #1
0
        public override void Update(GameTime gameTime, World world, Player player)
        {
            if (frame_cooldown > 0)
            {
                frame_cooldown -= 1;
            }

            if (player.Hurtbox.Intersects(Hurtbox))
            {
                if (player.Velocity.Y > 1) // player rifght above ruche falling
                {
                    if (frame_cooldown == 0)
                    {
                        frame_cooldown = 10;
                    }
                    if (frame_cooldown > 6)
                    {
                        player.Velocity.Y *= 0.7f;
                    }
                    if (frame_cooldown == 6)
                    {
                        player.Velocity.Y   = -12;
                        player.CurrentState = Player.PlayerState.jump;
                        SoundEffectPlayer.Play(jump);
                    }
                }
            }
            else if (player.Hurtbox.Intersects(Hurtbox))
            {
                player.Bump(this);
            }

            if (frame_cooldown > 6)
            {
                CurrentSprite = ruche2;
            }
            else if (frame_cooldown > 0)
            {
                CurrentSprite = ruche3;
                if (bee_count > 0)
                {
                    bee_count -= 1;
                    Bee b = new Bee(FeetPosition + new Vector2(-direction * 50, 0),
                                    new Vector2(-direction * r.Next(14, 25), r.Next(-2, 3))); // use (r.Next(0,2) * 2 - 1) to random -1 or 1
                    // b.Velocity = new Vector2(-10, 0);
                    world.NewStuff.Add(b);
                }
            }
            else
            {
                CurrentSprite = ruche1;
            }
            base.Update(gameTime, world, player);
        }
Example #2
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
#if DEBUG
            KeyboardState ks = Keyboard.GetState();
            if (ks.IsKeyDown(Keys.D))
            {
                CameraDestination.X += 8;
            }
            if (ks.IsKeyDown(Keys.Q))
            {
                CameraDestination.X -= 8;
            }
            if (ks.IsKeyDown(Keys.Z))
            {
                CameraDestination.Y -= 8;
            }
            if (ks.IsKeyDown(Keys.S))
            {
                CameraDestination.Y += 8;
            }
            if (ks.IsKeyDown(Keys.NumPad9))
            {
                Zoom *= 1.05f;
            }
            if (ks.IsKeyDown(Keys.NumPad8))
            {
                Zoom *= 0.95f;
            }
#endif
            if (!world.Bounds.Contains(ViewRectangle)) // camera oob
            {
                CameraPosition         = world.Bounds.Location.ToVector2();
                ViewRectangle.Location = world.Bounds.Location;
                CameraDestination      = CameraPosition;
            }
            //else

            if (player.Hurtbox.Center.X > ViewRectangle.Center.X && player.PlayerDirection == 1)
            {
                MoveCamera(new Vector2(10, 0));
                Console.WriteLine("move camera to the right");
            }
            else if (player.Hurtbox.Center.X < ViewRectangle.Center.X && player.PlayerDirection == -1)
            {
                MoveCamera(new Vector2(-10, 0));
                Console.WriteLine("move camera to the left");
            }

            if (player.Hurtbox.Center.Y < ViewRectangle.Center.Y - 100)
            {
                MoveCamera(new Vector2(0, -10));
                Console.WriteLine("move camera up");
            }
            else if (player.Hurtbox.Center.Y > ViewRectangle.Center.Y + 100)
            {
                MoveCamera(new Vector2(0, 10));
                Console.WriteLine("move camera down");
            }



            CameraPosition         = CameraPosition * 0.5f + CameraDestination * 0.5f;
            Camera                 = Matrix.CreateScale(Zoom) * Matrix.CreateTranslation(Zoom * (-CameraPosition.X), Zoom * (-CameraPosition.Y), 0);;
            ViewRectangle          = new Rectangle(0, 0, 1280, 720);
            ViewRectangle.Location = Vector2.Transform(ViewRectangle.Location.ToVector2(), Matrix.Invert(Camera)).ToPoint();
            ViewRectangle.Size     = (ViewRectangle.Size.ToVector2() * 1 / Zoom).ToPoint();
            //ViewRectangle.Inflate(-128 * 1/Zoom, -72 * 1/Zoom);



            player.Update(gameTime, world, player);
            world.Update(gameTime, player);
            Input.Update(Keyboard.GetState());
            SoundEffectPlayer.Update();

            if (world.levelIndex == 8)
            {
                Exit();
            }
            base.Update(gameTime);
        }
Example #3
0
        public override void Update(GameTime gameTime, World world, Player player)
        {
            this.world = world;
            KeyboardState KbState = Keyboard.GetState();

            if (PreviousState == CurrentState)
            {
                state_frames += 1;
            }
            else
            {
                state_frames = 0;
            }
            PreviousState = CurrentState;

            switch (CurrentState)
            {
            case PlayerState.idle:
                /*if (KbState.IsKeyDown(Input.Left) && KbState.IsKeyUp(Input.Right))
                 * {
                 *  if (Velocity.X > -MaxSpeed)
                 *      ApplyForce(new Vector2(-2f, 0));
                 *  CurrentState = PlayerState.walk;
                 * } else if (KbState.IsKeyDown(Input.Right))
                 * {
                 *  if (Velocity.X < MaxSpeed)
                 *      ApplyForce(new Vector2(2f, 0));
                 *  CurrentState = PlayerState.walk;
                 * }*/
                if (!IsOnGround(world))
                {
                    CurrentState = PlayerState.jump;
                }
                else if (Input.direction != 0)
                {
                    CurrentState = PlayerState.walk;
                }
                else if (KbState.IsKeyDown(Input.Jump))
                {
                    ApplyForce(new Vector2(0, -15f));
                    SoundEffectPlayer.Play(jump, 1f, 0f);
                    if (Input.direction != 0)
                    {
                        PlayerDirection = Input.direction;
                    }
                    CurrentState = PlayerState.jump;
                }
                break;

            case PlayerState.walk:
                if (KbState.IsKeyDown(Input.Jump))
                {
                    // Velocity = 0;
                    if (Input.direction != 0)
                    {
                        PlayerDirection = Input.direction;
                    }
                    ApplyForce(new Vector2(0, -15f));
                    SoundEffectPlayer.Play(jump, 1f, 0f);
                    CurrentState = PlayerState.jump;
                }
                else if (!IsOnGround(world))
                {
                    CurrentState = PlayerState.jump;
                }
                else if (Input.direction != 0)     // player is inputing a direction (either left or right)
                {
                    PlayerDirection = Input.direction;
                    if (Math.Sign(Velocity.X) * Math.Sign(Input.direction) >= 0) // if inputed direction is the same as current movement direction
                    {
                        if (Velocity.X * Velocity.X < MaxSpeed * MaxSpeed)       // if norm of velocity below max speed
                        {
                            ApplyForce(new Vector2(Input.direction * 5f, 0));
                        }
                    }
                    else     // if player is inputing the direction against the current movement (brake)
                    {
                        ApplyForce(new Vector2(Input.direction * 5f, 0));
                    }
                }
                else
                {
                    CurrentState = PlayerState.idle;
                }
                break;

            case PlayerState.jump:
                if (Velocity.Y < 0 && Velocity.X != 0)
                {
                    PlayerDirection = Math.Sign(Velocity.X);                                        // raising
                }
                if (KbState.IsKeyDown(Input.Jump) && !prevKbState.IsKeyDown(Input.Jump))
                {
                    Velocity.Y = 0;
                    //if (Input.direction == 0)
                    SoundEffectPlayer.Play(jump, 1f, 0.5f);
                    ApplyForce(new Vector2(0, -15));
                    //else
                    //{
                    //  PlayerDirection = Input.direction;
                    //  ApplyForce(new Vector2(Input.direction * 50, -8));
                    //  }
                    CurrentState = PlayerState.doublejump;
                }
                else if (Input.direction != 0)     // player is inputing a direction (either left or right)
                {
                    if ((Velocity.X + Input.direction) * Math.Sign(Velocity.X) <= MaxSpeed)
                    {
                        ApplyForce(new Vector2(Input.direction * 5f, 0));
                    }
                }
                if (IsOnGround(world))
                {
                    CurrentState = PlayerState.idle;
                }
                break;

            case (PlayerState.doublejump):
            {
                if (Velocity.Y < 0 && Velocity.X != 0)
                {
                    PlayerDirection = Math.Sign(Velocity.X);                                            // raising
                }
                if (IsOnGround(world))
                {
                    CurrentState = PlayerState.idle;
                }
                else if (Input.direction != 0)         // player is inputing a direction (either left or right)
                {
                    if ((Velocity.X + Input.direction) * Math.Sign(Velocity.X) <= MaxSpeed)
                    {
                        ApplyForce(new Vector2(Input.direction * 5f, 0));
                    }
                }
                break;
            }

            case (PlayerState.flip):
            {
                if (CurrentSprite.isOver && state_frames > 200)
                {
                    world.NextLevel(this);        //do something like next level;
                    CurrentState = PlayerState.idle;
                }
                break;
            }
            }
            //
            // SPRITE DETERMINATION
            //
            PreviousSprite = CurrentSprite;
            switch (CurrentState)
            {
            case (PlayerState.idle):
            {
                if (Velocity.X * Velocity.X < 1)
                {
                    CurrentSprite = idle;
                }
                else
                {
                    CurrentSprite = brake;
                }
                break;
            }

            case (PlayerState.walk):
            {
                CurrentSprite = run;
                break;
            }

            case (PlayerState.jump):
            {
                if (Velocity.Y < -1)
                {
                    CurrentSprite = rise;
                }
                else if (Velocity.Y > 1)
                {
                    CurrentSprite = fall;
                }
                else
                {
                    CurrentSprite = top;
                }
                break;
            }

            case (PlayerState.doublejump):
            {
                if (Velocity.Y < 3)
                {
                    CurrentSprite = roll;
                }
                else
                {
                    CurrentSprite = fall;
                }
                break;
            }

            case (PlayerState.flip):
            {
                CurrentSprite = flip;
                break;
            }
            }

            /*if (Input.double_tap_waiting && IsOnGround(world) && CurrentSprite != slug_walk)
             * {
             *  CurrentSprite = slug_charge_attack;
             *  PlayerDirection = Input.direction;
             * }*/

            if (CurrentSprite != PreviousSprite)
            {
                CurrentSprite.ResetAnimation();
                //Console.WriteLine("Switched to sprite " + CurrentSprite.Texture.Name);
            }
            CurrentSprite.direction = PlayerDirection;
            CurrentSprite.UpdateFrame(gameTime);

            foreach (PhysicalObject o in world.Stuff)
            {
                if (o is Bee b)
                {
                    b.AttractFromPlayer(this);
                    if (Hurtbox.Intersects(b.Hurtbox))
                    {
                        //Console.WriteLine("collision between bee and player");
                        world.RemovedStuff.Add(b);
                        SoundEffectPlayer.Play(bee_collected, 0.08f, (float)(r.NextDouble() * 0.2));
                    }
                }
                // do something;
            }

            prevKbState = KbState;
            base.Update(gameTime, world, this);
        }