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

            KeyboardState currentKeyState = Keyboard.GetState();
            GamePadState  currentPadState = GamePad.GetState(PlayerIndex.One);
            switch (currentState)
            {
                case ScreenState.Level:
                    {
                        waitForKeyPress();
                        break;
                    }
                case ScreenState.Start:
                    {
                        if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
                            this.Exit();
                        waitForKeyPress();
                        break;
                    }

                case ScreenState.Pause:
                    {
                        if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
                            this.Exit();
                        waitForKeyPress();

                        break;
                    }
                case ScreenState.End:
                    {
                        if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
                            this.Exit();
                        if ((GamePad.GetState(PlayerIndex.One).Buttons.Start == ButtonState.Pressed || currentKeyState.IsKeyDown(Keys.P)) && (lastKeyState.IsKeyUp(Keys.P) && lastpadState.IsButtonUp(Buttons.Start)))
                        {
                            currentState = ScreenState.Start;
                            level = 1;
                            plyr = new Player(new Vector3(0, 0, 50));
                            plyr.LoadContent();
                        } 
                        
                        lastKeyState = currentKeyState;
                        lastpadState = currentPadState;
                        break;
                    }
                case ScreenState.Play:
                    {
                        if ((GamePad.GetState(PlayerIndex.One).Buttons.Start == ButtonState.Pressed || currentKeyState.IsKeyDown(Keys.P)) && (lastKeyState.IsKeyUp(Keys.P) && lastpadState.IsButtonUp(Buttons.Start)))
                        {
                            currentState = ScreenState.Pause;
                        }
                        lastKeyState = currentKeyState;
                        lastpadState = currentPadState;
                        if (!plyr.isAlive())
                        {
                            currentState = ScreenState.End;
                        }
                        if (enemy.isAlive())
                        {
                            enemy.Update(gameTime);
                        }
                        else
                        {
                            if (level == 1)
                            {
                                v = v + plyr.health;
                            }

                            level++;
                            plyr.health += 2;
                            plyr.Score(v);
                            enemy = new Enemy(new Vector3(0, -3f, -30));
                            enemy.LoadContent();

                            if (level == 2)
                            {
                                currentState = ScreenState.Level;
                                v = 2;
                                if (plyr.health > 0 && plyr.health <= 6)
                                {
                                    v = plyr.health + v;
                                }
                                enemy.health ++;
                            }
                            if (level == 3)
                            {
                                currentState = ScreenState.Level;
                                v = 4;
                                if (plyr.health > 0 && plyr.health <=6)
                                {
                                    v = plyr.health + v;
                                }
                                enemy.health ++;
                            }
                            if (level > 3)
                            {
                                currentState = ScreenState.End;
                            }
                        }


                        // TODO: Add your update logic here
                        radar.Update(gameTime, plyr.Look());
                        plyr.Update(gameTime);
                        for (int i = 0; i < _bullets.Count; i++)
                        {
                            if (_bullets[i].isAlive())
                            {
                                _bullets[i].Update(gameTime);
                            }
                            else
                            {
                                _bullets.RemoveAt(i);
                            }
                        }

                        foreach (Obstacle obstacle in _obstacles)
                        {
                            obstacle.Update(gameTime);
                        }
                        break;
                    }
            }
            base.Update(gameTime);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            _bullets = new List<Bullet>();
            _obstacles = new List<Obstacle>();
            enemy = new Enemy(new Vector3(0, -3f, -30));
            plyr = new Player(new Vector3(0, 0, 120));
            radar = new Radar();

            //obstacles spawn in random locations
            Random rand = new Random();
#if (!DEBUG_PATHS || !DEBUG )
            for (int num = 0; num < 50; num++)
            {
               
                int x = rand.Next(-300, 500);
                int z = rand.Next(-300, 500);
                
                //draw obstacle if it does not spawn on an enemy or the player
                Obstacle tempObstacle = (new Obstacle(new Vector3(x, 0, z)));
                tempObstacle.LoadContent();
                if (!tempObstacle.collidesWith(enemy.getBoundingSphere(), enemy.getWorld()) && !tempObstacle.collidesWith(plyr.getBoundingSphere(), plyr.getWorld()))
                {
                    _obstacles.Add(tempObstacle);
                }
            }
#else
            Obstacle tmp = new Obstacle(new Vector3(7,0,-65));
            _obstacles.Add(tmp);
#endif

#if DEBUG
            currentState = ScreenState.Play;
#else
            currentState = ScreenState.Start;
#endif
            lastKeyState = Keyboard.GetState();
            lastpadState = GamePad.GetState(PlayerIndex.One);
            base.Initialize();
        }