Exemple #1
0
        private void FireKeyboardEvents()
        {
            foreach (var key in KeyList)
            {
                // Is the key currently down?
                if (CurrentKeyboardState.IsKeyDown(key))
                {
                    // Fire the OnKeyDown event
                    if (OnKeyDown != null)
                    {
                        OnKeyDown(this, new KeyboardEventArgs(key, CurrentKeyboardState,
                                                              PrevKeyboardState));
                    }
                }

                // Has the key been released? (Was down and is now up)
                if (PrevKeyboardState.IsKeyDown(key) && CurrentKeyboardState.IsKeyUp(key))
                {
                    // Fire the OnKeyUp event
                    if (OnKeyUp != null)
                    {
                        OnKeyUp(this, new KeyboardEventArgs(key, CurrentKeyboardState, PrevKeyboardState));
                    }
                }

                // Has the key been pressed? (Was up and is now down)
                if (PrevKeyboardState.IsKeyUp(key) && CurrentKeyboardState.IsKeyDown(key))
                {
                    if (OnKeyPressed != null)
                    {
                        OnKeyPressed(this, new KeyboardEventArgs(key, CurrentKeyboardState, PrevKeyboardState));
                    }
                }
            }
        }
Exemple #2
0
        private void FireKeyboardEvents()
        {
            // Check through each key in the key list
            foreach (Keys key in KeyList)
            {
                // Is the key currently down?
                if (CurrentKeyboardState.IsKeyDown(key))
                {
                    // Fire the OnKeyDown event
                    OnKeyDown?.Invoke(this, new KeyboardEventArgs(key, CurrentKeyboardState, PrevKeyboardState));
                }

                // Has the key been released? (Was down and is now up)
                if (PrevKeyboardState.IsKeyDown(key) && CurrentKeyboardState.IsKeyUp(key))
                {
                    OnKeyUp?.Invoke(this, new KeyboardEventArgs(key, CurrentKeyboardState, PrevKeyboardState));
                }

                // Has the key been pressed? (Was up and is now down)
                if (PrevKeyboardState.IsKeyUp(key) && CurrentKeyboardState.IsKeyDown(key))
                {
                    OnKeyPressed?.Invoke(this, new KeyboardEventArgs(key, CurrentKeyboardState, PrevKeyboardState));
                }
            }
        }
        private void FireKeyboardEvents()
        {
            foreach (Keys key in KeyList)
            {
                if (CurrentKeyboardState.IsKeyDown(key))
                {
                    if (OnKeyDown != null)
                    {
                        OnKeyDown(this, new KeyboardEventArgs(key, CurrentKeyboardState, PrevKeyboardState));
                    }
                }

                if (PrevKeyboardState.IsKeyDown(key) && CurrentKeyboardState.IsKeyUp(key))
                {
                    if (OnKeyUp != null)
                    {
                        OnKeyUp(this, new KeyboardEventArgs(key, CurrentKeyboardState, PrevKeyboardState));
                    }
                }

                if (PrevKeyboardState.IsKeyUp(key) && CurrentKeyboardState.IsKeyDown(key))
                {
                    if (OnKeyPressed != null)
                    {
                        OnKeyPressed(this, new KeyboardEventArgs(key, CurrentKeyboardState, PrevKeyboardState));
                    }
                }
            }
        }
Exemple #4
0
 public bool KeyDown(Keys key)
 {
     if (active)
     {
         return(CurrentKeyboardState.IsKeyDown(key));
     }
     return(false);
 }
Exemple #5
0
        /// <summary>
        /// 是否按了某个键
        /// </summary>
        /// <param name="key"></param>

        public static bool IsKeyPressed(Keys key)
        {
            if (previousKeyboardState.IsKeyUp(key) && CurrentKeyboardState.IsKeyDown(key))
            {
                return(true);
            }
            return(false);
        }
Exemple #6
0
        /// <summary>
        /// Used for determining if a keyType is being pressed.
        /// </summary>
        /// <param name="key">Key to check if pressed.</param>
        /// <returns>Returns true if keyType is down.</returns>
        public static bool KeyPressed(Keys key)
        {
            if (_active && CurrentKeyboardState.IsKeyDown(key))
            {
                return(true);
            }

            return(false);
        }
        /// <summary>
        /// returns true when a key was pressed once
        /// </summary>
        /// <returns></returns>
        public bool KeyPressed(Keys key)
        {
            if (CurrentKeyboardState.IsKeyDown(key) && PrevioKeyboardState.IsKeyUp(key))
            {
                return(true);
            }

            return(false);
        }
Exemple #8
0
        //überprüft tastaturinput und schreib sie in den string, gibt über Flags zurück welche Tasten gedrückt wurden (im moment nur Enter)
        static public byte WriteInput(ref string changingText)
        {
            Keys[] lk           = LastKeyboardState.GetPressedKeys();
            Keys[] ck           = CurrentKeyboardState.GetPressedKeys();
            Keys[] k            = ck.Except(lk).ToArray();
            byte   code         = 0;
            string tmpstring    = "";
            bool   shiftpressed = CurrentKeyboardState.IsKeyDown(Keys.RightShift) || CurrentKeyboardState.IsKeyDown(Keys.LeftShift);
            bool   backpressed  = false;

            for (int i = 0; i < k.Length; i++)
            {
                switch (k[i])
                {
                case Keys.Back: backpressed = true;
                    break;

                case Keys.OemPeriod: tmpstring += ".";
                    break;

                case Keys.Space: tmpstring += " ";
                    break;

                //Enter Flag Setzen
                case Keys.Enter: code |= 0x01;
                    break;

                case Keys.LeftShift:
                case Keys.RightShift: shiftpressed = true;
                    break;

                default:
                    //Buchstabe zum string hinzufügen fall er sich im erlaubten Ascii bereich befindet
                    if ((int)k[i] > 32 && (int)k[i] < 128)
                    {
                        tmpstring += (char)k[i];
                    }
                    break;
                }
            }
            if (!shiftpressed)
            {
                changingText += tmpstring.ToLower();
            }
            else
            {
                changingText += tmpstring.ToUpper();
            }

            if (backpressed && changingText != "")
            {
                //Lösche Letztes Zeichen
                changingText = changingText.Substring(0, changingText.Length - 1);
            }
            return(code);
        }
Exemple #9
0
        /// <summary>
        ///     Handles input for quitting the game.
        /// </summary>
        private void HandleInput()
        {
            CurrentKeyboardState = Keyboard.GetState();

            // Check for exit.
            if (CurrentKeyboardState.IsKeyDown(Keys.Escape))
            {
                Exit();
            }
        }
Exemple #10
0
 /// <summary>
 /// Wurde die aktuelle Taste gedrückt und war sie im letzten Frame nicht gedrückt?
 /// </summary>
 public bool KeyPressed(Keys key)
 {
     // Is the key down?
     if (CurrentKeyboardState.IsKeyDown(key))
     {
         // If not down last update, key has just been pressed.
         if (!PreviousKeyboardState.IsKeyDown(key))
         {
             return(true);
         }
     }
     return(false);
 }
Exemple #11
0
 /// <summary>
 /// Wurde die aktuelle Taste losgelassen und war sie im letzten Frame noch gedrückt?
 /// </summary>
 public bool KeyReleased(Keys key)
 {
     // Is the key up?
     if (!CurrentKeyboardState.IsKeyDown(key))
     {
         // If down last update, key has just been released.
         if (PreviousKeyboardState.IsKeyDown(key))
         {
             return(true);
         }
     }
     return(false);
 }
Exemple #12
0
        internal bool IsKeyReleased(Keys key)
        {
            if (key == Keys.None)
            {
                return(true);
            }

            if (CurrentKeyboardState == null || PreviousKeyboardState == null)
            {
                return(false);
            }

            return((!CurrentKeyboardState.IsKeyDown(key)) && (PreviousKeyboardState.IsKeyDown(key)));
        }
Exemple #13
0
 //Gibt die Zahl der Taste zurück die gerade losgelassen wurde, bei mehreren wird die niedrigere Zurückgegeben
 //0 Entspricht 10!
 //Falls keine Zahlentaste (!)  gedrückt wurde wird -1 zurückgeben
 //Zahlentasten des NumPads werden nicht berücksichtigt
 static public int GetNumberPressed()
 {
     if (!LastKeyboardState.IsKeyDown(Keys.D1) && CurrentKeyboardState.IsKeyDown(Keys.D1))
     {
         return(1);
     }
     if (!LastKeyboardState.IsKeyDown(Keys.D2) && CurrentKeyboardState.IsKeyDown(Keys.D2))
     {
         return(2);
     }
     if (!LastKeyboardState.IsKeyDown(Keys.D3) && CurrentKeyboardState.IsKeyDown(Keys.D3))
     {
         return(3);
     }
     if (!LastKeyboardState.IsKeyDown(Keys.D4) && CurrentKeyboardState.IsKeyDown(Keys.D4))
     {
         return(4);
     }
     if (!LastKeyboardState.IsKeyDown(Keys.D5) && CurrentKeyboardState.IsKeyDown(Keys.D5))
     {
         return(5);
     }
     if (!LastKeyboardState.IsKeyDown(Keys.D6) && CurrentKeyboardState.IsKeyDown(Keys.D6))
     {
         return(6);
     }
     if (!LastKeyboardState.IsKeyDown(Keys.D7) && CurrentKeyboardState.IsKeyDown(Keys.D7))
     {
         return(7);
     }
     if (!LastKeyboardState.IsKeyDown(Keys.D8) && CurrentKeyboardState.IsKeyDown(Keys.D8))
     {
         return(8);
     }
     if (!LastKeyboardState.IsKeyDown(Keys.D9) && CurrentKeyboardState.IsKeyDown(Keys.D9))
     {
         return(9);
     }
     if (!LastKeyboardState.IsKeyDown(Keys.D0) && CurrentKeyboardState.IsKeyDown(Keys.D0))
     {
         return(10);
     }
     return(-1);
 }
        //
        // Events that should be fired based on the interaction/input received

        private void FireKeyboardEvents()
        {
            foreach (Keys key in KeyList)
            {
                // Is key currently down?
                if (CurrentKeyboardState.IsKeyDown(key))
                {
                    OnKeyDown?.Invoke(key);
                }

                // Has the key been released?
                if (PrevKeyboardState.IsKeyDown(key) && CurrentKeyboardState.IsKeyUp(key))
                {
                    OnKeyUp?.Invoke(key);
                }

                // Key has been held
                if (PrevKeyboardState.IsKeyDown(key) && CurrentKeyboardState.IsKeyDown(key))
                {
                    OnKeyPressed?.Invoke(key);
                }
            }
        }
Exemple #15
0
 public static bool WasJustPressed(Keys key)
 {
     return(OldKeyboardState.IsKeyUp(key) && CurrentKeyboardState.IsKeyDown(key));
 }
Exemple #16
0
 public static bool IsKeyPressed(Keys k) => CurrentKeyboardState.IsKeyDown(k) && !OldKeyboardState.IsKeyDown(k);
Exemple #17
0
        /// <summary>
        /// Update method
        /// </summary>
        /// <param name="gameTime"></param>
        protected override void Update(GameTime gameTime)
        {
            if (this.Name == "OptionsSelectionFrame")
            {
                string currentPosition = null;

                foreach (KeyValuePair <string, Vector2> keyValuePair in optionMenuDictionary)
                {
                    if ((
                            (keyValuePair.Value.X - 20 == this.DrawLocation.X)
                            ) && (
                            (keyValuePair.Value.Y - 15 == this.DrawLocation.Y)
                            ) && (
                            (keyValuePair.Key != "OptionSelectionFrame")
                            ))
                    {
                        currentPosition = keyValuePair.Key;                                 // Find the current index of the selection bar
                    }
                }
                // Move the selection bar based on key pressed
                if (CurrentKeyboardState.IsKeyDown(Keys.Down) && PreviousKeyboardState.IsKeyUp(Keys.Down))
                {
                    SoundEffectInstances["MenuMove"].Play();

                    switch (currentPosition)
                    {
                    case "Music":
                        base.CreateRectangle(
                            (int)(optionMenuDictionary["SFX"].X - 20),
                            (int)(optionMenuDictionary["SFX"].Y - 15)
                            );

                        break;
                    }
                }
                else if (CurrentKeyboardState.IsKeyDown(Keys.Up) && PreviousKeyboardState.IsKeyUp(Keys.Up))
                {
                    SoundEffectInstances["MenuMove"].Play();

                    switch (currentPosition)
                    {
                    case "SFX":
                        base.CreateRectangle(
                            (int)(optionMenuDictionary["Music"].X - 20),
                            (int)(optionMenuDictionary["Music"].Y - 15)
                            );

                        break;
                    }
                }
                else if (CurrentKeyboardState.IsKeyDown(Keys.Right) && PreviousKeyboardState.IsKeyUp(Keys.Right))
                {
                    switch (currentPosition)
                    {
                    case "Music":
                        if (SoundEffectInstances["BackgroundMusic"].Volume < 0.9f)          // Move the side scrolling volume controls

                        {
                            SoundEffectInstances["BackgroundMusic"].Volume += 0.1f;

                            foreach (Option menuOption in OptionElements)
                            {
                                if (menuOption.Name == "MusicSlider")
                                {
                                    menuOption.CreateRectangle(                             // Adjust the volume
                                        (int)(optionMenuDictionary["MusicSlider"].X + 10),
                                        (int)(optionMenuDictionary["MusicSlider"].Y)
                                        );

                                    optionMenuDictionary["MusicSlider"] = new Vector2(
                                        (int)(optionMenuDictionary["MusicSlider"].X + 10),
                                        (int)(optionMenuDictionary["MusicSlider"].Y)
                                        );

                                    SoundEffectInstances["MenuMove"].Play();
                                }
                            }
                        }
                        else
                        {
                            SoundEffectInstances["Error"].Play();
                        }

                        break;

                    case "SFX":
                        bool movedSlider = false;

                        foreach (KeyValuePair <string, SoundEffectInstance> keyValuePair in SoundEffectInstances)
                        {
                            if (keyValuePair.Key != "BackgroundMusic")
                            {
                                if (keyValuePair.Value.Volume < 0.9f)                       // Move the side scrolling volume controls
                                {
                                    keyValuePair.Value.Volume += 0.1f;

                                    if (!movedSlider)
                                    {
                                        foreach (Option menuOption in OptionElements)
                                        {
                                            if (menuOption.Name == "SFXSlider")
                                            {
                                                menuOption.CreateRectangle(                 // Adjust the volume
                                                    (int)(optionMenuDictionary["SFXSlider"].X + 10),
                                                    (int)(optionMenuDictionary["SFXSlider"].Y)
                                                    );

                                                optionMenuDictionary["SFXSlider"] = new Vector2(
                                                    (int)(optionMenuDictionary["SFXSlider"].X + 10),
                                                    (int)(optionMenuDictionary["SFXSlider"].Y)
                                                    );

                                                SoundEffectInstances["MenuMove"].Play();
                                            }
                                        }

                                        movedSlider = true;
                                    }
                                }
                                else
                                {
                                    SoundEffectInstances["Error"].Play();
                                }
                            }
                        }

                        break;

                    case "Difficulty":
                        break;
                    }
                }
                else if (CurrentKeyboardState.IsKeyDown(Keys.Left) && PreviousKeyboardState.IsKeyUp(Keys.Left))
                {
                    switch (currentPosition)
                    {
                    case "Music":
                        if (SoundEffectInstances["BackgroundMusic"].Volume > 0.1f)          // Move the side scrolling volume controls
                        {
                            SoundEffectInstances["BackgroundMusic"].Volume -= 0.1f;

                            foreach (Option menuOption in OptionElements)
                            {
                                if (menuOption.Name == "MusicSlider")
                                {
                                    menuOption.CreateRectangle(                             // Adjust the volume
                                        (int)(optionMenuDictionary["MusicSlider"].X - 10),
                                        (int)(optionMenuDictionary["MusicSlider"].Y)
                                        );

                                    optionMenuDictionary["MusicSlider"] = new Vector2(
                                        (int)(optionMenuDictionary["MusicSlider"].X - 10),
                                        (int)(optionMenuDictionary["MusicSlider"].Y)
                                        );

                                    SoundEffectInstances["MenuMove"].Play();
                                }
                            }
                        }
                        else
                        {
                            SoundEffectInstances["Error"].Play();
                        }

                        break;

                    case "SFX":
                        bool movedSlider = false;

                        foreach (KeyValuePair <string, SoundEffectInstance> keyValuePair in SoundEffectInstances)
                        {
                            if (keyValuePair.Key != "BackgroundMusic")
                            {
                                if (keyValuePair.Value.Volume > 0.1f)                       // Move the side scrolling volume controls
                                {
                                    keyValuePair.Value.Volume -= 0.1f;

                                    if (!movedSlider)
                                    {
                                        foreach (Option menuOption in OptionElements)
                                        {
                                            if (menuOption.Name == "SFXSlider")
                                            {
                                                menuOption.CreateRectangle(                 // Adjust the volume
                                                    (int)(optionMenuDictionary["SFXSlider"].X - 10),
                                                    (int)(optionMenuDictionary["SFXSlider"].Y)
                                                    );

                                                optionMenuDictionary["SFXSlider"] = new Vector2(
                                                    (int)(optionMenuDictionary["SFXSlider"].X - 10),
                                                    (int)(optionMenuDictionary["SFXSlider"].Y)
                                                    );

                                                SoundEffectInstances["MenuMove"].Play();
                                            }
                                        }

                                        movedSlider = true;
                                    }
                                }
                                else
                                {
                                    SoundEffectInstances["Error"].Play();
                                }
                            }
                        }

                        break;
                    }
                }
            }
        }
Exemple #18
0
 public static bool IsKeyPressed(Keys key)
 {
     return(CurrentKeyboardState.IsKeyDown(key));
 }
Exemple #19
0
        /// <summary>
        /// Update method
        /// </summary>
        /// <param name="gameTime"></param>
        protected override void Update(GameTime gameTime)
        {
            if (this.Name == "TitleSelectionFrame")
            {
                string currentPosition = null;

                foreach (KeyValuePair <string, Vector2> keyValuePair in titleMenuDictionary) // Find the current position of the menu selection image
                {
                    if ((
                            (keyValuePair.Value.X == this.DrawLocation.X)
                            ) && (
                            (keyValuePair.Value.Y == this.DrawLocation.Y)
                            ) && (
                            (keyValuePair.Key != "TitleSelectionFrame")
                            ))
                    {
                        currentPosition = keyValuePair.Key;
                    }
                }

                // Move the image down if the down key is pressed
                if (CurrentKeyboardState.IsKeyDown(Keys.Down) && PreviousKeyboardState.IsKeyUp(Keys.Down))
                {
                    SoundEffectInstances["MenuMove"].Play();

                    switch (currentPosition)
                    {
                    case "NewGame":
                        base.CreateRectangle(titleMenuDictionary["LevelEditor"]);

                        break;

                    case "LevelEditor":
                        base.CreateRectangle(titleMenuDictionary["Options"]);

                        break;
                    }
                }// Move the image up if the up key is pressed
                else if (CurrentKeyboardState.IsKeyDown(Keys.Up) && PreviousKeyboardState.IsKeyUp(Keys.Up))
                {
                    SoundEffectInstances["MenuMove"].Play();

                    switch (currentPosition)
                    {
                    case "LevelEditor":
                        base.CreateRectangle(titleMenuDictionary["NewGame"]);

                        break;

                    case "Options":
                        base.CreateRectangle(titleMenuDictionary["LevelEditor"]);

                        break;
                    }
                }// Go into the menu if the enter key is pressed
                else if (CurrentKeyboardState.IsKeyDown(Keys.Enter) && PreviousKeyboardState.IsKeyUp(Keys.Enter))
                {
                    switch (currentPosition)
                    {
                    case "NewGame":
                        gameState = GameState.InGame;

                        break;

                    case "LevelEditor":
                        gameState = GameState.LevelEditor;

                        break;

                    case "Options":
                        gameState = GameState.Options;

                        break;
                    }
                }
            }
        }
Exemple #20
0
 public static bool OnePressed(Keys key)
 {
     return(CurrentKeyboardState.IsKeyDown(key) && OldKeyboardState.IsKeyUp(key));
 }
Exemple #21
0
 private bool IsKeyPressed(Keys key1, Keys key2)
 {
     return(CurrentKeyboardState.IsKeyDown(key1) || CurrentKeyboardState.IsKeyDown(key2));
 }
Exemple #22
0
 private bool IsKeyTapped(Keys key)
 {
     return(CurrentKeyboardState.IsKeyDown(key) && PreviousKeyboardState.IsKeyUp(key));
 }
Exemple #23
0
        public void DrawShadows(Light light)
        {
            Vector3 LightPos;

            LightPos = new Vector3(Mouse.GetState().X, Mouse.GetState().Y, 250);
            LightList[0].Position = new Vector3(SpritePos.X, SpritePos.Y, 0) + new Vector3(16, 16, 0);
            //LightList[0].Position = LightPos;

            //LightList[LightList.Count - 1].Position = LightPos;

            Vector2 SourcePosition = new Vector2(light.Position.X, light.Position.Y);

            RayList.Clear();
            ShadowList.Clear();

            foreach (Solid solid in SolidList)
            {
                Vector3 lightVector, check1, check2, thing, thing2;

                for (int i = 0; i < solid.vertices.Count(); i++)
                {
                    if (CurrentKeyboardState.IsKeyDown(Keys.P) &&
                        PreviousKeyboardState.IsKeyUp(Keys.P))
                    {
                        int stop = 10;
                    }

                    lightVector = solid.vertices[i].Position - new Vector3(SourcePosition, 0);
                    //lightVector.Normalize();

                    //lightVector *= light.Size;

                    int nextIndex, prevIndex;

                    nextIndex = Wrap(i + 1, 4);
                    prevIndex = Wrap(i - 1, 4);

                    check1 = solid.vertices[nextIndex].Position - new Vector3(SourcePosition, 0);
                    check2 = solid.vertices[prevIndex].Position - new Vector3(SourcePosition, 0);

                    thing  = Vector3.Cross(lightVector, check1);
                    thing2 = Vector3.Cross(lightVector, check2);

                    //NOTE: THIS LINE SEEMS TO FIX THE 0 VALUE CHECK VARIABLE RESULTING IN A DISAPPEARING SHADOW
                    thing.Normalize();

                    //SHADOWS DON'T SHOW UP IF THE Y OR X VALUES FOR THE THING AND CHECK ARE THE SAME.
                    //i.e. check1.y = 158 AND thing1.y = 158. Then the next if evaluates to false and a ray isn't added.
                    //meaning that there's a blank side for the polygon
                    //The Check variables use the previous and next vertex positions to calculate a vector
                    //This can end up with the vector having a 0 in it if the light lines up with a side
                    //This makes the cross product values messed up

                    if ((thing.Z <= 0 && thing2.Z <= 0) ||
                        (thing.Z >= 0 && thing2.Z >= 0))
                    {
                        RayList.Add(new myRay()
                        {
                            direction = lightVector, position = solid.vertices[i].Position, length = 10f
                        });
                    }
                }

                if (RayList.Count > 1)
                {
                    int p = RayList.Count() - 2;

                    VertexPositionColor[] vertices = new VertexPositionColor[6];

                    vertices[0].Position = RayList[p].position;
                    vertices[1].Position = RayList[p].position + (RayList[p].direction * 100);
                    vertices[2].Position = RayList[p + 1].position + (RayList[p + 1].direction * 100);

                    vertices[3].Position = RayList[p + 1].position + (RayList[p + 1].direction * 100);
                    vertices[4].Position = RayList[p + 1].position;
                    vertices[5].Position = RayList[p].position;

                    vertices[0].Color = Color.Black;
                    vertices[1].Color = Color.Black;
                    vertices[2].Color = Color.Black;
                    vertices[3].Color = Color.Black;
                    vertices[4].Color = Color.Black;
                    vertices[5].Color = Color.Black;

                    ShadowList.Add(new PolygonShadow()
                    {
                        Vertices = vertices
                    });
                }
            }
        }
Exemple #24
0
 public static bool IsKeyDown(Keys key) => CurrentKeyboardState.IsKeyDown(key);
Exemple #25
0
        /// <summary>
        /// Applies movement to the player character
        /// </summary>
        /// <param name="gameTime"></param>
        /// <returns>The new rectangle where the character needs to be drawn</returns>
        public override Vector2 ApplyMovement(GameTime gameTime)
        {
            Vector2 returnValue;

            // Apply movement based on keys pressed
            if ((CurrentKeyboardState.IsKeyDown(Keys.A)) && (PreviousKeyboardState.IsKeyUp(Keys.A)) ||
                (CurrentKeyboardState.IsKeyDown(Keys.Left)) && (PreviousKeyboardState.IsKeyUp(Keys.Left)))
            {
                base.MovementAppliedTo = MovementAppliedTo.Left;
                base.SpriteEffect      = SpriteEffects.FlipHorizontally;
            }
            else if ((CurrentKeyboardState.IsKeyDown(Keys.D)) && (PreviousKeyboardState.IsKeyUp(Keys.D)) ||
                     (CurrentKeyboardState.IsKeyDown(Keys.Right)) && (PreviousKeyboardState.IsKeyUp(Keys.Right)))
            {
                base.MovementAppliedTo = MovementAppliedTo.Right;
                base.SpriteEffect      = SpriteEffects.None;
            }
            else if ((CurrentKeyboardState.IsKeyUp(Keys.A)) && (PreviousKeyboardState.IsKeyDown(Keys.A)) ||
                     (CurrentKeyboardState.IsKeyUp(Keys.Left)) && (PreviousKeyboardState.IsKeyDown(Keys.Left)))
            {
                if ((!base.JumpInProgress) && (!base.HasJumped))
                {
                    base.MovementAppliedTo = MovementAppliedTo.None;
                }
            }
            else if ((CurrentKeyboardState.IsKeyUp(Keys.D)) && (PreviousKeyboardState.IsKeyDown(Keys.D)) ||
                     (CurrentKeyboardState.IsKeyUp(Keys.Right)) && (PreviousKeyboardState.IsKeyDown(Keys.Right)))
            {
                if ((!base.JumpInProgress) && (!base.HasJumped))
                {
                    base.MovementAppliedTo = MovementAppliedTo.None;
                    base.SpriteEffect      = SpriteEffects.None;
                }
            }
            // Implement the jump feature
            if (base.GravityDirection == GravityDirection.Down)
            {
                if (((CurrentKeyboardState.IsKeyDown(Keys.Space)) && (PreviousKeyboardState.IsKeyUp(Keys.Space)) ||
                     (CurrentKeyboardState.IsKeyDown(Keys.Up)) && (PreviousKeyboardState.IsKeyUp(Keys.Up))) &&
                    ((base.HitObstacle == HitObstacle.FromTop) || (this.JumpCount == 1)))
                {
                    base.TimeSinceJump = gameTime.ElapsedGameTime.Milliseconds;

                    base.MovementAppliedTo = MovementAppliedTo.Up;

                    base.HitObstacle = HitObstacle.None;

                    if (this.PlatformVerticalAcceleration > 0)
                    {
                        base.GravitationalVelocity -= this.PlatformVerticalAcceleration;
                    }

                    if (base.HasJumped == false)
                    {
                        base.HasJumped = true;
                        SoundEffectInstances["JumpSound"].Play();
                    }

                    if (base.JumpInProgress == false)
                    {
                        base.JumpInProgress = true;
                    }
                }
            }
            else if (base.GravityDirection == GravityDirection.Up)
            {
                if (((CurrentKeyboardState.IsKeyDown(Keys.Space)) && (PreviousKeyboardState.IsKeyUp(Keys.Space)) ||
                     (CurrentKeyboardState.IsKeyUp(Keys.Up)) && (PreviousKeyboardState.IsKeyDown(Keys.Up))) &&
                    ((base.HitObstacle == HitObstacle.FromTop) || (this.JumpCount == 1)))
                {
                    base.MovementAppliedTo = MovementAppliedTo.Down;

                    base.HitObstacle = HitObstacle.None;

                    if (base.HasJumped == false)
                    {
                        base.HasJumped = true;
                    }

                    if (base.JumpInProgress == false)
                    {
                        base.JumpInProgress = true;
                    }
                }
            }
            // Cancel movement if nothing is being pressed (because of velocity)
            if ((CurrentKeyboardState.IsKeyUp(Keys.A)) && (CurrentKeyboardState.IsKeyUp(Keys.D)) &&
                (CurrentKeyboardState.IsKeyUp(Keys.Left)) && (CurrentKeyboardState.IsKeyUp(Keys.Right)) &&
                (base.Falling == false) && (base.HasJumped == false) && (base.JumpInProgress == false))
            {
                base.MovementAppliedTo = MovementAppliedTo.None;
            }
            // Attempt at working with gametime
            if (base.TimeSinceLastUpdate > 100)
            {
                this.UpdateSprite();
                base.SelectSprite(base.CurrentSpriteIndex);

                base.TimeSinceLastUpdate = 0;
            }

            base.CalculateGravity(gameTime);
            base.CalculateMovement(gameTime);

            returnValue = new Vector2(
                this.DrawLocation.X + base.MovementVelocity,
                this.DrawLocation.Y + base.GravitationalVelocity
                );

            return(returnValue);
        }
 /// <summary>
 /// Queries the current and previous keyboard states to work out whether a key has been pressed
 /// </summary>
 /// <param name="key">The key we wish to query</param>
 /// <returns>Returns true if the key is down this frame and up the previous frame</returns>
 public bool IsKeyPressed(Keys key)
 {
     return(CurrentKeyboardState.IsKeyDown(key) && PreviousKeyboardState.IsKeyUp(key));
 }
Exemple #27
0
 public static bool IsKeyPressed(Keys key) => CurrentKeyboardState.IsKeyDown(key) && PreviousKeyboardState.IsKeyUp(key);
Exemple #28
0
 /// <summary>
 ///     Check if key has just been pressed
 /// </summary>
 /// <param name="key">Key to check</param>
 public static bool IsKeyTyped(Keys key)
 {
     return(PreviousKeyboardState.IsKeyUp(key) && CurrentKeyboardState.IsKeyDown(key));
 }
 /// <summary>
 /// returns if the current key is down
 /// </summary>
 /// <param name="key"></param>
 /// <returns></returns>
 public bool KeyDown(Keys key)
 {
     return(CurrentKeyboardState.IsKeyDown(key));
 }
Exemple #30
0
        protected override void Update(GameTime gameTime)
        {
            CurrentKeyboardState = Keyboard.GetState();

            if (Mouse.GetState().LeftButton == ButtonState.Pressed)
            {
                Vector2 thing = new Vector2(232, 462) - new Vector2(Mouse.GetState().X, Mouse.GetState().Y);

                int numSeg = (int)MathHelper.Clamp(GetEven((int)thing.Length() / 10), 4, (float)double.PositiveInfinity);
                LightningList.Clear();
                ToonLightning newLightning = new ToonLightning(numSeg, 15, new Vector2(232, 462), new Vector2(Mouse.GetState().X, Mouse.GetState().Y), new Vector2(80, 100));
                LightningList.Add(newLightning);
            }

            CurShotTime += (float)gameTime.ElapsedGameTime.TotalMilliseconds;

            if (CurrentKeyboardState.IsKeyDown(Keys.Q))
            {
                CrepLightList[0].Exposure += 0.01f;
            }


            if (CurrentKeyboardState.IsKeyDown(Keys.Y))
            {
                SpecVal += 0.001f;
                LightEffect.Parameters["specVal"].SetValue(SpecVal);
            }

            if (CurrentKeyboardState.IsKeyDown(Keys.H))
            {
                SpecVal -= 0.001f;
                LightEffect.Parameters["specVal"].SetValue(SpecVal);
            }

            if (CurrentKeyboardState.IsKeyDown(Keys.A))
            {
                CrepLightList[0].Exposure -= 0.01f;
            }

            if (CurrentKeyboardState.IsKeyDown(Keys.G))
            {
                if (CurShotTime > ShotTime)
                {
                    Vector2 pos;
                    pos = new Vector2(Mouse.GetState().X, Mouse.GetState().Y);

                    Vector2 Direction;
                    Direction = LightningList[0].Direction;

                    Emitter FlashEmitter = new Emitter(HitEffectParticle, pos,
                                                       new Vector2(
                                                           MathHelper.ToDegrees(-(float)Math.Atan2(Direction.Y, Direction.X)) - 30,
                                                           MathHelper.ToDegrees(-(float)Math.Atan2(Direction.Y, Direction.X)) + 30),
                                                       new Vector2(8, 12), new Vector2(100, 200), 1f, false,
                                                       new Vector2(0, 0), new Vector2(0, 0), new Vector2(0.25f, 0.25f),
                                                       Color.Yellow, Color.Orange, 0f, 0.05f, 100, 7, false, new Vector2(0, 720), true,
                                                       1.0f, null, null, null, null, null, true, new Vector2(0.25f, 0.25f), false, false,
                                                       null, false, false, false);

                    EmitterList.Add(FlashEmitter);

                    Emitter FlashEmitter2 = new Emitter(HitEffectParticle, pos,
                                                        new Vector2(
                                                            MathHelper.ToDegrees(-(float)Math.Atan2(Direction.Y, Direction.X)) - 5,
                                                            MathHelper.ToDegrees(-(float)Math.Atan2(Direction.Y, Direction.X)) + 5),
                                                        new Vector2(12, 15), new Vector2(80, 150), 1f, false,
                                                        new Vector2(0, 0), new Vector2(0, 0), new Vector2(0.35f, 0.35f),
                                                        Color.LightYellow, Color.Yellow, 0f, 0.05f, 100, 7, false, new Vector2(0, 720), true,
                                                        1.0f, null, null, null, null, null, true, new Vector2(0.18f, 0.18f), false, false,
                                                        null, false, false, false);

                    EmitterList.Add(FlashEmitter2);


                    LightList.Add(new Light()
                    {
                        //Color = new Color(0, 180, 255, 42),
                        Color    = Color.Goldenrod,
                        Active   = true,
                        Power    = 0.35f,
                        Position = new Vector3(pos.X, pos.Y, 0),
                        Size     = 400,
                        MaxTime  = 80,
                        CurTime  = 0
                    });

                    CurShotTime = 0;
                }
            }

            LightList[1].Position = new Vector3(Mouse.GetState().X, Mouse.GetState().Y, 0);

            CrepLightList[0].Position = new Vector2(Mouse.GetState().X, Mouse.GetState().Y);



            foreach (Emitter emitter in EmitterList)
            {
                emitter.Update(gameTime);
            }

            foreach (ToonLightning bolt in LightningList)
            {
                bolt.Update(gameTime);
            }

            foreach (Sprite sprite in SpriteList)
            {
                sprite.Update(gameTime);
            }

            foreach (Solid solid in SolidList)
            {
                solid.Update(gameTime);
            }

            foreach (Light light in LightList)
            {
                light.Update(gameTime);
            }

            //if (CurrentKeyboardState.IsKeyDown(Keys.Space))
            //{
            //    SpawnCrate();
            //}

            SpritePos += new Vector2(
                (float)Math.Sin(2 * (float)gameTime.TotalGameTime.TotalSeconds),
                (float)Math.Cos(4 * (float)gameTime.TotalGameTime.TotalSeconds)) * 10;

            CrepLightList[1].Position = SpritePos;

            PreviousKeyboardState = CurrentKeyboardState;

            //World.Step((float)gameTime.ElapsedGameTime.TotalSeconds);

            base.Update(gameTime);
        }