Esempio n. 1
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            FogOfWar.LoadContent(Content);
            Planet.LoadContent(Content);
            //.LoadContent(Content);
            Chunk.LoadContent(Content);
            NoiseGenerator.LoadTextures(Content);

            Space.spriteFont = Content.Load <SpriteFont>("Fonts/MainFont");

            GameOptions gameOptions = new GameOptions(NumberOfSolarSystems.Normal, NumberOfPlantes.Normal, GameSpeed.Normal);

            // TODO move and optimize imports to LIB , for client only

            //Fonts.Load(Content); TODO Implement
            Models.Load(Content);

            SpaceRts.Models.Base = Models.Zhus_Base;
            SpaceRts.Models.Load(Content);
            Textures.Load(Content);
            Shaders.Load(Content);

            Space = new Space(1423, gameOptions, 3, graphics);

            Global.Camera = new Camera(GraphicsDevice);

            PlayButton = new ClickableText(PlayPosition, "Play", Space.spriteFont, Color.White, new Point(0, 0), (GameTime gameTime) => {
                PlayButtonClicked = true;
                TimePlayClicked   = gameTime.TotalGameTime.TotalSeconds;
            });

            SettingsButton = new ClickableText(PlayPosition + new Point(0, (int)Space.spriteFont.MeasureString("Play").Y + 50), "Settigs", Space.spriteFont, Color.White, new Point(0, 0), (GameTime gameTime) => {
                GameSteate = GameSteates.Settings;
            });

            ExitButton = new ClickableText(PlayPosition + new Point(0, (int)Space.spriteFont.MeasureString("Settigs").Y + 50) + new Point(0, (int)Space.spriteFont.MeasureString("Play").Y + 50), "Exit", Space.spriteFont, Color.White, new Point(0, 0), (GameTime gameTime) => {
                Exit();
            });

            _planetRenderTarget = new RenderTarget2D(GraphicsDevice, (int)(GraphicsDevice.Viewport.Width * 0.625f + 1), GraphicsDevice.Viewport.Height / 2, false, SurfaceFormat.Color, DepthFormat.None);

            Shaders.MainMenu.Parameters["resolution"].SetValue(new Vector2(_planetRenderTarget.Width * 1.25f, _planetRenderTarget.Height));

            // TODO: use this.Content to load your game content here
        }
Esempio n. 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)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            MouseState    mouseState    = Mouse.GetState();
            KeyboardState keyboardState = Keyboard.GetState();

            if (GameSteate == GameSteates.MainMenu)
            {
                PlayButton.Update(gameTime, mouseState);
                SettingsButton.Update(gameTime, mouseState);
                ExitButton.Update(gameTime, mouseState);

                if (PlayButtonClicked && TimePlayClicked - gameTime.TotalGameTime.TotalSeconds < -Math.PI * 0.75)
                {
                    GameSteate = GameSteates.Game;
                }
            }

            if (GameSteate == GameSteates.Game)
            {
                Global.MouseState    = mouseState;
                Global.KeyboardState = keyboardState;

                if (PlanetOrSolarSwitchCulldown <= 0)
                {
                    if (keyboardState.IsKeyDown(Keys.Left))
                    {
                        Global.SelectedPlanet      -= 1;
                        PlanetOrSolarSwitchCulldown = 2000;
                    }
                    else if (keyboardState.IsKeyDown(Keys.Right))
                    {
                        Global.SelectedPlanet      += 1;
                        PlanetOrSolarSwitchCulldown = 2000;
                    }

                    if (keyboardState.IsKeyDown(Keys.Up) && keyboardState.IsKeyUp(Keys.LeftControl))
                    {
                        Global.SelectedSolarSystem += 1;
                        PlanetOrSolarSwitchCulldown = 2000;
                    }
                    else if (keyboardState.IsKeyDown(Keys.Down) && keyboardState.IsKeyUp(Keys.LeftControl))
                    {
                        Global.SelectedSolarSystem -= 1;
                        PlanetOrSolarSwitchCulldown = 2000;
                    }
                }
                else
                {
                    PlanetOrSolarSwitchCulldown -= gameTime.ElapsedGameTime.TotalMilliseconds;
                }

                Global.Camera.Update(gameTime, mouseState, keyboardState);

                Vector2 mousePosition = mouseState.Position.ToVector2();

                Vector3 nearPoint = new Vector3(mousePosition, 0);
                Vector3 farPoint  = new Vector3(mousePosition, 1);

                nearPoint = GraphicsDevice.Viewport.Unproject(nearPoint, Global.Camera.ProjectionMatrix, Global.Camera.ViewMatrix, Matrix.Identity);
                farPoint  = GraphicsDevice.Viewport.Unproject(farPoint, Global.Camera.ProjectionMatrix, Global.Camera.ViewMatrix, Matrix.Identity);

                Vector3 direction = farPoint - nearPoint;
                direction.Normalize();

                Global.ClickRay = new Ray(nearPoint, direction);

                Space.Update();

                if (keyboardState.IsKeyDown(Keys.NumPad1))
                {
                    Global.Camera.position     = new Vector3(30, 30, 40);
                    Global.Camera.lookAtVector = new Vector3(0, 0, 0);
                    cameraPerspective          = CameraPerspectives.closeUp;
                }
                else if (keyboardState.IsKeyDown(Keys.NumPad2))
                {
                    Global.Camera.position     = new Vector3(600, 600, 600);
                    Global.Camera.lookAtVector = new Vector3(80, 80, 0);
                    cameraPerspective          = CameraPerspectives.closeUp;
                }
                else if (keyboardState.IsKeyDown(Keys.NumPad3))
                {
                    Global.Camera.position     = new Vector3(2100, 1800, 1800);
                    Global.Camera.lookAtVector = new Vector3(300, 300, 0);
                    cameraPerspective          = CameraPerspectives.map;
                }
            }

            if (keyboardState.IsKeyDown(Keys.F12))
            {
                goneFullScreen = true;

                graphics.PreferredBackBufferWidth  = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width;
                graphics.PreferredBackBufferHeight = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height;

                _planetRenderTarget = new RenderTarget2D(GraphicsDevice, (int)(GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width), GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height, false, SurfaceFormat.Color, DepthFormat.None);
                Shaders.MainMenu.Parameters["resolution"].SetValue(new Vector2(_planetRenderTarget.Width * 1.25f, _planetRenderTarget.Height));


                graphics.ToggleFullScreen();
                graphics.ApplyChanges();
            }

            base.Update(gameTime);
        }