Ejemplo n.º 1
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 (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }

            //Update the Touches BEFORE updating the Game Objects
            TouchCollection    touch      = TouchPanel.GetState();
            AccelerometerState accelstate = Accelerometer.GetState();

            phsX.Gravity = (float)9.8 * (new Vector2(accelstate.Acceleration.X, -accelstate.Acceleration.Y));

            foreach (TouchLocation tl in touch)
            {
                foreach (Geom b in phsX.GeomList)
                {
                    b.Body.ApplyForce((tl.Position - b.Position) / (float)2.0);
                }
            }

            phsX.Update((float)(1.0 / 30.0)); //Update physX

            base.Update(gameTime);
        }
Ejemplo n.º 2
0
 public virtual void UpdatePhysics(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
 {
     if (!coveredByOtherScreen && !otherScreenHasFocus)
     {
         PhysicsSimulator.Update(gameTime.ElapsedGameTime.Milliseconds * 0.001f);
     }
 }
Ejemplo n.º 3
0
 public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
 {
     if (IsActive)
     {
         PhysicsSimulator.Update(gameTime.ElapsedGameTime.Milliseconds * .001f);
     }
     base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
 }
Ejemplo n.º 4
0
        protected override void Update(GameTime gameTime)
        {
            net.Update();
            if (net.SessionState == NetworkSessionState.Playing)
            {
                netData  = "";
                netData += Convert.ToString(this.getMouse().X) + "|";
                netData += Convert.ToString(this.getMouse().Y) + "|";
                netData += Convert.ToString(this.getMouse().LeftButton) + "|";
                netData += Convert.ToString(this.getMouse().RightButton) + "|";

                // Send any key pressed to the remote player
                foreach (Keys key in Keyboard.GetState().GetPressedKeys())
                {
                    netData += key.ToString() + "|";
                }

                keysPressed = false;
                foreach (Microsoft.Xna.Framework.Input.Keys value in Enum.GetValues(typeof(Microsoft.Xna.Framework.Input.Keys)))
                {
                    if (this.isKeyPressed(value))
                    {
                        keysPressed = true;
                        key         = Convert.ToString(value);
                        if (key != previousKey)
                        {
                            theText += key;
                        }
                        previousKey = key;
                    }
                }
                if (keysPressed == false)
                {
                    previousKey = "";
                }
                this.test.changeText(theText);



                net.SendMessage(netData);

                // Receive the keys from the remote player
                net.ReceiveMessage();
            }
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }

            // TODO: Add your update logic here
            gameLogic();
            ps.Update(gameTime.ElapsedGameTime.Milliseconds * 0.001f);//PHYSICS

            this.gameTimeInfo = gameTime;
            base.Update(gameTime);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Allows the screen to run logic, such as updating the transition position.
        /// Unlike <see cref="HandleInput"/>, this method is called regardless of whether the screen
        /// is active, hidden, or in the middle of a transition.
        /// </summary>
        public virtual void Update(GameTime gameTime, bool otherScreenHasFocus,
                                   bool coveredByOtherScreen)
        {
            _otherScreenHasFocus = otherScreenHasFocus;

            if (_isExiting)
            {
                // If the screen is going away to die, it should transition off.
                _screenState = ScreenState.TransitionOff;

                if (!UpdateTransition(gameTime, _transitionOffTime, 1))
                {
                    // When the transition finishes, remove the screen.
                    ScreenManager.RemoveScreen(this);

                    _isExiting = false;
                }
            }
            else if (coveredByOtherScreen)
            {
                // If the screen is covered by another, it should transition off.
                if (UpdateTransition(gameTime, _transitionOffTime, 1))
                {
                    // Still busy transitioning.
                    _screenState = ScreenState.TransitionOff;
                }
                else
                {
                    // Transition finished!
                    _screenState = ScreenState.Hidden;
                }
            }
            else
            {
                // Otherwise the screen should transition on and become active.
                if (UpdateTransition(gameTime, _transitionOnTime, -1))
                {
                    // Still busy transitioning.
                    _screenState = ScreenState.TransitionOn;
                }
                else
                {
                    // Transition finished!
                    _screenState = ScreenState.Active;
                }
            }

            if (!coveredByOtherScreen && !otherScreenHasFocus)
            {
                PhysicsSimulator.Update(gameTime.ElapsedGameTime.Milliseconds * .001f);
            }
        }
Ejemplo n.º 6
0
        public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
        {
            if (IsActive)
            {
                for (int i = 0; i < _spiders.Length; i++)
                {
                    _spiders[i].Update(gameTime);
                }
                PhysicsSimulator.Update(gameTime.ElapsedGameTime.Milliseconds * .001f);
            }

            base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
        }
Ejemplo n.º 7
0
 // POINT OF INTEREST
 // This is doing the actual physics update. It can be called on both threads. When there are
 // more HW threads present in the system /and the multithreaded processing isn't forced off/
 // it is going to be called by the physics thread, while the main thread is drawing.
 // Otherwise it is going to be called on the main thread, so there is no speed gain.
 private void DoThinkPhysics()
 {
     // POINT OF INTEREST
     // Unsignal the idle signal while working.
     _idleEvent.Reset();
     // POINT OF INTEREST
     // Linit the frame rate to 100ms. This is going to cause a slowdown in the simulator when
     // the framerate drops below 10FPS. But I think the lagg is more frustrating than the
     // slowdown. I prefer a little slowdown, instead of dying between two frames.
     _physicsSimulator.Update(Math.Min(_iterateParam.GameTime.ElapsedGameTime.Milliseconds, 100) * .001f);
     // POINT OF INTEREST
     // Done updating, now syncronise the links
     SyncronizeLinks();
     // POINT OF INTEREST
     // The physics thread is idle again
     _idleEvent.Set();
 }
Ejemplo n.º 8
0
        /// <summary>
        /// 编辑游戏逻辑,如更新,检测碰撞,收集输入,播放声音等 (循环方法)
        /// </summary>
        /// <param name="gameTime"></param>
        protected override void Update(GameTime gameTime)
        {
            /* 手柄第一个键退出 */
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }

            /* 键盘esc退出 */
            if (Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            /*------------------------移动圆形监听--------------------------*/
            if (Keyboard.GetState().IsKeyDown(Keys.Left))
            {
                boxBody2.ApplyForce(new Vector2(-400, 0));
                boxBody2.ApplyTorque(-5000f);
            }

            if (Keyboard.GetState().IsKeyDown(Keys.Right))
            {
                boxBody2.ApplyForce(new Vector2(400, 0));
                boxBody2.ApplyTorque(5000f);
            }

            if (Keyboard.GetState().IsKeyDown(Keys.Up))
            {
                boxBody2.ApplyForce(new Vector2(0, -400));
            }

            if (Keyboard.GetState().IsKeyDown(Keys.Down))
            {
                boxBody2.ApplyForce(new Vector2(0, 400));
            }
            /*-----------------------移动圆形监听结束-----------------------*/

            /* 物理引擎运行,注释后物理引擎失效 */
            physicsSimulator.Update(gameTime.ElapsedGameTime.Milliseconds * 0.001f);

            //HandlerMouseInput();

            base.Update(gameTime);
        }
Ejemplo n.º 9
0
        public override void Behave(GameTime gameTime)
        {
            showFill = false;
            Vector2 mouse = new Vector2(Mouse.GetState().X, Mouse.GetState().Y);

            foreach (var item in bodies[0].Mesh.Triangles)
            {
                if (item.IsInside(mouse))
                {
                    showFill = true;
                    break;
                }
            }

            form.Update(gameTime);
            base.Behave(gameTime);

            if (!paused)
            {
                sim.Update(gameTime);
            }
        }
Ejemplo n.º 10
0
        private void gameLoop_Update(TimeSpan elapsedTime)
        {
            if (!Visible)
            {
                return;
            }
            double secs = elapsedTime.TotalSeconds + _leftoverUpdateTime;

            while (secs > .01)
            {
                Update(elapsedTime);
                if (MenuActive == false)
                {
                    physicsSimulator.Update(.01f);
                    foreach (IDrawingBrush b in drawingList)
                    {
                        b.Update();
                    }
                }
                secs -= .01;
            }
            _leftoverUpdateTime = secs;
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Allows the game component to Update itself.
 /// </summary>
 /// <param name="gameTime">Provides a snapshot of timing values.</param>
 public override void Update(GameTime gameTime)
 {
     // TODO: Add your Update code here
     _physicsSimulator.Update(gameTime.ElapsedGameTime.Milliseconds * .001f);
     base.Update(gameTime);
 }
Ejemplo n.º 12
0
        /// <summary>
        /// Update Farseer Engine
        /// </summary>

        public static void Update(GameTime gameTime)
        {
            physics.Update((float)gameTime.ElapsedGameTime.TotalSeconds);
        }
Ejemplo n.º 13
0
 protected virtual void Update(TimeSpan span)
 {
     HandleKeyboardInput();
     physicsSimulator.Update((float)span.TotalSeconds);
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Allows the game component to update itself.
 /// </summary>
 /// <param name="gameTime">Provides a snapshot of timing values.</param>
 public override void Update(GameTime gameTime)
 {
     Simulator.Update(gameTime.ElapsedGameTime.Milliseconds * 0.005f);
     base.Update(gameTime);
 }
        private void MainStoryboard_Completed(object sender, EventArgs e)
        {
            textBlockCount.Text = string.Format("No. of blocks - {0}", GameObjects.Count - 1);

            // the game loop
            elapsedTime    = DateTime.Now - lastUpdateTime;
            lastUpdateTime = DateTime.Now;
            double secs = (elapsedTime.TotalMilliseconds / 1000.0) + leftoverUpdateTime;

            while (secs > .01)
            {
                physicsSimulator.Update(.01f);

                List <IGameObject> delete = new List <IGameObject>();
                foreach (IGameObject iGameObject in GameObjects)
                {
                    if (iGameObject.Body.Position.Y != Canvas.GetTop(iGameObject.UIElement))
                    {
                        Canvas.SetTop(iGameObject.UIElement, iGameObject.Body.Position.Y);
                    }

                    if (iGameObject.Body.Position.X != (double)Canvas.GetLeft(iGameObject.UIElement))
                    {
                        Canvas.SetLeft(iGameObject.UIElement, iGameObject.Body.Position.X);
                    }

                    double theAngle = (iGameObject.Body.Rotation * 360) / (2 * Math.PI);
                    if (theAngle != iGameObject.RotateTransform.Angle)
                    {
                        iGameObject.RotateTransform.Angle = theAngle;
                    }

                    if (iGameObject.Body.Position.X > 600 ||
                        iGameObject.Body.Position.X < -10 ||
                        iGameObject.Body.Position.Y > 600 ||
                        iGameObject.Body.Position.Y < -10)
                    {
                        delete.Add(iGameObject);
                    }

                    double y = (double)winLine.GetValue(Canvas.TopProperty);
                    if (winCountDown == false &&
                        iGameObject.Y < y)
                    {
                        winCountDown = true;
                        winnerBrick  = iGameObject;
                        winnerClock  = DateTime.Now;
                    }

                    if (winCountDown == true)
                    {
                        Int32 seconds = (DateTime.Now - winnerClock).Seconds;
                        textBlockCount.Text = string.Format("Win in {0} seconds.", 3 - seconds);
                    }
                }

                foreach (IGameObject iGameObject in delete)
                {
                    iGameObject.UIElement.Visibility = Visibility.Collapsed;
                    GameObjects.Remove(iGameObject);
                    TheCanvas.Children.Remove(iGameObject.UIElement);
                    iGameObject.Delete();
                }

                secs -= .01;
            }
            leftoverUpdateTime = secs;

            double winLineY = (double)winLine.GetValue(Canvas.TopProperty);

            if (winCountDown == true &&
                winnerBrick != null &&
                winnerBrick.Y < winLineY)
            {
                if (winnerClock.AddSeconds(3) <= DateTime.Now)
                {
                    running             = false;
                    textBlockCount.Text = "You Win!";
                    if ((double)winLine.GetValue(Canvas.TopProperty) < 1.0)
                    {
                        Play.Content    = "You are a Grand Champion!";
                        Play.Visibility = Visibility.Collapsed;
                    }
                    else
                    {
                        Play.Content    = "Next Level";
                        Play.Visibility = Visibility.Visible;
                    }
                }
            }
            else
            {
                winCountDown = false;
            }
            if (winCountDown == false &&
                running == true &&
                GameObjects.Count > 85)
            {
                Play.Content        = "Try Again";
                Play.Visibility     = Visibility.Visible;
                textBlockCount.Text = "Too many bricks!";
                running             = false;
            }

            if (running == true)
            {
                MainStoryboard.Begin();
            }
        }