An encapsulation of the accelerometer's current state.
示例#1
0
        public override void HandleInput(GameTime gameTime, InputState input)
        {
            //// get all of our input states
            keyboardState = Keyboard.GetState();
            //gamePadState = GamePad.GetState(PlayerIndex.One);
            touchState         = TouchPanel.GetState();
            accelerometerState = Accelerometer.GetState();

            if (maze.player.IsAlive == false)
            {
                if (keyboardState.IsKeyDown(Keys.Space) || gamePadState.IsButtonDown(Buttons.A) || touchState.Any() == true)
                {
                    maze.StartRoom().StartNewLife(ScreenManager.GraphicsDevice);
                }
            }

            // Exit the game when back is pressed.
            ///// if (gamePadState.Buttons.Back == ButtonState.Pressed)
            ////// Exit();

            bool continuePressed = keyboardState.IsKeyDown(Keys.Space) || gamePadState.IsButtonDown(Buttons.A) || touchState.Any();


            wasContinuePressed = continuePressed;
        }
示例#2
0
        private void UpdateTilesUp(GameTime gameTime, KeyboardState keyboardState, GamePadState gamePadState, TouchCollection touchState, AccelerometerState accelState, DisplayOrientation orientation)
        {
            int y = Height - 1;

            for (int x = 0; x <= Width - 1; x++)
            {
                // If there is a visible Tile in that position
                Texture2D texture = null;
                texture = tiles[x, y].Texture;
                if (texture != null)
                {
                    // Draw it in screen space.
                    Rectangle rect     = new Rectangle(x * Convert.ToInt32(Math.Truncate(Tile.Size.X)), -1 * Convert.ToInt32(Math.Truncate(Tile.Size.Y)) - BOTTOM_BORDER, Convert.ToInt32(texture.Width), Convert.ToInt32(texture.Height));
                    Vector2   position = new Vector2(rect.X, rect.Y);
                    tiles[x, y].Update(gameTime, keyboardState, gamePadState, touchState, accelState, orientation);
                }
            }
        }
示例#3
0
 private void UpdateTilesTemporaney(GameTime gameTime, KeyboardState keyboardState, GamePadState gamePadState, TouchCollection touchState, AccelerometerState accelState, DisplayOrientation orientation)
 {
     try
     {
         //workaroud to thread unsafe...?
         lock (tilesTemporaney)
         {
             foreach (Tile item in tilesTemporaney)
             {
                 // Insert your code here.
                 item.Update(gameTime, keyboardState, gamePadState, touchState, accelState, orientation);
             }
         }
     }
     catch (Exception ex)
     {
         ex = new Exception();
     }
 }
示例#4
0
        private void UpdateSprites(GameTime gameTime, KeyboardState keyboardState, GamePadState gamePadState, TouchCollection touchState, AccelerometerState accelState, DisplayOrientation orientation)
        {
            foreach (Sprite s in SpritesInRoom())
            {
                switch (s.GetType().Name)
                {
                case "Guard":
                    ((Guard)s).Update(gameTime, keyboardState, gamePadState, touchState, accelState, orientation);
                    break;

                case "Skeleton":
                    ((Skeleton)s).Update(gameTime, keyboardState, gamePadState, touchState, accelState, orientation);
                    break;


                case "Serpent":
                    ((Serpent)s).Update(gameTime, keyboardState, gamePadState, touchState, accelState, orientation);
                    break;
                }
            }
        }
示例#5
0
 private void UpdateItems(GameTime gameTime, KeyboardState keyboardState, GamePadState gamePadState, TouchCollection touchState, AccelerometerState accelState, DisplayOrientation orientation)
 {
     for (int y = Height - 1; y >= 0; y += -1)
     {
         for (int x = 0; x <= Width - 1; x++)
         {
             if (tiles[x, y].item != null)
             {
                 tiles[x, y].item.Update(gameTime, keyboardState, gamePadState, touchState, accelState, orientation);
             }
         }
     }
 }
示例#6
0
        public void Update(GameTime gameTime, KeyboardState keyboardState, GamePadState gamePadState, TouchCollection touchState, AccelerometerState accelState, DisplayOrientation orientation)
        {
            //THIS IS FOR NOT UPDATE THE BLOCK ROOM AND SAVE SOME CPU TIME....
            if (this.roomName == "MAP_blockroom.xml")
            {
                return;
            }
            //player.Update(gameTime, keyboardState, gamePadState, touchState, accelState, orientation);

            UpdateTilesTemporaney(gameTime, keyboardState, gamePadState, touchState, accelState, orientation);

            UpdateTiles(gameTime, keyboardState, gamePadState, touchState, accelState, orientation);
            //maze.LeftRoom(this).UpdateTilesLeft(gameTime, keyboardState, gamePadState, touchState, accelState, orientation);

            //maze.UpRoom(this).UpdateTilesUp(gameTime, keyboardState, gamePadState, touchState, accelState, orientation);

            UpdateItems(gameTime, keyboardState, gamePadState, touchState, accelState, orientation);

            //update spritesssss
            //UpdateSprites(gameTime, keyboardState, gamePadState, touchState, accelState, orientation);
        }
示例#7
0
        /// <summary>
        /// Handles input, performs physics, and animates the player sprite.
        /// </summary>
        /// <remarks>
        /// We pass in all of the input states so that our game is only polling the hardware
        /// once per frame. We also pass the game's orientation because when using the accelerometer,
        /// we need to reverse our motion when the orientation is in the LandscapeRight orientation.
        /// </remarks>

        public void Update(GameTime gameTime, KeyboardState keyboardState, GamePadState gamePadState, TouchCollection touchState, AccelerometerState accelState, DisplayOrientation orientation)
        {
            float elapsed = Convert.ToSingle(gameTime.ElapsedGameTime.TotalSeconds);

            // TODO: Add your game logic here.
            sprite.UpdateFrame(elapsed, ref _position, ref flip, ref spriteState);

            if (IsAlive == false)
            {
                DropDead();
                return;
            }


            //bool thereIsKid = false;
            foreach (Sprite s in SpriteRoom.SpritesInRoom())
            {
                switch (s.GetType().Name)
                {
                case "Player":
                    if (true)
                    {
                        if (s.IsAlive == false)
                        {
                            break; // TODO: might not be correct. Was : Exit Select
                        }

                        //thereIsKid = true;
                        if (s.Position.CheckOnRow(Position))
                        {
                            if (s.Position.CheckOnRowDistancePixel(Position) >= 0 & s.Position.CheckOnRowDistancePixel(Position) <= 70 & Alert == true & spriteState.Value().state == Enumeration.State.strike)
                            {
                                if (spriteState.Value().Name == Enumeration.State.strike.ToString().ToUpper())
                                {
                                    //check if block
                                    if (s.spriteState.Value().Name != Enumeration.State.readyblock.ToString().ToUpper())
                                    {
                                        spriteState.Value().Name = string.Empty;
                                        s.Splash(true, gameTime);
                                        //Splash splash = new Splash(SpriteRoom, Position.Value, graphicsDevice, SpriteEffects.None, true);
                                        //Maze.sprites.Add(splash);

                                        s.Energy = s.Energy - 1;
                                        s.StrikeRetreat();
                                    }
                                    else
                                    {
                                        System.Console.WriteLine("P->" + Enumeration.State.readyblock.ToString().ToUpper());
                                        //blocked
                                    }
                                }
                                if (s.Energy == 0)
                                {
                                    Fastheathe();
                                }
                            }

                            Alert = true;

                            //Chenge Flip player..
                            if (Position.X < s.Position.X)
                            {
                                flip = SpriteEffects.None;
                            }
                            else
                            {
                                flip = SpriteEffects.FlipHorizontally;
                            }



                            Advance(s.Position, flip);
                        }
                        else
                        {
                            Alert = false;
                        }
                        break; // TODO: might not be correct. Was : Exit Select
                    }

                default:
                    break; // TODO: might not be correct. Was : Exit Select
                }
            }



            if (Alert == false)
            {
                Stand();
            }
            //Ready();
            else
            {
                Stand();
            }
        }
示例#8
0
        /// <summary>
        /// Handles input, performs physics, and animates the player sprite.
        /// </summary>
        /// <remarks>
        /// We pass in all of the input states so that our game is only polling the hardware
        /// once per frame. We also pass the game's orientation because when using the accelerometer,
        /// we need to reverse our motion when the orientation is in the LandscapeRight orientation.
        /// </remarks>
        public void Update(GameTime gameTime, KeyboardState keyboardState, GamePadState gamePadState, TouchCollection touchState, AccelerometerState accelState, DisplayOrientation orientation)
        {
            HandleCollision();

            if (object.ReferenceEquals(this.GetType(), typeof(Spikes)))
            {
                ((Spikes)this).elapsedTimeOpen += Convert.ToSingle(gameTime.ElapsedGameTime.TotalSeconds);
                if (((Spikes)this).elapsedTimeOpen > ((Spikes)this).timeOpen)
                {
                    ((Spikes)this).Close();
                }
            }

            if (object.ReferenceEquals(this.GetType(), typeof(Lava)))
            {
                ((Lava)this).elapsedTimeOpen += Convert.ToSingle(gameTime.ElapsedGameTime.TotalSeconds);
                if (((Lava)this).elapsedTimeOpen > ((Lava)this).timeOpen)
                {
                    ((Lava)this).Close();
                }
            }

            if (object.ReferenceEquals(this.GetType(), typeof(Chomper)))
            {
                ((Chomper)this).elapsedTimeOpen += Convert.ToSingle(gameTime.ElapsedGameTime.TotalSeconds);
                if (((Chomper)this).elapsedTimeOpen > ((Chomper)this).timeOpen)
                {
                    ((Chomper)this).Close();
                }
            }


            if (object.ReferenceEquals(this.GetType(), typeof(Gate)))
            {
                ((Gate)this).elapsedTimeOpen += Convert.ToSingle(gameTime.ElapsedGameTime.TotalSeconds);
                if (((Gate)this).timeOpen == 0 && ((Gate)this).tileState.Value().state == Enumeration.StateTile.opened)
                {
                    ((Gate)this).Opened();
                }

                else if (((Gate)this).elapsedTimeOpen > ((Gate)this).timeOpen)
                {
                    ((Gate)this).Close();
                }
            }

            if (object.ReferenceEquals(this.GetType(), typeof(PressPlate)))
            {
                ((PressPlate)this).elapsedTimeOpen += Convert.ToSingle(gameTime.ElapsedGameTime.TotalSeconds);
                if (((PressPlate)this).elapsedTimeOpen > ((PressPlate)this).timeOpen & ((PressPlate)this).State == Enumeration.StateTile.dpressplate)
                {
                    ((PressPlate)this).DePress();
                }
            }

            if (object.ReferenceEquals(this.GetType(), typeof(Loose)))
            {
                if (((Loose)this).tileState.Value().state == Enumeration.StateTile.loose)
                {
                    ((Loose)this).elapsedTimeOpen += Convert.ToSingle(gameTime.ElapsedGameTime.TotalSeconds);
                    if (((Loose)this).elapsedTimeOpen > ((Loose)this).timeFall)
                    {
                        ((Loose)this).Fall();
                    }
                }
            }

            float elapsed = Convert.ToSingle(gameTime.ElapsedGameTime.TotalSeconds);

            tileAnimation.UpdateFrameTile(elapsed, ref _position, ref flip, ref tileState);
        }
示例#9
0
        /// <summary>
        /// Handles input, performs physics, and animates the player sprite.
        /// </summary>
        /// <remarks>
        /// We pass in all of the input states so that our game is only polling the hardware
        /// once per frame. We also pass the game's orientation because when using the accelerometer,
        /// we need to reverse our motion when the orientation is in the LandscapeRight orientation.
        /// </remarks>

        public void Update(GameTime gameTime, KeyboardState keyboardState, GamePadState gamePadState, TouchCollection touchState, AccelerometerState accelState, DisplayOrientation orientation)
        {
            float elapsed = Convert.ToSingle(gameTime.ElapsedGameTime.TotalSeconds);

            // TODO: Add your game logic here.
            sprite.UpdateFrame(elapsed, ref _position, ref flip, ref spriteState);
        }
示例#10
0
        public void Update(GameTime gameTime, KeyboardState keyboardState, GamePadState gamePadState, TouchCollection touchState, AccelerometerState accelState, DisplayOrientation orientation)
        {
            float elapsed = Convert.ToSingle(gameTime.ElapsedGameTime.TotalSeconds);

            itemAnimation.UpdateFrameItem(elapsed, ref position, ref flip, ref itemState);
        }