Пример #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)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }
            MouseInput.Poll(gameTime);
            if (xMenu != null)
            {
                xMenu.Update(gameTime);
            }
            Monitor.UpdateCalled();
            // TODO: Add your update logic here

            base.Update(gameTime);
        }
Пример #2
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)
        {
            Menu.Update(gameTime);
            MonoMenu.Engine.Monitor.UpdateCalled();
            MouseInput.Poll(gameTime);
            Camera.Instance.Tick();

            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            if (Keyboard.GetState().IsKeyDown(Keys.Space))
            {
                pause = true;
            }
            else
            {
                pause       = false;
                passedTime += gameTime.ElapsedGameTime.TotalMilliseconds;
                if (passedTime > 33)
                {
                    Galaxy.Instance.UpdateGalaxyOptimizedThreaded();
                    passedTime = 0;
                }
            }

            if (Keyboard.GetState().IsKeyDown(Keys.Enter))
            {
                Planet target = Galaxy.Instance.Planets[0];
                foreach (Planet potential in Galaxy.Instance.Planets)
                {
                    double targetDistance    = Math.Pow(target.posX - Camera.Instance.Position.X, 2) + Math.Pow(target.posY - Camera.Instance.Position.Y, 2);
                    double potentialDistance = Math.Pow(potential.posX - Camera.Instance.Position.X, 2) + Math.Pow(potential.posY - Camera.Instance.Position.Y, 2);
                    if (potentialDistance < targetDistance)
                    {
                        target = potential;
                    }
                }
                Camera.Instance.Follow(target);
                Camera.Instance.Zoom = (float)(100 / target.size);
            }

            if (Keyboard.GetState().IsKeyDown(Keys.OemPlus))
            {
                Constants.TIME_CONSTANT *= 2;
            }

            if (Keyboard.GetState().IsKeyDown(Keys.OemMinus))
            {
                Constants.TIME_CONSTANT /= 2;
            }

            if (Keyboard.GetState().IsKeyDown(Keys.W))
            {
                Camera.Instance.MoveCamera(new Vector2D(0, -1000));
            }
            if (Keyboard.GetState().IsKeyDown(Keys.S))
            {
                Camera.Instance.MoveCamera(new Vector2D(0, 1000));
            }
            if (Keyboard.GetState().IsKeyDown(Keys.A))
            {
                Camera.Instance.MoveCamera(new Vector2D(-1000, 0));
            }
            if (Keyboard.GetState().IsKeyDown(Keys.D))
            {
                Camera.Instance.MoveCamera(new Vector2D(1000, 0));
            }

            if (Keyboard.GetState().IsKeyDown(Keys.F))
            {
                if (Camera.Instance.Following is Planet)
                {
                    Camera.Instance.Follow((Camera.Instance.Following as Planet).Star);
                    Thread.Sleep(50);
                }
                else
                {
                    Planet target = Galaxy.Instance.Planets[0];
                    bool   found  = false;
                    while (!System.Threading.Monitor.TryEnter(Galaxy.Instance.planetListLock))
                    {
                        ;
                    }
                    foreach (Planet potential in Galaxy.Instance.Planets)
                    {
                        double targetDistance    = Math.Pow(target.posX - Camera.Instance.Position.X, 2) + Math.Pow(target.posY - Camera.Instance.Position.Y, 2);
                        double potentialDistance = Math.Pow(potential.posX - Camera.Instance.Position.X, 2) + Math.Pow(potential.posY - Camera.Instance.Position.Y, 2);
                        if (found)
                        {
                            if (potentialDistance < targetDistance && potential.PlanetHabitability == Planet.Habitability.M)
                            {
                                target = potential;
                            }
                        }
                        else
                        {
                            if (potential.PlanetHabitability == Planet.Habitability.M)
                            {
                                target = potential;
                                found  = true;
                            }
                        }
                    }
                    if (found || target.PlanetHabitability == Planet.Habitability.M)
                    {
                        Camera.Instance.Follow(target);
                    }
                    System.Threading.Monitor.Exit(Galaxy.Instance.planetListLock);
                }
            }
            // TODO: Add your update logic here

            base.Update(gameTime);
        }