Ejemplo n.º 1
0
 public Game1()
 {
     graphics = new GraphicsDeviceManager(this);
     gsm = new GamestateManager();
     //graphics.IsFullScreen = true;
     graphics.PreferredBackBufferHeight = 500;
     graphics.PreferredBackBufferWidth = 900;
     Content.RootDirectory = "Content";
     ExitGame = this;
     ch = new ControlHandler();
     r = new Random();
     p = new Player();
     hud = new HUD();
     oMenu = new OptionsMenu(graphics, Content);
     intro = new AsteroidsIntro();
     screenHeight = graphics.PreferredBackBufferHeight;
     screenWidth = graphics.PreferredBackBufferWidth;
     numOfAsteroids = 3;
     currentGameState = 1;
 }
Ejemplo 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 == 1)
            {
                if (Keyboard.GetState().IsKeyDown(Keys.E))
                {
                    currentGameState = 3;
                }
                else
                {
                    intro.IntroText();
                }
            }

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

                foreach (Asteroid a in asteroid)
                {
                    a.Update(gameTime);
                    a.CheckBoundries(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);

                    if (p.GetPlayerHitbox().Intersects(a.GetAsteroidHitbox()))
                    {
                        switch (a.GetSize())
                        {
                            case 1:
                                numOfAsteroids -= 1;
                                Vector2 temp = new Vector2((float)a.GetXPos(), (float)a.GetYPos());
                                asteroidKillList.Add(a);
                                p.SetLives((p.GetLife() - 1));
                                break;
                            case 2:
                                numOfAsteroids -= 1;
                                for (int i = 0; i < 2; i++)
                                {
                                    double angle = r.NextDouble() * 2 * Math.PI;
                                    newAsteroidList.Add(new Asteroid(new Vector2(a.GetXPos(), a.GetYPos()), 1, 3.0f, dir = new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle))));
                                    numOfAsteroids += 1;
                                }
                                asteroidKillList.Add(a);
                                p.SetLives((p.GetLife() - 1));
                                break;
                            case 3:
                                numOfAsteroids -= 1;
                                for (int i = 0; i < 2; i++)
                                {
                                    double angle = r.NextDouble() * 2 * Math.PI;
                                    newAsteroidList.Add(new Asteroid(new Vector2(a.GetXPos(), a.GetYPos()), 2, 3.0f, dir = new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle))));
                                    numOfAsteroids += 1;
                                }
                                asteroidKillList.Add(a);
                                p.SetLives((p.GetLife() - 1));
                                break;
                            default:
                                System.Windows.Forms.MessageBox.Show("Oeps");
                                break;
                        }
                    }
                }

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

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

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

                asteroidKillList.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:
                                    asteroidKillList.Add(a);
                                    killListWep.Add(wep);
                                    hud.SetScore(10);
                                    numOfAsteroids -= 1;
                                    break;
                                case 2:
                                    for (int i = 0; i < 2; i++)
                                    {
                                        double angle = r.NextDouble() * 2 * Math.PI;
                                        newAsteroidList.Add(new Asteroid(new Vector2(a.GetXPos(), a.GetYPos()), 1, 3.0f, dir = new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle))));
                                        numOfAsteroids += 1;
                                    }
                                    asteroidKillList.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(new Vector2(a.GetXPos(), a.GetYPos()), 2, 3.0f, dir = new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle))));
                                        numOfAsteroids += 1;
                                    }
                                    asteroidKillList.Add(a);
                                    killListWep.Add(wep);
                                    hud.SetScore(50);
                                    break;
                                default:

                                    break;
                            }
                        }
                    }
                }

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

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

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

            if (currentGameState == 5)
            {
                if (Keyboard.GetState().IsKeyDown(Keys.F))
                {
                    currentGameState = 2;
                }
                else
                {
                    oMenu.Update(ch);
                }
            }

            if (currentGameState == 8)
            {
                if (loadingScreen != null)
                {
                    IsFixedTimeStep = false;
                    loader = loadingScreen.Update();
                    if (loader != null)
                    {
                        loadingScreen = null;
                        IsFixedTimeStep = true;
                    }
                }
            }

            base.Update(gameTime);
        }
Ejemplo n.º 3
0
        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            gsm = new GamestateManager();
            //graphics.IsFullScreen = true;
            graphics.PreferredBackBufferHeight = 500;
            graphics.PreferredBackBufferWidth = 900;
            Content.RootDirectory = "Content";
            ExitGame = this;
            ch = new ControlHandler();
            r = new Random();
            p = new Player(ch);
            scores = new Highscores();

            intro = new AsteroidsIntro();
            credit = new Credit();

            screenHeight = graphics.PreferredBackBufferHeight;
            screenWidth = graphics.PreferredBackBufferWidth;
            drawShield = false;
            intersected = false;
            randomized = false;
            shield = new Classes.Perks.ShieldPerk(Content, p);
            speedUp = new Classes.Perks.SpeedUpPerk(Content, p);
            extraLife = new Classes.Perks.ExtraLifePerk(Content, p);
            machineGun = new Classes.Perks.MachineGunPerk(Content, p);
            hud = new HUD(screenWidth, screenHeight, shield);
            pickUp = new Pickup();

            numOfAsteroids = 3;
            currentGameState = 1;
        }
Ejemplo n.º 4
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()
        {
            asteroidKillList = new List<Asteroid>();
            asteroid = new List<Asteroid>();
            newAsteroidList = new List<Asteroid>();
            killListWep = new List<Weapon>();
            mainMenu = new MainMenu(Content, graphics.GraphicsDevice, ch);
            hud = new HUD(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);

            for (int i = 0; i < numOfAsteroids; i++)
            {
                rndNum = r.Next(1, 3);

                switch (rndNum)
                {
                    case 1:
                        rnd2 = r.Next(0, screenHeight);
                        rnd1 = r.Next(-100, 0);
                        break;
                    case 2:
                        rnd2 = r.Next(screenHeight, screenHeight + 100);
                        rnd1 = r.Next(0, screenWidth);
                        break;
                    default:
                        System.Windows.Forms.MessageBox.Show("oeps");
                        rnd1 = 0;
                        rnd2 = 0;
                        break;
                }
                double speed = r.NextDouble() * 3 * Math.PI;
                System.Threading.Thread.Sleep(1);
                double angle = r.NextDouble() * 2 * Math.PI;
                asteroid.Add(new Asteroid(new Vector2(rnd1, rnd2), r.Next(1, 4), (float)speed, dir = new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle)), Content));
            }

            loader = new Loader(this.Content);
            base.Initialize();
        }
Ejemplo n.º 5
0
        public void Update(GameTime gameTime, HUD hud, Highscores scores, ControlHandler contHand)
        {
            MouseState mouse = Mouse.GetState();
            Point mousePoint = new Point(mouse.X, mouse.Y);
            textScore = hud.GetScore().ToString();
            SelectName(mouse, mousePoint, gameTime, contHand, scores);
            //Rectangle mouseRec = new Rectangle((int)mouse.X, (int)mouse.Y, 1,1);
            //if (recRetry.Contains(mousePoint))
            //{
            //    if (mouse.LeftButton == ButtonState.Pressed && mouseReleased == true)
            //    {
            //        gameStateNumber = 2;
            //        mouseReleased = false;
            //    }
            //}
            //if (recMainMenu.Contains(mousePoint))
            //{
            //    if (mouse.LeftButton == ButtonState.Pressed && mouseReleased == true)
            //    {
            //        gameStateNumber = 1;
            //        mouseReleased = false;
            //    }
            //}
            //if (recSubmit.Contains(mousePoint))
            //{
            //    if (mouse.LeftButton == ButtonState.Pressed && mouseReleased == true)
            //    {
            //        scores.AddHighscore(hud.GetScore(), Name);
            //        scores.SaveHighScores();
            //        scores.LoadHighScores();
            //        scores.SortHighScores();

            //        mouseReleased = false;
            //    }
            //}
            //if (mouse.LeftButton == ButtonState.Released)
            //{
            //    mouseReleased = true;
            //}
        }