예제 #1
0
        private void MapButtonValue(XNAInput.ButtonState previousXnaButton, XNAInput.ButtonState xnaButton, MappingButtons button)
        {
            // Mapping
            bool isDown = false;
            bool isPressed = false;
            bool isReleased = false;

            if (xnaButton == XNAInput.ButtonState.Pressed)
            {
                isDown = true;

                if (previousXnaButton == XNAInput.ButtonState.Released)
                {
                    isPressed = true;
                }
            }
            else if (xnaButton == XNAInput.ButtonState.Released)
            {
                if (previousXnaButton == XNAInput.ButtonState.Pressed)
                {
                    isReleased = true;
                }
            }

            SetMappingValue(button, isDown, isPressed, isReleased);
        }
예제 #2
0
        public Keys? GetMapping(MappingButtons button)
        {
            foreach (Keys key in _keyboardMapping.Keys)
            {
                if (_keyboardMapping[key] == button) return key;
            }

            return null;
        }
예제 #3
0
        /// <summary>
        /// Get a button state.
        /// </summary>
        /// <param name="button"></param>
        /// <returns></returns>
        /// <remarks>For thumbsticks, use the thumbsticks (left / right) properties</remarks>
        public ButtonState GetState(MappingButtons button)
        {
            if (IsConnected)
            {
                if (mapping.Keys.Contains(button))
                {
                    return(mapping[button]);
                }
            }

            return(new ButtonState());
        }
예제 #4
0
        public Keys?GetMapping(MappingButtons button)
        {
            foreach (Keys key in _keyboardMapping.Keys)
            {
                if (_keyboardMapping[key] == button)
                {
                    return(key);
                }
            }

            return(null);
        }
예제 #5
0
        protected void SetMappingValue(MappingButtons button, bool isDown, bool isPressed, bool isReleased)
        {
            ButtonState state;

            if (mapping.TryGetValue(button, out state) == false)
            {
                state = new ButtonState();
            }

            state.IsDown     = isDown;
            state.IsPressed  = isPressed;
            state.IsReleased = isReleased;

            mapping[button] = state;
        }
예제 #6
0
        protected void SetMappingValue(MappingButtons button, bool isDown, bool isPressed, bool isReleased)
        {
            ButtonState state;

            if (mapping.TryGetValue(button, out state) == false)
            {
                state = new ButtonState();
            }

            state.IsDown = isDown;
            state.IsPressed = isPressed;
            state.IsReleased = isReleased;

            mapping[button] = state;
        }
예제 #7
0
        /// <summary>
        /// Get a button state.
        /// </summary>
        /// <param name="button"></param>
        /// <returns></returns>
        /// <remarks>For thumbsticks, use the thumbsticks (left / right) properties</remarks>
        public ButtonState GetState(MappingButtons button)
        {
            if (IsConnected)
            {
                if (mapping.Keys.Contains(button))
                {
                    return mapping[button];
                }
            }

            return new ButtonState();
        }
예제 #8
0
 public void MapButton(Keys key, MappingButtons button)
 {
     _keyboardMapping[key] = button;
 }
예제 #9
0
        /// <summary>
        /// Positive box collision
        /// </summary>
        /// <param name="collider"></param>
        /// <param name="depth"></param>
        public override void EntityDetected(Entity collider, Vector2 depth)
        {
            if (!_isDead)
            {
                if (collider is OCoin)
                {
                    collider.IsAlive = false;
                    LapinsScript.AddToScore(100);

                    int carrotCounter = Application.ScriptManager.GetFlag<int>(LapinsScript.CarrotsCount);
                    carrotCounter++;
                    Application.ScriptManager.SetFlag(LapinsScript.CarrotsCount, carrotCounter);

                    // Sound
                    playEatSound();

                    if (carrotCounter % 250 == 0)
                    {
                        addLife();
                    }
                }
                else if (collider is OLife)
                {
                    collider.IsAlive = false;

                    addLife();
                }
                else if (collider is Keys)
                {
                    collider.IsAlive = false;

                    LapinsScript.AddToScore(5000);

                    Application.ScriptManager.SetFlag(LapinsScript.HasKeys, true);

                    // Sound
                    Application.MagicContentManager.GetSound("s_keys").Play(0.5f, 0, 0);
                }
                else if (collider is Letter)
                {
                    collider.IsAlive = false;

                    LapinsScript.AddToScore(2000);

                    List<Letter> collectedLetters = Application.ScriptManager.GetFlag<List<Letter>>(LapinsScript.CollectedLetters);
                    collectedLetters.Add((Letter)collider);

                    // Sort by order in the initial list
                    collectedLetters.Sort();

                    if (collectedLetters.Count == OLetterSpawn.LetterCount)
                    {
                        LapinsScript.AddToScore(10000);
                    }

                    Application.ScriptManager.SetFlag(LapinsScript.CollectedLetters, collectedLetters);

                    // Sound
                    Application.MagicContentManager.GetSound("s_letter").Play(0.5f, 0, 0);

                }
                else if (collider is OShip)
                {
                    // End game ?
                    bool hasKeys = Application.ScriptManager.GetFlag<bool>(LapinsScript.HasKeys);

                    if (hasKeys)
                    {
                        if (_isNotVisible == false)
                        {
                            LapinsScript.AddToScore(5000);
                            Application.ScriptManager.SetFlag(LapinsScript.EscapeState, 1);

                            _isNotVisible = true;
                        }
                    }
                    else
                    {
                        ((OShip)collider).Question();
                    }
                }
                else if (collider is OPancarte)
                {
                    // Display input to use
                    _showInputAlpha = 1.0f;
                    _inputHelp = MappingButtons.Y;

                    // Display help ?
                    if (_pressedAction)
                    {
                        // Sound
                        Application.MagicContentManager.GetSound("s_pancarte").Play(0.5f, 0, 0);

                        ((OPancarte)collider).IsActivated = true;
                    }
                }
            }
        }
예제 #10
0
        /// <summary>
        /// Player hitbox collision
        /// </summary>
        /// <param name="collider"></param>
        /// <param name="depth"></param>
        public override void CollisionDetected(Entity collider, Vector2 depth)
        {
            if (!_isDead)
            {
                if (collider is OSpikes)
                {
                    LoseLife();
                    TriggerDeathAnimationAndTeleport();
                }
                else if (collider is Asteroid)
                {
                    LoseLife();
                }
                else if (collider is OWolfTrap)
                {
                    var wolfTrap = collider as OWolfTrap;
                    wolfTrap.Activate();

                    LoseLife();
                    TriggerDeathAnimationAndTeleport();
                }
                else if (collider is OTerrier)
                {
                    // Display input to use
                    _showInputAlpha = 1.0f;
                    _inputHelp = MappingButtons.Y;

                    // Teleport !
                    if (_canTeleport)
                    {
                        if (_pressedAction)
                        {
                            var terrier = collider as OTerrier;
                            if (terrier.LinkedTerrier != null)
                            {
                                _canTeleport = false;

                                // Sound
                                Application.MagicContentManager.GetSound("s_teleport").Play(0.5f, 0, 0);

                                // Fade in/out & teleport
                                Application.GameStateManager.CurrentGameState.SceneCamera.FadeIn(10f, () =>
                                {
                                    location = terrier.LinkedTerrier.Location + new Vector2(70, 120) - (new Vector2(SrcRect.Width / 2, SrcRect.Height));
                                    Application.GameStateManager.CurrentGameState.SceneCamera.FadeOut(10f, null);
                                });
                            }

                        }
                    }
                }
                else if (collider is OBumper)
                {
                    // Bumper will eject bunny in the air
                    if (location.Y < collider.Location.Y)
                    {
                        var bumper = ((OBumper)collider);
                        bumper.IsPressed = true;

                        velocity = bumper.BounceVector;

                        _isJumping = true;
                        _jumpTime += _elapsedFrameTime;

                        // Sound
                        Application.MagicContentManager.GetSound("s_bump").Play(0.5f, 0, 0);
                    }
                }
                else if (collider is OBox)
                {
                    var box = (OBox)collider;
                    if (!box.Activated)
                    {
                        box.Activated = true;
                    }
                    if (box.Trapped)
                    {
                        _boxlife = 5;
                        box.IsAlive = false;
                    }
                }
            }
        }
예제 #11
0
        public override void Update(Microsoft.Xna.Framework.GameTime gameTime)
        {
            _keyboard = Keyboard.GetState();

            base.Update(gameTime);

            // Update mapping
            foreach (Keys key in _keyboardMapping.Keys)
            {
                MappingButtons button     = _keyboardMapping[key];
                bool           isDown     = false;
                bool           isPressed  = false;
                bool           isReleased = false;

                if (_keyboard.IsKeyDown(key))
                {
                    isDown = true;

                    if (_pkeyboard.IsKeyUp(key))
                    {
                        isPressed = true;
                    }
                }
                else if (_keyboard.IsKeyUp(key))
                {
                    if (_pkeyboard.IsKeyDown(key))
                    {
                        isReleased = true;
                    }
                }

                SetMappingValue(button, isDown, isPressed, isReleased);
            }

            // Thumbstick emulation
            // -- LEFT
            float leftx = 0f;

            if (_keyboard.IsKeyDown(_thumbsLeftLeft))
            {
                leftx = -1f;
            }
            else if (_keyboard.IsKeyDown(_thumbsLeftRight))
            {
                leftx = 1f;
            }

            ThumbStickLeft.X = leftx;

            float lefty = 0f;

            if (_keyboard.IsKeyDown(_thumbsLeftUp))
            {
                lefty = -1f;
            }
            else if (_keyboard.IsKeyDown(_thumbsLeftDown))
            {
                lefty = 1f;
            }

            ThumbStickLeft.Y = lefty;

            // --RIGHT
            float rightx = 0f;

            if (_keyboard.IsKeyDown(_thumbsRightLeft))
            {
                rightx = -1f;
            }
            else if (_keyboard.IsKeyDown(_thumbsRightRight))
            {
                rightx = 1f;
            }

            ThumbStickRight.X = rightx;

            float righty = 0f;

            if (_keyboard.IsKeyDown(_thumbsRightUp))
            {
                righty = -1f;
            }
            else if (_keyboard.IsKeyDown(_thumbsRightDown))
            {
                righty = 1f;
            }

            ThumbStickRight.Y = righty;

            _pkeyboard = _keyboard;
        }
예제 #12
0
 public void MapButton(Keys key, MappingButtons button)
 {
     _keyboardMapping[key] = button;
 }
예제 #13
0
        private void MapButtonValue(XNAInput.ButtonState previousXnaButton, XNAInput.ButtonState xnaButton, MappingButtons button)
        {
            // Mapping
            bool isDown     = false;
            bool isPressed  = false;
            bool isReleased = false;

            if (xnaButton == XNAInput.ButtonState.Pressed)
            {
                isDown = true;

                if (previousXnaButton == XNAInput.ButtonState.Released)
                {
                    isPressed = true;
                }
            }
            else if (xnaButton == XNAInput.ButtonState.Released)
            {
                if (previousXnaButton == XNAInput.ButtonState.Pressed)
                {
                    isReleased = true;
                }
            }

            SetMappingValue(button, isDown, isPressed, isReleased);
        }