Ejemplo n.º 1
0
		public static void SetupAccelerometer()
		{
            _sensorManger = (SensorManager)Game.Activity.GetSystemService(Context.SensorService);
            _sensor = _sensorManger.GetDefaultSensor(SensorType.Accelerometer);

            if (_sensor != null) 
            {
                _state = new AccelerometerState { IsConnected = true };                
            }
            else _state = new AccelerometerState { IsConnected = false };
        }
Ejemplo n.º 2
0
        public static void SetupAccelerometer()
        {
            _sensorManger = (SensorManager)Game.contextInstance.GetSystemService(Context.SensorService);
            _sensor = _sensorManger.GetDefaultSensor(SensorType.Accelerometer);

            if (_sensor != null) {
                _state = new AccelerometerState { IsConnected = true };
                _sensorManger.RegisterListener(new SensorListener(), _sensor, SensorDelay.Game);
            }
            else _state = new AccelerometerState { IsConnected = false };
        }
Ejemplo n.º 3
0
        public static void SetupAccelerometer()
        {
            _sensorManger = (SensorManager)Game.contextInstance.GetSystemService(Context.SensorService);
            _sensor       = _sensorManger.GetDefaultSensor(SensorType.Accelerometer);

            if (_sensor != null)
            {
                _state = new AccelerometerState {
                    IsConnected = true
                };
            }
            else
            {
                _state = new AccelerometerState {
                    IsConnected = false
                }
            };
        }
Ejemplo n.º 4
0
		public static void SetupAccelerometer()
		{
            _state = new AccelerometerState { IsConnected = true };                
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Update the Player state, the tracking camera, and the currently active level.
        /// </summary>
        /// <param name="gameTime">The current time step of the game.</param>
        /// <param name="keyboardState">The current state of the PC keyboard.</param>
        /// <param name="gamePadState"></param>
        /// <param name="touchState"></param>
        /// <param name="accelState"></param>
        /// <param name="orientation"></param>
        public void Update(GameTime gameTime, 
            KeyboardState keyboardState,
            GamePadState gamePadState,
            TouchCollection touchState,
            AccelerometerState accelState,
            DisplayOrientation orientation,
            InputManager inputManager)
        {
            //Update the Player
            if (!Player.IsAlive && !deathPan)
            {
                // Still want to perform physics on the player.
                Player.ApplyPhysics(gameTime);

                //TODO: Pan the camera to the active spawn
                //if(keyboardState.IsKeyDown(Keys.R))
                //Player.Reset(activeLevel.ActiveSpawn.Position);
                camera = new PanningDirector(camera.Camera, activeLevel.ActiveSpawn, 0.75f);
                deathPan = true;
            }
            else
            {
                Player.Update(gameTime, keyboardState, gamePadState, touchState, accelState, orientation, inputManager);

                if (!Player.IsAlive)
                {
                    activeLevel.ActiveSpawn.Spawn();
                }
            }

            // Update the camera
            if (camera is PanningDirector)
            {
                PanningDirector panningDirector = (PanningDirector)camera;
                if (panningDirector.Completed)
                {
                    camera = new TrackingDirector(panningDirector.Camera, player);
                }
                else if(deathPan && panningDirector.Returning)
                    {
                        Player.Reset(activeLevel.ActiveSpawn.Position - new Vector2(2, 0));
                        camera = new TrackingDirector(panningDirector.Camera, player);
                        deathPan = false;
                    }
            }
            camera.update(gameTime);

            //Update the current level
            activeLevel.Update(Player, gameTime, keyboardState, inputManager);
        }
Ejemplo n.º 6
0
 public static void SetupAccelerometer()
 {
     _state = new AccelerometerState {
         IsConnected = true
     };
 }
Ejemplo n.º 7
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)
        {
            // Allows the game to exit
            /*if (g.state == GameState.endGame)
            {
                this.Exit();
            }*/

            switch (g.state)
            {
                case GameState.play:
                    //set direction, if need be.
                    accelState = Accelerometer.GetState();
                    if (accelState.Acceleration.X >= 0.35 && (accelState.Acceleration.Y > -0.5 && accelState.Acceleration.Y < 0.5) && (accelState.Acceleration.Z > -0.85 && accelState.Acceleration.Z < 0.85))
                        g.gravity = Direction.left;
                    else if (accelState.Acceleration.Y >= 0.35 && (accelState.Acceleration.X > -0.5 && accelState.Acceleration.X < 0.5) && (accelState.Acceleration.Z > -0.85 && accelState.Acceleration.Z < 0.85))
                        g.gravity = Direction.down;
                    else if (accelState.Acceleration.X < -0.35 && (accelState.Acceleration.Y > -0.5 && accelState.Acceleration.Y < 0.5) && (accelState.Acceleration.Z > -0.85 && accelState.Acceleration.Z < 0.85))
                        g.gravity = Direction.right;
                    else if (accelState.Acceleration.Y < -0.35 && (accelState.Acceleration.X > -0.5 && accelState.Acceleration.X < 0.5) && (accelState.Acceleration.Z > -0.85 && accelState.Acceleration.Z < 0.85))
                        g.gravity = Direction.up;
                    g.player.update();
                    break;
                case GameState.paws:
                    paws.update();
                    break;
                case GameState.mainMenu:
                    mainMenu.update();
                    break;
                case GameState.endScreen:
                    endMenu.update();
                    break;
                case GameState.highScores:
                    highScores.update();
                    break;
                case GameState.instructions:
                    instructions.update();
                    break;
                default:
                    break;
            }
            base.Update(gameTime);
        }
Ejemplo n.º 8
0
Archivo: Main.cs Proyecto: jhedin/Orbs
        /// <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)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            Stack<int> done = new Stack<int>();
            Circle circ;
            for (int i = 0; i < updateList.Count; i++)
            {
                circ = updateList[i];
                if (circ.updateLoc())
                {
                    done.Push(i);
                    circ.randColour();
                }
            }
            while (done.Count != 0)
            {
                updateList.RemoveAt(done.Pop());
            }
            //random mode
            if (counter >= counterCmp)
            {
                int X = randGenerator.Next(242);
                int Y = randGenerator.Next(480);
                TreeNode tNode = search(X, Y);
                tNode.split();
                if (nodeCount > 1075)
                {
                    counterCmp = 1075 - 2 * nodeCount/counterCmp;
                }
                if (nodeCount > 4500)
                {
                    Initialize();
                }
                counter = 1000;
            }
            counter++;

            //user input
            touchCollection = TouchPanel.GetState();
            foreach (TouchLocation touch in touchCollection)
            {
                TreeNode tNode = search((int)touch.Position.X, (int)touch.Position.Y);
                if (tNode.inCircle(touch.Position))
                    tNode.split();
                counter = 0;
                counterCmp = 1075;
            }

            accelState = Accelerometer.GetState();

            if (accelState.Acceleration.LengthSquared() > 1.5)
            {
                Initialize();
            }

            base.Update(gameTime);
        }
Ejemplo n.º 9
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)
        {
            base.Update(gameTime);

            touchCollection = TouchPanel.GetState();
            accelerometerState = Accelerometer.GetState();

            // Use X axis to determine if the Zune is being viewed from the
            // left or right side.
            // Leave fixed for now, need to rethink recalculating marble
            // positions when screen is rotated.

            if (accelerometerState.Acceleration.X >= 0.0 &&
                accelerometerState.Acceleration.X < 1.0)
            {
                screenOrientation = ScreenOrientation.LandscapeRight;
                screenRotation = 4.72f;
            }
            else
            {
                screenOrientation = ScreenOrientation.LandscapeLeft;
                screenRotation = 1.57f;
            }

            if (screenOrientation != priorScreenOrientation)
            {
                if (GameState == GameState.Play2D)
                    mainGame.RecalculateMarblePositions();

                priorScreenOrientation = screenOrientation;
            }

            if (NextGameState != GameState.None)
            {
                ChangeGameState();
            }
        }
Ejemplo n.º 10
0
        // Gets player horizontal movement and jump commands from input.
        private void GetInput(
            KeyboardState keyboardState,
            GamePadState gamePadState,
            AccelerometerState accelState,
            DisplayOrientation orientation)
        {
            // Get analog horizontal movement.
            movement = gamePadState.ThumbSticks.Left.X * GlobalConstants.MoveStickScale;

            // Ignore small movements to prevent running in place.
            if (Math.Abs(movement) < 0.5f)
                movement = 0.0f;

            // Move the player with accelerometer
            if (Math.Abs(accelState.Acceleration.Y) > 0.10f)
            {
                // set our movement speed
                movement = MathHelper.Clamp(-accelState.Acceleration.Y * GlobalConstants.AccelerometerScale, -1f, 1f);

                // if we're in the LandscapeLeft orientation, we must reverse our movement
                if (orientation == DisplayOrientation.LandscapeRight)
                    movement = -movement;
            }

            // If any digital horizontal movement input is found, override the analog movement.
            if (gamePadState.IsButtonDown(Buttons.DPadLeft) ||
                keyboardState.IsKeyDown(Keys.Left) ||
                keyboardState.IsKeyDown(Keys.A))
            {
                movement = -1.0f;
            }
            else if (gamePadState.IsButtonDown(Buttons.DPadRight) ||
                     keyboardState.IsKeyDown(Keys.Right) ||
                     keyboardState.IsKeyDown(Keys.D))
            {
                movement = 1.0f;
            }

            // Check if the player wants to jump.
            isJumping =
                gamePadState.IsButtonDown(GlobalConstants.JumpButton) ||
                keyboardState.IsKeyDown(Keys.Space) ||
                keyboardState.IsKeyDown(Keys.Up) ||
                keyboardState.IsKeyDown(Keys.W);
        }
Ejemplo n.º 11
0
        // Handles input, performs physics, and animates the player sprite.
        // Pass the game's orientation because when using the accelerometer,
        // we need to reverse our motion when the orientation is in the LandscapeRight orientation.
        public void Update(
            GameTime gameTime,
            KeyboardState keyboardState,
            GamePadState gamePadState,
            AccelerometerState accelState,
            DisplayOrientation orientation)
        {
            GetInput(keyboardState, gamePadState, accelState, orientation);

            if (previousKeyboardState.IsKeyUp(Keys.F) && keyboardState.IsKeyDown(Keys.F))
            {
                if (AttackTime != GlobalConstants.MaxAttackTime)
                {
                    isAttacking = true;
                    AttackTime = GlobalConstants.MaxAttackTime;
                }
            }

            DoAttack(gameTime);

            ApplyPhysics(gameTime);

            if (IsAlive && IsOnGround)
            {
                if (isAttacking)
                {
                    sprite.PlayAnimation(attackAnimation);

                }
                else
                {
                    if (Math.Abs(Velocity.X) - 0.02f > 0)
                    {
                        sprite.PlayAnimation(runAnimation);
                    }
                    else
                    {
                        sprite.PlayAnimation(idleAnimation);
                    }
                }
            }

            //Basically saying if the player is alive, and is on the ground
            //then you can play the animation. and if he is in the air, then it applies velocity

            // Clear input.
            movement = 0.0f;
            isJumping = false;
            if (isOnGround)
            {
                numberOfJumps = 0;
            }
        }