Exemple #1
0
 public void IsKeyDown()
 {
     if (player[0].Direction != new Vector2(0, 0))
     {
         if (StaticKeyboard.IsKeyDown(Keys.W) && player[0].LastDirection.Y != 1)
         {
             player[0].Direction = new Vector2(0, -1);
         }
         if (StaticKeyboard.IsKeyDown(Keys.S) && player[0].LastDirection.Y != -1)
         {
             player[0].Direction = new Vector2(0, 1);
         }
         if (StaticKeyboard.IsKeyDown(Keys.A) && player[0].LastDirection.X != 1)
         {
             player[0].Direction = new Vector2(-1, 0);
         }
         if (StaticKeyboard.IsKeyDown(Keys.D) && player[0].LastDirection.X != -1)
         {
             player[0].Direction = new Vector2(1, 0);
         }
         if (multiplayer)
         {
             if (StaticKeyboard.IsKeyDown(Keys.Up) && player[1].LastDirection.Y != 1)
             {
                 player[1].Direction = new Vector2(0, -1);
             }
             else if (StaticKeyboard.IsKeyDown(Keys.Down) && player[1].LastDirection.Y != -1)
             {
                 player[1].Direction = new Vector2(0, 1);
             }
             else if (StaticKeyboard.IsKeyDown(Keys.Left) && player[1].LastDirection.X != 1)
             {
                 player[1].Direction = new Vector2(-1, 0);
             }
             else if (StaticKeyboard.IsKeyDown(Keys.Right) && player[1].LastDirection.X != -1)
             {
                 player[1].Direction = new Vector2(1, 0);
             }
         }
     }
 }
Exemple #2
0
        public override void Update()
        {
            if (Healthpoints <= 0)
            {
                MessageBox.Show("Game Over!: You died");
            }
            else
            {
                if (StaticKeyboard.IsKeyDown(Keys.W) && _currentWalkDir == WalkDirection.None)
                {
                    _currentWalkDir = WalkDirection.Jump;
                }
                if (StaticKeyboard.IsKeyDown(Keys.A))
                {
                    _currentWalkDir  = WalkDirection.Left;
                    _watchDir        = WatchDirection.Left;
                    _DeltaJumpHeight = 0;
                }
                if (StaticKeyboard.IsKeyDown(Keys.D))
                {
                    _currentWalkDir  = WalkDirection.Right;
                    _watchDir        = WatchDirection.Right;
                    _DeltaJumpHeight = 0;
                }

                // Gravity
                if (_hitbox.Y < Hitbox.Y + StaticDisplay.DisplayHeight / 2)
                {
                    _hitbox.Y += Gravity * (float)StaticDisplay.FixedDelta;
                }

                // Animation on Jumping
                if (_currentWalkDir == WalkDirection.Jump)
                {
                    Gravity = 12;
                    if (_DeltaJumpHeight < maxJumpHeight)
                    {
                        _DeltaJumpHeight += 25 * (int)StaticDisplay.FixedDelta;
                        _hitbox.Y        -= 25 * (float)StaticDisplay.FixedDelta;
                    }
                    else if (_hitbox.Bottom >= StaticDisplay.DisplayHeight - 70 || IsCollision())
                    {
                        _DeltaJumpHeight = 0;
                        _currentWalkDir  = WalkDirection.None;
                        return;
                    }
                }

                // Animation when running to the right
                if (_currentWalkDir == WalkDirection.Right)
                {
                    if (_DeltaWalk < maxWalkWidth)
                    {
                        Textures.MobBitmaps.TryGetValue("HumanRightWalk", out Bitmap bitmap);
                        {
                            CurrentTexture = bitmap;
                        }
                        _DeltaWalk += 7 * (int)StaticDisplay.FixedDelta;
                        _hitbox.X  += 7 * (int)StaticDisplay.FixedDelta;
                    }
                    else
                    {
                        Textures.MobBitmaps.TryGetValue("HumanRight", out Bitmap bitmap);
                        {
                            CurrentTexture = bitmap;
                        }
                        _DeltaWalk      = 0;
                        _currentWalkDir = WalkDirection.None;
                    }
                }

                // Animation when running to the left
                if (_currentWalkDir == WalkDirection.Left)
                {
                    if (_DeltaWalk < maxWalkWidth)
                    {
                        Textures.MobBitmaps.TryGetValue("HumanLeftWalk", out Bitmap bitmap);
                        {
                            CurrentTexture = bitmap;
                        }
                        _DeltaWalk += 7 * (int)StaticDisplay.FixedDelta;
                        _hitbox.X  -= 7 * (int)StaticDisplay.FixedDelta;
                    }
                    else
                    {
                        Textures.MobBitmaps.TryGetValue("HumanLeft", out Bitmap bitmap);
                        {
                            CurrentTexture = bitmap;
                        }
                        _DeltaWalk      = 0;
                        _currentWalkDir = WalkDirection.None;
                    }
                }
            }
        }