Esempio n. 1
0
 public Game1()
 {
     graphics = new GraphicsDeviceManager(this);
     //graphics.IsFullScreen = true;
     graphics.PreferredBackBufferHeight = 500;
     graphics.PreferredBackBufferWidth = 900;
     Content.RootDirectory = "Content";
     r = new Random();
     p = new Player();
     hud = new HUD();
     numOfAsteroids = 5;
 }
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)
        {
            // Allows the game to exit
            if (Keyboard.GetState().IsKeyDown(Keys.Escape))
                this.Exit();

            gsm.GameStateChanger(currentGameState);
            if (currentGameState == 3)
            {
                p.Update(gameTime);
                p.CheckBoundries(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);
                hud.Update(gameTime);

                foreach (Asteroid ast in asteroid)
                {
                    ast.Update(gameTime);
                    ast.CheckBoundries(graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight);

                    if (p.GetPlayerHitbox().Intersects(ast.GetAsteroidHitbox()))
                    {
                        switch (ast.GetSize())
                        {
                            case 1:
                               /* for (int i = 0; i < 1; i++)
                                {
                                    newAsteroidList.Add(new Asteroid(ast.getXPos(), ast.getYPos(), 0, .0f, Vector2.Zero, Content));
                                }*/
                                asteroidList.Add(ast);
                                p.SetLives((p.GetLife() - 1));
                                break;
                            case 2:
                                for (int i = 0; i < 2; i++)
                                {
                                    double angle = r.NextDouble() * 2 * Math.PI;
                                    newAsteroidList.Add(new Asteroid(ast.getXPos(), ast.getYPos(), 1, 3.0f, dir = new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle)), Content));
                                }
                                asteroidList.Add(ast);
                                p.SetLives((p.GetLife() - 1));
                                break;
                            case 3:
                                for (int i = 0; i < 2; i++)
                                {
                                    double angle = r.NextDouble() * 2 * Math.PI;
                                    newAsteroidList.Add(new Asteroid(ast.getXPos(), ast.getYPos(), 2, 3.0f, dir = new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle)), Content));
                                }
                                asteroidList.Add(ast);
                                p.SetLives((p.GetLife() - 1));
                                break;
                            default:

                                break;
                        }
                        ast.Update(gameTime);
                        ast.ExplodeAnimation(gameTime);
                    }
                }

                if (asteroid.Count == 0)
                {
                    LevelsIncrease();
                }

                foreach (Asteroid a in newAsteroidList)
                {
                    asteroid.Add(a);
                }

                foreach (Asteroid a in asteroidList)
                {
                    asteroid.Remove(a);
                }

                asteroidList.Clear();
                newAsteroidList.Clear();

                foreach (Weapon wep in p.weapList)
                {
                    wep.Update(gameTime, wep.GetDirection());
                    wep.CheckBoundries(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);

                    if (wep.GetFadeTime() == 0)
                    {
                        wep.SetIsVisable(false);
                        killListWep.Add(wep);
                    }

                    foreach (Asteroid a in asteroid)
                    {
                        if (wep.GetHitbox().Intersects(a.GetAsteroidHitbox()))
                        {
                            switch (a.GetSize())
                            {
                                case 1:
                                    /*for (int i = 0; i < 2; i++)
                                    {
                                        newAsteroidList.Add(new Asteroid(ast.getXPos(), ast.getYPos(), 0, .0f, Vector2.Zero, Content));
                                    }*/
                                    asteroidList.Add(a);
                                    killListWep.Add(wep);
                                    hud.SetScore(10);
                                    break;
                                case 2:
                                    for (int i = 0; i < 2; i++)
                                    {
                                        double angle = r.NextDouble() * 2 * Math.PI;
                                        newAsteroidList.Add(new Asteroid(a.getXPos(), a.getYPos(), 1, 3.0f, dir = new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle)),Content));
                                    }
                                    asteroidList.Add(a);
                                    killListWep.Add(wep);
                                    hud.SetScore(25);
                                    break;
                                case 3:
                                    for (int i = 0; i < 2; i++)
                                    {
                                        double angle = r.NextDouble() * 2 * Math.PI;
                                        newAsteroidList.Add(new Asteroid(a.getXPos(), a.getYPos(), 2, 3.0f, dir = new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle)),Content));
                                    }
                                    asteroidList.Add(a);
                                    killListWep.Add(wep);
                                    hud.SetScore(50);
                                    break;
                                default:

                                    break;
                            }
                            a.ExplodeAnimation(gameTime);
                        }
                    }
                }

                foreach (Weapon weap in killListWep)
                {
                    p.weapList.Remove(weap);
                }

                playerLife = p.GetLife();
                if (playerLife <= 0)
                {
                    p.RocketExplosion(gameTime);
                    //currentGameState = 4;
                }
            }

            if (currentGameState == 4)
            {
                if (Keyboard.GetState().IsKeyDown(Keys.Enter))
                {
                    numOfAsteroids = 5;
                    r = new Random();
                    p = new Player(Content);
                    hud = new HUD();
                    Initialize();
                    currentGameState = 3;
                }
            }

            base.Update(gameTime);
        }