Example #1
0
        public override void Update(GameLoop gameLoop)
        {
            FontHandler.AddText(new Text("My house is secure", "menu1", new Vector2(Program.Window.Width / 2, 100), 2f, false));
            FontHandler.AddText(new Text("start game", "menu2", new Vector2(Program.Window.Width / 2, 350), 1f, false));
            FontHandler.AddText(new Text("exit", "menu3", new Vector2(Program.Window.Width / 2, 420), 1f, false));

            if (Input.GetState(0).Mouse.LeftButton)
            {
                if (GameObject.Contains(Input.GetState(0).MousePosition, button1))
                {
                    button1.color        = Color4.DarkBlue;
                    button1Outline.color = Color4.Blue;
                }
                else if (GameObject.Contains(Input.GetState(0).MousePosition, button2))
                {
                    button2.color        = Color4.DarkGreen;
                    button2Outline.color = Color4.Green;
                }
            }
            else
            {
                button1.color        = Color4.Blue;
                button1Outline.color = Color4.DarkBlue;
                button2.color        = Color4.Green;
                button2Outline.color = Color4.DarkGreen;
            }
        }
Example #2
0
 public static void Draw()
 {
     FontHandler.AddText(new Text(PlayerAmmo.ToString(), "ammo", new Vector2(35, 85), 0.4f, true));
     FontHandler.AddText(new Text(PlayerHealth.ToString(), "health", new Vector2(35, 110), 0.5f, true));
     FontHandler.AddText(new Text(PlayerMoney.ToString(), "monies", new Vector2(35, 143.5f), 0.5f, true));
     Weapon.Draw();
     Hud.Draw();
 }
Example #3
0
        public override void Update(GameLoop gameLoop)
        {
            if (!startedMusic && Program.MenuMusic != null)
            {
                Program.MenuMusic.Gain = 0;
                Program.MenuMusic.Play();
                startedMusic = true;
            }

            if (!begin && alpha > 0)
            {
                alpha -= 0.001f;
                if (Program.MenuMusic != null && Program.MenuMusic.Gain < 0.25)
                {
                    Program.MenuMusic.Gain += 0.00025f;
                }
                if (Program.Music != null && Program.Music.Gain > 0)
                {
                    Program.Music.Gain -= 0.00025f;
                }
            }
            if (alpha <= 0 && !begin)
            {
                if (Program.MenuMusic != null && Program.MenuMusic.Gain < 0.25)
                {
                    Program.MenuMusic.Gain += 0.00025f;
                }
                if (Program.Music != null && Program.Music.Gain > 0)
                {
                    Program.Music.Gain -= 0.00025f;
                }
                if (!showQuitMessage)
                {
                    if (Input.GetState(0).Keyboard[Key.Up] && arrow.Position.Y != 228)
                    {
                        ContentManager.GetSound("select").Play();
                        arrow.Position.Y = 228;
                    }
                    if (Input.GetState(0).Keyboard[Key.Down] && arrow.Position.Y != 228 + 45)
                    {
                        ContentManager.GetSound("select").Play();
                        arrow.Position.Y = 228 + 45;
                    }
                    if (Input.GetState(0).Keyboard[Key.Enter] && !Input.GetState(1).Keyboard[Key.Enter])
                    {
                        ContentManager.GetSound("select").Play();
                        if (arrow.Position.Y == 228)
                        {
                            begin = true;
                        }
                        else
                        {
                            showQuitMessage = true;
                            Random rand = new Random();
                            switch (rand.Next(0, 8))
                            {
                            case 0:
                                FontHandler.AddText(new MetalLib.Pencil.Gaming.Text("For guns and glory, press N ", "quit1", new Vector2(640 / 2, 480 / 2 - 25), 0.5f, false));
                                FontHandler.AddText(new MetalLib.Pencil.Gaming.Text("For work and worry, press Y", "quit2", new Vector2(640 / 2, 480 / 2 + 25), 0.5f, false));
                                break;

                            case 1:
                                FontHandler.AddText(new MetalLib.Pencil.Gaming.Text("Press N if you are brave", "quit1", new Vector2(640 / 2, 480 / 2 - 25), 0.5f, false));
                                FontHandler.AddText(new MetalLib.Pencil.Gaming.Text("Press Y to cower in shame", "quit2", new Vector2(640 / 2, 480 / 2 + 25), 0.5f, false));
                                break;

                            case 2:
                                FontHandler.AddText(new MetalLib.Pencil.Gaming.Text("You are at an intersection", "quit1", new Vector2(640 / 2, 480 / 2 - 25), 0.5f, false));
                                FontHandler.AddText(new MetalLib.Pencil.Gaming.Text("A sign says, `press Y to quit.`", "quit2", new Vector2(640 / 2, 480 / 2 + 25), 0.5f, false));
                                break;

                            case 3:
                                FontHandler.AddText(new MetalLib.Pencil.Gaming.Text("Press N to save the world", "quit1", new Vector2(640 / 2, 480 / 2 - 25), 0.5f, false));
                                FontHandler.AddText(new MetalLib.Pencil.Gaming.Text("Press Y to abandon it in its hour of need", "quit2", new Vector2(640 / 2, 480 / 2 + 25), 0.5f, false));
                                break;

                            case 4:
                                FontHandler.AddText(new MetalLib.Pencil.Gaming.Text("Press N for more carnage", "quit1", new Vector2(640 / 2, 480 / 2 - 25), 0.5f, false));
                                FontHandler.AddText(new MetalLib.Pencil.Gaming.Text("Press Y to be a weenie", "quit2", new Vector2(640 / 2, 480 / 2 + 25), 0.5f, false));
                                break;

                            case 5:
                                FontHandler.AddText(new MetalLib.Pencil.Gaming.Text("Heroes, press N", "quit1", new Vector2(640 / 2, 480 / 2 - 25), 0.5f, false));
                                FontHandler.AddText(new MetalLib.Pencil.Gaming.Text("Whimps, press Y", "quit2", new Vector2(640 / 2, 480 / 2 + 25), 0.5f, false));
                                break;

                            case 6:
                                FontHandler.AddText(new MetalLib.Pencil.Gaming.Text("Chickening out...", "quit1", new Vector2(640 / 2, 480 / 2 - 25), 0.5f, false));
                                FontHandler.AddText(new MetalLib.Pencil.Gaming.Text("already?", "quit2", new Vector2(640 / 2, 480 / 2 + 25), 0.5f, false));
                                break;

                            default:
                                FontHandler.AddText(new MetalLib.Pencil.Gaming.Text("Dost thou wish to leave with ", "quit1", new Vector2(640 / 2, 480 / 2 - 25), 0.5f, false));
                                FontHandler.AddText(new MetalLib.Pencil.Gaming.Text("such hasty abandon? Y / N", "quit2", new Vector2(640 / 2, 480 / 2 + 25), 0.5f, false));
                                break;
                            }
                        }
                    }
                }
                else
                {
                    if (Input.GetState(0).Keyboard['Y'])
                    {
                        ContentManager.GetSound("select").Play();
                        gameLoop.Run = false;
                    }
                    else if (Input.GetState(0).Keyboard['N'])
                    {
                        ContentManager.GetSound("select").Play();
                        showQuitMessage      = false;
                        FontHandler.TextList = new List <MetalLib.Pencil.Gaming.Text>();
                    }
                }
            }
            if (begin)
            {
                if (Program.MenuMusic.Gain > 0.0)
                {
                    Program.MenuMusic.Gain -= 0.00025f;
                }
                if (alpha < 1f)
                {
                    alpha += 0.001f;
                    Glfw.SetTime(0.0);
                }
                else
                {
                    Program.TotalTime += (float)Glfw.GetTime();
                    double delta = Glfw.GetTime();
                    if (Program.TotalTime > 1f)
                    {
                        Glfw.SetTime(0.0);
                    }
                    psycheTime -= delta;
                    if (psycheTime <= 0)
                    {
                        GL.Color4(Color4.White);
                        if (gameplayState == null)
                        {
                            gameLoop.ActiveGameState = new GamePlayState();
                        }
                        else
                        {
                            gameLoop.ActiveGameState = gameplayState;
                        }
                    }
                }
            }
        }
Example #4
0
        public override void Update(GameLoop gameLoop)
        {
            FontHandler.AddText(new Text("150", "0", new Vector2(150, 480), 1f, false));
            FontHandler.AddText(new Text("150", "1", new Vector2(150 + 248, 480), 1f, false));
            FontHandler.AddText(new Text("50", "2", new Vector2(150 + (248 * 2), 480), 1f, false));
            FontHandler.AddText(new Text("50", "3", new Vector2(150 + (248 * 3), 480), 1f, false));
            FontHandler.AddText(new Text("125", "4", new Vector2(150 + (248 * 4), 480), 1f, false));
            FontHandler.AddText(new Text("TO SPEND: " + HudHandler.PlayerMoney, "money", new Vector2(Program.Window.Width / 2, 600), 1f, false));



            if (Input.GetState(0).Mouse.LeftButton&& !Input.GetState(1).Mouse.LeftButton)
            {
                int i = 0;
                foreach (GameObject g in boxes)
                {
                    if (GameObject.Contains(Input.GetState(0).MousePosition, g))
                    {
                        if (i == 0 && !Player.hasMP7 && HudHandler.PlayerMoney >= 150)
                        {
                            Player.hasMP7           = true;
                            HudHandler.PlayerMoney -= 150;
                            ContentManager.GetSound("cashRegister").Play();
                        }
                        if (i == 1 && !Player.hasShotgun && HudHandler.PlayerMoney >= 150)
                        {
                            Player.hasShotgun       = true;
                            HudHandler.PlayerMoney -= 150;
                            ContentManager.GetSound("cashRegister").Play();
                        }
                        if (i == 2 && HudHandler.PlayerMoney >= 50)
                        {
                            HudHandler.PlayerAmmo  += 100;
                            HudHandler.PlayerMoney -= 50;
                            ContentManager.GetSound("cashRegister").Play();
                        }
                        if (i == 3 && HudHandler.PlayerMoney >= 50)
                        {
                            HudHandler.PlayerHealth = 100;
                            HudHandler.PlayerMoney -= 50;
                            ContentManager.GetSound("cashRegister").Play();
                        }
                        if (i == 4 && HudHandler.PlayerMoney >= 125)
                        {
                            HudHandler.PlayerHealth = 250;
                            HudHandler.PlayerMoney -= 125;
                            ContentManager.GetSound("cashRegister").Play();
                        }
                        if (i == 5)
                        {
                            FontHandler.TextList = new List <Text>();
                            GameplayState.InShop = false;
                            GameplayState.currentWave++;
                            game.GameWorld      = Loader.LoadMap();
                            game.zombiesSpawned = 0;
                        }
                    }
                    i++;
                }
            }
        }
Example #5
0
 public override void Update(GameLoop gameLoop)
 {
     FontHandler.TextList = new List <Text>();
     FontHandler.AddText(new Text("UR DEAD :]", "teehee", new Vector2(Program.Window.Width / 2, Program.Window.Height / 2), 2f, false));
     FontHandler.AddText(new Text("SPACE TO TRY AGAIN", "teehee2", new Vector2(Program.Window.Width / 2, Program.Window.Height / 2 + 50), 1f, false));
 }
Example #6
0
 public override void Update(GameLoop gameLoop)
 {
     if (!musicPlaying)
     {
         if (ContentManager.GetSound("music") != null)
         {
             ContentManager.GetSound("music").Play();
             ContentManager.GetSound("music").Looping = true;
             musicPlaying = true;
         }
     }
     if (!InShop)
     {
         if (ScreenShakeDuration > 0)
         {
             int    intensity = 15;
             int    speed     = 15;
             Random r         = new Random();
             CameraPos = GameUtils.MoveTowards(CameraPos, new Vector2(r.Next(0, intensity) - intensity / 2, r.Next(0, intensity) - intensity / 2), speed);
             ScreenShakeDuration--;
         }
         else
         {
             if (GameUtils.GetDistance(CameraPos, Vector2.Zero) > 1)
             {
                 CameraPos = GameUtils.MoveTowards(CameraPos, new Vector2(0, 0), 1f);
             }
             else
             {
                 CameraPos = Vector2.Zero;
             }
         }
         spawntimer--;
         if (spawntimer <= 0 && zombiesSpawned < waveThreshold[currentWave])
         {
             List <GameObject> woot = GameWorld.getGameGrid("ground").ToGameObjectCollection("temp").ObjectList.Where(x => x.textureName == "grass").ToList();
             int r = new Random().Next(0, woot.Count);
             if (GameWorld.getGameGrid("walls").Grid[((Tile)woot[r]).X, ((Tile)woot[r]).Y] == null)
             {
                 ZombieList.Add(new Zombie("zombie", new Vector2((((Tile)woot[r]).X * 32) + 8, (((Tile)woot[r]).Y * 32) + 8)));
                 ContentManager.GetSound("zombie").Play();
                 zombiesSpawned++;
             }
             if (currentWave == 0)
             {
                 spawntimer = new Random().Next(80, 250);
             }
             else
             if (currentWave == 1)
             {
                 spawntimer = new Random().Next(80, 175);
             }
             else
             if (currentWave == 2)
             {
                 spawntimer = new Random().Next(50, 150);
             }
             else
             if (currentWave == 3)
             {
                 spawntimer = new Random().Next(45, 125);
             }
             else
             if (currentWave == 4)
             {
                 spawntimer = new Random().Next(30, 100);
             }
         }
         if (zombiesSpawned >= waveThreshold[currentWave] && ZombieList.Count == 0)
         {
             InShop    = true;
             shopState = new ShopState(this);
         }
         Player.Rotation = (float)GameUtils.GetRotation(Player.Position, Input.GetState(0).MousePosition - new Vector2((Program.Window.Width / 2) - ((GridWidth * 16) - 16), (Program.Window.Height / 2) - ((GridHeight * 16) - 16))) + 90;
         for (int i = 0; i < 3; i++)
         {
             Vector2 newpos = Player.Position, oldpos = Player.Position;
             if (Input.GetState(0).Keyboard['W'])
             {
                 if (newpos.Y > 8)
                 {
                     newpos.Y--;
                 }
             }
             if (Input.GetState(0).Keyboard['S'])
             {
                 if (newpos.Y < Program.Window.Height - 40)
                 {
                     newpos.Y++;
                 }
             }
             if (Input.GetState(0).Keyboard['A'])
             {
                 if (newpos.X > 8)
                 {
                     newpos.X--;
                 }
             }
             if (Input.GetState(0).Keyboard['D'])
             {
                 if (newpos.X < 1272)
                 {
                     newpos.X++;
                 }
             }
             Player.Position = newpos;
             bool collision = false;
             foreach (GameObject x in GameWorld.getGameGrid("walls").ToGameObjectCollection("temp").ObjectList)
             {
                 if (GameObject.Intersects(Player, x))
                 {
                     if (x.textureName == "door")
                     {
                         if (((Door)x).IsOpen)
                         {
                             continue;
                         }
                         else
                         {
                             ((Door)x).IsOpen = true;
                             ContentManager.GetSound("doorSound").Play();
                         }
                     }
                     collision = true;
                     break;
                 }
             }
             if (collision)
             {
                 Player.Position.X = oldpos.X;
                 collision         = false;
                 foreach (GameObject x in GameWorld.getGameGrid("walls").ToGameObjectCollection("temp").ObjectList)
                 {
                     if (GameObject.Intersects(Player, x))
                     {
                         if (x.textureName == "door")
                         {
                             if (((Door)x).IsOpen)
                             {
                                 continue;
                             }
                             else
                             {
                                 ((Door)x).IsOpen = true;
                                 ContentManager.GetSound("doorSound").Play();
                             }
                         }
                         collision = true;
                         break;
                     }
                 }
                 if (collision)
                 {
                     Player.Position.X = newpos.X;
                     Player.Position.Y = oldpos.Y;
                     collision         = false;
                     foreach (GameObject x in GameWorld.getGameGrid("walls").ToGameObjectCollection("temp").ObjectList)
                     {
                         if (GameObject.Intersects(Player, x))
                         {
                             if (x.textureName == "door")
                             {
                                 if (((Door)x).IsOpen)
                                 {
                                     continue;
                                 }
                                 else
                                 {
                                     ((Door)x).IsOpen = true;
                                     ContentManager.GetSound("doorSound").Play();
                                 }
                             }
                             collision = true;
                             break;
                         }
                     }
                     if (collision)
                     {
                         Player.Position = oldpos;
                     }
                 }
             }
         }
         Player.Update(ref ProjectileList);
         ProjectileList = ProjectileList.Where(x => !x.remove).ToList();
         ProjectileList.ForEach(x => x.Update(GameWorld, ZombieList, ref ParticleList));
         ParticleList = ParticleList.Where(x => !x.remove).ToList();
         ParticleList.ForEach(x => x.Update(0.25f));
         ZombieList = ZombieList.Where(x => !x.remove).ToList();
         ZombieList.ForEach(x => x.Update(Player, GameWorld));
         for (int x = 0; x < GridWidth; x++)
         {
             for (int y = 0; y < GridHeight; y++)
             {
                 if (GameWorld.getGameGrid("walls").Grid[x, y] != null)
                 {
                     if (GameWorld.getGameGrid("walls").Grid[x, y].remove)
                     {
                         GameWorld.getGameGrid("walls").Grid[x, y] = null;
                     }
                 }
             }
         }
         FontHandler.AddText(new Text("WAVE: " + (currentWave + 1) + " - Zombies: " + zombiesSpawned + " / " + waveThreshold[currentWave], "wave", new Vector2(Program.Window.Width / 2, 20), 1f, false));
     }
     else
     {
         shopState.Update(gameLoop);
     }
 }