Exemplo n.º 1
0
        public void InitializeGame()
        {
            health = new Healthbar(graphicsDevice);
            health.Initialize();

            floor = new Floor(graphicsDevice);
            floor.Initialize();

            ExplosionManager.Initialize(graphicsDevice);

            EntityManager.Add(Ship.Instance);

            camera = new Camera(graphicsDevice);
        }
Exemplo n.º 2
0
        public void Update(GameTime gameTime)
        {
            if ((health == 0) && (ending == false))
            {
                ending = true;
                Game1.Explode.Play(0.4f, Game1.NextFloat(rand, 0.4f, 0.4f), 0);
                ExplosionManager.Add(new Explosion(Ship.Instance.Position, 0, 63));
                Ship.Instance.IsExpired = true;
            }


            if (ending == true)
            {
                if (endtime <= 3.0f)
                {
                    endtime += (float)gameTime.ElapsedGameTime.TotalSeconds;
                }
            }
        }
Exemplo n.º 3
0
 public void Draw()
 {
     if (gameState == 0)
     {
         MainMenu.Begin();
         MainMenu.Draw(MainBack, new Rectangle(0, 0, 800, 900), Color.White);
         MainMenu.Draw(MainHeader, new Rectangle(0, 0, 800, 200), Color.White);
         MainMenu.Draw(MainButton, new Rectangle(200, 250, 400, 100), Color.White);
         MainMenu.DrawString(MainButtonName, "Level 1", new Vector2(230, 265), Color.Black);
         MainMenu.Draw(MainButton, new Rectangle(200, 400, 400, 100), Color.White * locked2);
         MainMenu.DrawString(MainButtonName, "Level 2", new Vector2(230, 415), Color.Black * locked2);
         MainMenu.Draw(MainButton, new Rectangle(200, 550, 400, 100), Color.White * locked3);
         MainMenu.DrawString(MainButtonName, "Level 3", new Vector2(230, 565), Color.Black * locked3);
         MainMenu.Draw(MainButton, new Rectangle(200, 700, 400, 100), Color.White);
         MainMenu.DrawString(MainButtonName, "Credits", new Vector2(230, 715), Color.Black);
         MainMenu.End();
         graphicsDevice.BlendState        = BlendState.Opaque;
         graphicsDevice.DepthStencilState = DepthStencilState.Default;
     }
     else if (gameState == 1)
     {
         MainMenu.Begin();
         MainMenu.Draw(MainBack, new Rectangle(0, 0, 800, 900), Color.White);
         MainMenu.Draw(MainHeader, new Rectangle(0, 0, 800, 200), Color.White);
         MainMenu.Draw(MainButton, new Rectangle(200, 700, 400, 100), Color.White);
         MainMenu.DrawString(MainButtonName, "Credits:", new Vector2(200, 265), Color.Black);
         MainMenu.DrawString(CreditsText, "Explosion Texture: \r\n\r\nhttps://opengameart.org/content/explosion-sheet", new Vector2(200, 365), Color.Black * locked2);
         MainMenu.DrawString(CreditsText, "Music and Sounds: \r\n\r\nhttp://musmus.main.jp/english.html", new Vector2(200, 515), Color.Black * locked2);
         MainMenu.DrawString(MainButtonName, "Back", new Vector2(230, 715), Color.Black);
         MainMenu.End();
         graphicsDevice.BlendState        = BlendState.Opaque;
         graphicsDevice.DepthStencilState = DepthStencilState.Default;
     }
     else
     {
         EntityManager.Draw(camera);
         floor.Draw(camera);
         ExplosionManager.Draw(camera);
         health.Draw();
     }
 }
Exemplo n.º 4
0
        static void HandleCollisions()
        {
            // handle collisions between bullets and enemy1
            for (int i = 0; i < enemy1.Count; i++)
            {
                for (int j = 0; j < playerbullets.Count; j++)
                {
                    if (IsColliding(enemy1[i], playerbullets[j]))
                    {
                        enemy1[i].health--;
                        playerbullets[j].IsExpired = true;
                        Game1.PlayerShoot.Play(0.4f, 0.8f, 0);
                        ExplosionManager.Add(new Explosion(enemy1[i].Position, 0, 2));
                        if (enemy1[i].health <= 0)
                        {
                            Game1.Explode.Play(0.4f, Game1.NextFloat(rand, 0.4f, 0.4f), 0);
                            ExplosionManager.Add(new Explosion(enemy1[i].Position, 0, 63));
                            enemy1[i].IsExpired = true;
                        }
                    }
                }
            }

            // handle collisions between bullets and enemy2
            for (int i = 0; i < enemy2.Count; i++)
            {
                for (int j = 0; j < playerbullets.Count; j++)
                {
                    if (IsColliding(enemy2[i], playerbullets[j]))
                    {
                        enemy2[i].health--;
                        playerbullets[j].IsExpired = true;
                        Game1.PlayerShoot.Play(0.4f, 0.8f, 0);
                        ExplosionManager.Add(new Explosion(enemy2[i].Position, 0, 2));
                        if (enemy2[i].health <= 0)
                        {
                            Game1.Explode.Play(0.4f, Game1.NextFloat(rand, 0.4f, 0.4f), 0);
                            ExplosionManager.Add(new Explosion(enemy2[i].Position, 0, 63));
                            enemy2[i].IsExpired = true;
                        }
                    }
                }
            }

            // handle collisions between bullets and player
            for (int i = 0; i < enemybullets.Count; i++)
            {
                if (IsColliding(Ship.Instance, enemybullets[i]))
                {
                    Healthbar.Hit();
                    enemybullets[i].IsExpired = true;
                    Game1.EnemyShoot.Play(0.4f, -0.8f, 0);
                }
            }

            // handle collisions between bullets and boss shield
            for (int i = 0; i < shield.Count; i++)
            {
                for (int j = 0; j < playerbullets.Count; j++)
                {
                    if (IsColliding(shield[i], playerbullets[j]))
                    {
                        shield[i].health--;
                        boss[0].health--;
                        playerbullets[j].IsExpired = true;
                        Game1.PlayerShoot.Play(0.4f, 0.8f, 0);
                        ExplosionManager.Add(new Explosion(shield[i].Position, 0, 2));
                        if (shield[i].health <= 0)
                        {
                            Game1.Explode.Play(0.4f, Game1.NextFloat(rand, 0.4f, 0.4f), 0);
                            ExplosionManager.Add(new Explosion(shield[i].Position, 0, 63));
                            shield[i].IsExpired = true;
                        }
                    }
                }
            }

            // handle collisions between bullets and boss core
            for (int i = 0; i < core.Count; i++)
            {
                for (int j = 0; j < playerbullets.Count; j++)
                {
                    if (IsColliding(core[i], playerbullets[j]))
                    {
                        core[i].health--;
                        boss[0].health--;
                        playerbullets[j].IsExpired = true;
                        Game1.PlayerShoot.Play(0.4f, 0.8f, 0);
                        ExplosionManager.Add(new Explosion(core[i].Position, 0, 2));
                        if (core[i].health <= 0)
                        {
                            Game1.Explode.Play(0.4f, Game1.NextFloat(rand, 0.4f, 0.4f), 0);
                            ExplosionManager.Add(new Explosion(core[i].Position, 0, 63));
                            core[i].IsExpired = true;
                        }
                    }
                }
            }

            //remove boss when cores destroyed
            if (core.Count > 0)
            {
                bossSpawned = true;
            }
            else if ((core.Count == 0) && (bossSpawned == true))
            {
                for (int i = 0; i < turret.Count; i++)
                {
                    turret[i].IsExpired = true;
                }
                ExplosionManager.Add(new Explosion(boss[0].Position, 0, 63));
                boss[0].IsExpired = true;
                bossSpawned       = false;
            }
        }
Exemplo n.º 5
0
        public void Update(GameTime gameTime)
        {
            if ((Mouse.GetState().LeftButton == ButtonState.Pressed) && (gameState < 2))
            {
                clicked = true;
            }

            if ((Mouse.GetState().LeftButton == ButtonState.Released) && (gameState < 2) && (clicked == true))
            {
                clicked  = false;
                mousePos = new Point(Mouse.GetState().X, Mouse.GetState().Y);
                if (Level1.Contains(mousePos))
                {
                    InitializeGame();
                    gameState           = 2;
                    game.IsMouseVisible = false;
                    MediaPlayer.Play(Game1.Ingame);
                    Game1.Select.Play(0.2f, 0, 0);
                }
                else if ((Level2.Contains(mousePos)) && (locked2 == 1f))
                {
                    InitializeGame();
                    gameState           = 3;
                    game.IsMouseVisible = false;
                    MediaPlayer.Play(Game1.Ingame);
                    Game1.Select.Play(0.2f, 0, 0);
                }
                else if ((Level3.Contains(mousePos)) && (locked3 == 1f))
                {
                    InitializeGame();
                    gameState           = 4;
                    game.IsMouseVisible = false;
                    MediaPlayer.Play(Game1.Boss);
                    Game1.Select.Play(0.2f, 0, 0);
                }
                else if (Credits.Contains(mousePos))
                {
                    Game1.SelectCredits.Play(0.2f, 0, 0);
                    if (gameState == 0)
                    {
                        gameState = 1;
                    }
                    else
                    {
                        gameState = 0;
                    }
                }
            }

            if (gameState > 1)
            {
                EntityManager.Update(gameTime);
                floor.Update(gameTime);
                ExplosionManager.Update(gameTime);
                camera.Update(gameTime);
                health.Update(gameTime);
                if (speed == -100)
                {
                    speed = 3.0f;
                }
                else if (speed <= 0.15f)
                {
                    speed = 0.15f;
                    remain--;
                }
            }

            if (gameState == 2)
            {
                if (cooldown <= speed)
                {
                    cooldown += (float)gameTime.ElapsedGameTime.TotalSeconds;
                }
                else
                {
                    if (remain > 0)
                    {
                        Spawning(0);
                        cooldown = 0;
                        speed   -= speed * 0.05f;
                    }
                    else
                    {
                        if (EntityManager.enemy1.Count == 0)
                        {
                            if (ending <= 3.0f)
                            {
                                ending += (float)gameTime.ElapsedGameTime.TotalSeconds;
                            }
                            else
                            {
                                gameState = 0;
                                EntityManager.ResetAll();
                                locked2 = 1f;
                                ending  = 0;
                            }
                        }
                    }
                }
            }
            else if (gameState == 3)
            {
                if (cooldown <= speed)
                {
                    cooldown += (float)gameTime.ElapsedGameTime.TotalSeconds;
                }
                else
                {
                    if (remain > 0)
                    {
                        if (level2spawn > 1)
                        {
                            Spawning(0);
                            level2spawn--;
                        }
                        else
                        {
                            Spawning(1);
                            level2spawn = 3;
                        }

                        cooldown = 0;
                        speed   -= speed * 0.05f;
                    }
                    else
                    {
                        if ((EntityManager.enemy1.Count == 0) && (EntityManager.enemy2.Count == 0))
                        {
                            if (ending <= 3.0f)
                            {
                                ending += (float)gameTime.ElapsedGameTime.TotalSeconds;
                            }
                            else
                            {
                                gameState = 0;
                                EntityManager.ResetAll();
                                locked3 = 1f;
                                ending  = 0;
                            }
                        }
                    }
                }
            }
            else if (gameState == 4)
            {
                if (spawnedboss == false)
                {
                    if (cooldown <= 4.0f)
                    {
                        cooldown += (float)gameTime.ElapsedGameTime.TotalSeconds;
                    }
                    else
                    {
                        EntityManager.Add(new EnemyBoss(new Vector3(90, -40, 20)));
                        cooldown    = 0;
                        spawnedboss = true;
                    }
                }

                if ((EntityManager.boss.Count == 0) && (spawnedboss == true))
                {
                    if (ending <= 3.0f)
                    {
                        ending += (float)gameTime.ElapsedGameTime.TotalSeconds;
                    }
                    else
                    {
                        gameState = 0;
                        EntityManager.ResetAll();
                        locked3 = 1f;
                        ending  = 0;
                    }
                }
            }
        }