Beispiel #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 || Keyboard.GetState().IsKeyDown(Keys.Escape))
                this.Exit();

            if (!IsActive) return;

            if (Helper.Random.Next(10) == 1)
            {
                Vector3 pos = new Vector3(100f, -50f+((float)Helper.Random.NextDouble()*100f), 5f + ((float)Helper.Random.NextDouble()*10f));
                Vector3 col = (Vector3.One * 0.5f) + (Vector3.One*((float)Helper.Random.NextDouble()*0.5f));
                if(scrollSpeed>0f) gameStarfield.Spawn(pos, new Vector3((-0.1f-((float)Helper.Random.NextDouble()*1f)) * 5f, 0f, 0f), 0.5f, new Color(col), 20000, false);
            }

            if (scrollPos < (gameWorld.X_CHUNKS-11) * (Chunk.X_SIZE * Voxel.SIZE))
            {
                scrollDist += (scrollSpeed*1.5f);
                scrollPos += scrollSpeed;
                gameCamera.Target.X = scrollPos;

                if (scrollDist >= Chunk.X_SIZE * Voxel.SIZE && scrollColumn<gameWorld.X_CHUNKS-1)
                {
                    scrollDist = 0f;
                    for (int yy = 0; yy < 11; yy++)
                        if (tileLayer.Tiles[scrollColumn, yy] != null) gameWorld.CopySprite(scrollColumn * Chunk.X_SIZE, yy * Chunk.Y_SIZE, 0, tilesSprite.AnimChunks[tileLayer.Tiles[scrollColumn, yy].Index - 1]);
                    scrollColumn++;
                }
            }
            else if(scrollSpeed>0f) scrollSpeed -= 0.01f;

            MouseState cms = Mouse.GetState();
            KeyboardState cks = Keyboard.GetState();
            GamePadState cgs = GamePad.GetState(PlayerIndex.One);

            Vector2 virtualJoystick = Vector2.Zero;
            if (cks.IsKeyDown(Keys.W) || cks.IsKeyDown(Keys.Up)) virtualJoystick.Y = -1;
            if (cks.IsKeyDown(Keys.A) || cks.IsKeyDown(Keys.Left)) virtualJoystick.X = -1;
            if (cks.IsKeyDown(Keys.S) || cks.IsKeyDown(Keys.Down)) virtualJoystick.Y = 1;
            if (cks.IsKeyDown(Keys.D) || cks.IsKeyDown(Keys.Right)) virtualJoystick.X = 1;
            //if (virtualJoystick.Length() > 0f) virtualJoystick.Normalize();
            //if (cgs.ThumbSticks.Left.Length() > 0.1f)
            //{
            //    virtualJoystick = cgs.ThumbSticks.Left;
            //    virtualJoystick.Y = -virtualJoystick.Y;
            //}

            gameHero.Move(virtualJoystick);

            if (cks.IsKeyDown(Keys.Z)) gameHero.Fire();

            lms = cms;
            lks = cks;
            lgs = cgs;

            gameCamera.Update(gameTime, gameWorld);
            gameWorld.Update(gameTime, gameCamera);

            gameHero.Update(gameTime, gameCamera, gameWorld, scrollSpeed);

            enemyController.Update(gameTime, gameCamera, gameHero, gameWorld, scrollPos, scrollSpeed);
            projectileController.Update(gameTime, gameCamera, gameHero, gameWorld, scrollPos);
            particleController.Update(gameTime, gameCamera, gameWorld);
            powerupController.Update(gameTime, gameCamera, gameWorld, gameHero, scrollPos);
            gameStarfield.Update(gameTime, gameCamera, gameWorld, scrollSpeed);

            drawEffect.View = gameCamera.viewMatrix;
            drawEffect.World = gameCamera.worldMatrix;

            base.Update(gameTime);
        }