Exemplo n.º 1
0
        public DeathState(MainGameState game, bool respawn) : base(game.Game)
        {
            Glfw.Enable(GlfwEnableCap.MouseCursor);

            Label deadLabel = new Label("YOU DEADED", Game);

            deadLabel.Position = new Vector2i(Game.Screen.Width, Game.Screen.Height) / 2 - TextureTools.MeasureString(deadLabel.Text, 4, 5) / 2;
            Gui.Add(deadLabel);

            if (respawn)
            {
                Button bSP = new Button(Game, "RESPAWN");
                bSP.Position      = new Vector2i(Game.Screen.Width / 2 - bSP.Image.Width / 2, Game.Screen.Height / 2 + 30);
                bSP.MouseClicked += (sender, e) => {
                    CheckPoint.Restore(game);
                    Game.CurrentGameState = game;
                    Glfw.Disable(GlfwEnableCap.MouseCursor);
                };
                Gui.Add(bSP);
            }
            else
            {
                Button bSP = new Button(Game, "QUIT");
                bSP.Position      = new Vector2i(Game.Screen.Width / 2 - bSP.Image.Width / 2, Game.Screen.Height / 2 + 30);
                bSP.MouseClicked += (sender, e) => {
                    Game.CurrentGameState = new MenuState(Game);
                };
                Gui.Add(bSP);
            }
        }
Exemplo n.º 2
0
 private void PlayerStepOnSpecialLoc(int x, int z)
 {
     if (CurrentLevel == 1 && !steppedOnLevel1Special)
     {
         steppedOnLevel1Special = true;
         Game.CurrentGameState  = new PlotScreen(Game,
                                                 "Good.\n\n" +
                                                 "Let me summarize the situation for you. You're in a bad place, you need to get out of here. There are guards pretty much everywhere. They are not good, shoot them on sight.\n" +
                                                 "Also, there are locations in here marked with a blue sphere with an arrow in the middle, these store space and time temporarily, so that if you happen to die, you can go back. If you grab enough of them, I might be able to warp you elsewhere.\n\n" +
                                                 "Shit, on the left! Shoot the bastards!",
                                                 (sender, e) => {
             Game.CurrentGameState = this;
             Glfw.Disable(GlfwEnableCap.MouseCursor);
         },
                                                 (sender, e) => {
             Game.CurrentGameState = this;
             Glfw.Disable(GlfwEnableCap.MouseCursor);
         });
     }
 }
Exemplo n.º 3
0
 public MainGameState(MainClass game, string ip, string uname, int port) : base(game)
 {
     IsMultiplayer = (ip != null);
     if (IsMultiplayer)
     {
         CurrentPlayer = new Player(this, 32, 32, uname);
         try {
             Client = new MultiplayerClient(this, ip, port);
             Client.SendConnectMessage(uname);
         } catch (Exception) {
             changeToRequest = true;
         }
     }
     else
     {
         LoadLevel(1);
     }
     if (!IsServer)
     {
         Glfw.Disable(GlfwEnableCap.MouseCursor);
     }
 }
Exemplo n.º 4
0
        public AreYouSure(MainGameState maingame) : base(maingame.Game)
        {
            Glfw.Enable(GlfwEnableCap.MouseCursor);

            Label deadLabel = new Label("ARE YOU SURE YOU WANT TO QUIT?", Game);

            deadLabel.Position = new Vector2i(Game.Screen.Width, Game.Screen.Height) / 2 - TextureTools.MeasureString(deadLabel.Text, 4, 5) / 2;
            Gui.Add(deadLabel);

            Button yes = new Button(Game, "YES");

            yes.Position      = new Vector2i(Game.Screen.Width / 2 - yes.Image.Width - 15, Game.Screen.Height / 2 + 30);
            yes.MouseClicked += (sender, e) => { Game.CurrentGameState = new MenuState(Game); };
            Gui.Add(yes);

            Button no = new Button(Game, "NO");

            no.Position      = new Vector2i(Game.Screen.Width / 2 + 15, Game.Screen.Height / 2 + 30);
            no.MouseClicked += (sender, e) => { Game.CurrentGameState = maingame; Glfw.Disable(GlfwEnableCap.MouseCursor); };
            Gui.Add(no);

            mainGame = maingame;
        }
Exemplo n.º 5
0
        public void LoadLevel(int level)
        {
            CheckPoint.ClearCheckPoints();
            CurrentLevel = -level;
            if (level > 0 && level < 4)
            {
                Blocks.Clear();
                Enemies.Clear();
                Crates.Clear();
                SpecialLocations.Clear();
                HealthPacks.Clear();
                Projectiles.Clear();
                DroppedWeapons.Clear();
                Texture2D tex = TextureTools.LoadTexture(IsServer, "level" + level + ".gif", new Rectanglei(0, 0, 64, 64));
                BlockGrid   = new Block[tex.Width, tex.Height];
                WorldWidth  = tex.Width;
                WorldHeight = tex.Height;
                List <Action> enemyAdditions = new List <Action>();
                for (int x = 0; x < tex.Width; ++x)
                {
                    int xReal = tex.Width - x - 1;
                    for (int z = 0; z < tex.Height; ++z)
                    {
                        Color c = tex.Get(x, z);
                        switch (c)
                        {
                        case 0xFFFF0000:
                            Blocks.Add(new Block(xReal, z, TextureTools.TextureWall1));
                            BlockGrid [xReal, z] = Blocks.Last();
                            break;

                        case 0xFF0000FF:
                            Blocks.Add(new Block(xReal, z, TextureTools.TextureWall2));
                            BlockGrid [xReal, z] = Blocks.Last();
                            break;

                        case 0xFFFFFF00:
                            if (!MainGameState.IsServer)
                            {
                                Blocks.Add(new Door(xReal, z, TextureTools.TextureDoor1, TextureTools.TextureDoor1Upper, TextureTools.TextureDoor1Lower));
                                BlockGrid [xReal, z] = Blocks.Last();
                            }
                            break;

                        case 0xFF333333:
                        {
                            int xRealCopy = xReal;
                            int zCopy     = z;
                            enemyAdditions.Add(() => {
                                    for (int i = 0; i < 2; ++i)
                                    {
                                        while (true)
                                        {
                                            float offsetX = ((float)MainClass.Random.NextDouble() - .5f);
                                            float offsetZ = ((float)MainClass.Random.NextDouble() - .5f);
                                            Enemy e       = new Enemy(xRealCopy + offsetX, zCopy + offsetZ);
                                            if (BlockGrid [(int)e.X, (int)e.Z] == null)
                                            {
                                                Enemies.Add(e);
                                                break;
                                            }
                                        }
                                    }
                                });
                        }
                        break;

                        case 0xFF666666:
                        {
                            int xRealCopy = xReal;
                            int zCopy     = z;
                            enemyAdditions.Add(() => {
                                    for (int i = 0; i < 4; ++i)
                                    {
                                        while (true)
                                        {
                                            float offsetX = ((float)MainClass.Random.NextDouble() - .5f);
                                            float offsetZ = ((float)MainClass.Random.NextDouble() - .5f);
                                            Enemy e       = new Enemy(xRealCopy + offsetX, zCopy + offsetZ);
                                            if (BlockGrid [(int)e.X, (int)e.Z] == null)
                                            {
                                                Enemies.Add(e);
                                                break;
                                            }
                                        }
                                    }
                                });
                        }
                        break;

                        case 0xFF999999:
                        {
                            int xRealCopy = xReal;
                            int zCopy     = z;
                            enemyAdditions.Add(() => {
                                    for (int i = 0; i < 6; ++i)
                                    {
                                        while (true)
                                        {
                                            float offsetX = ((float)MainClass.Random.NextDouble() - .5f);
                                            float offsetZ = ((float)MainClass.Random.NextDouble() - .5f);
                                            Enemy e       = new Enemy(xRealCopy + offsetX, zCopy + offsetZ);
                                            if (BlockGrid [(int)e.X, (int)e.Z] == null)
                                            {
                                                Enemies.Add(e);
                                                break;
                                            }
                                        }
                                    }
                                });
                        }
                        break;

                        case 0xFFCCCCCC:
                        {
                            int xRealCopy = xReal;
                            int zCopy     = z;
                            enemyAdditions.Add(() => {
                                    for (int i = 0; i < 8; ++i)
                                    {
                                        while (true)
                                        {
                                            float offsetX = ((float)MainClass.Random.NextDouble() - .5f);
                                            float offsetZ = ((float)MainClass.Random.NextDouble() - .5f);
                                            Enemy e       = new Enemy(xRealCopy + offsetX, zCopy + offsetZ);
                                            if (BlockGrid [(int)e.X, (int)e.Z] == null)
                                            {
                                                Enemies.Add(e);
                                                break;
                                            }
                                        }
                                    }
                                });
                        }
                        break;

                        case 0xFFFFFFFF:
                            if (!IsServer)
                            {
                                if (CurrentPlayer == null)
                                {
                                    CurrentPlayer = new Player(this, xReal, z, "LOCAL");
                                }
                                else
                                {
                                    CurrentPlayer.Position = new Vector2(xReal, z);
                                }
                            }

                            Spawn = new Vector2i(xReal, z);
                            break;

                        case 0xFF00FF00:
                            Crates.Add(new AmmoCrate(xReal + .5f, z + .5f));
                            break;

                        case 0xFFFF00FF:
                            HealthPacks.Add(new HealthPack(xReal + .5f, z + .5f));
                            break;

                        case 0xFF00FFFF:
                            if (!MainGameState.IsServer)
                            {
                                Projectiles.Add(new CheckPoint(xReal + .5f, z + .5f));
                            }
                            break;

                        case 0xFF808080:
                            SpecialLocations.Add(new Vector2i(xReal, z));
                            break;
                        }
                    }
                }
                foreach (Action a in enemyAdditions)
                {
                    a();
                }
            }
            else
            {
                CurrentLevel          = short.MinValue;
                Game.CurrentGameState = new PlotScreen(Game,
                                                       "So we meet at last.",
                                                       (sender, e) => {
                    Game.CurrentGameState = this;
                    Glfw.Disable(GlfwEnableCap.MouseCursor);
                },
                                                       (sender, e) => {
                    Game.CurrentGameState = new PlotScreen(Game,
                                                           "I have a confession to make now.\n\n" +
                                                           "The guys in suits, those weren't the bad guys. Or at least, you wouldn't have thought they were the bad guys.\n" +
                                                           "You see, you just killed a whole lot of your own people. Yes, you did.\n\n" +
                                                           "You had the key of that first room you were in in your pocket, but you couldn't remember after some of my people drugged you.",
                                                           (sender1, e1) => {
                        Game.CurrentGameState = this;
                        Glfw.Disable(GlfwEnableCap.MouseCursor);
                    },
                                                           (sender1, e1) => {
                        Game.CurrentGameState = new PlotScreen(Game,
                                                               "I'm the bad guy. Bye bye.",
                                                               (sender2, e2) => {
                            Game.CurrentGameState = this;
                            Glfw.Disable(GlfwEnableCap.MouseCursor);
                        },
                                                               (sender2, e2) => {
                            Game.CurrentGameState = new DeathState(this, false);
                        });
                    });
                });
            }
        }
Exemplo n.º 6
0
        private void UpdateClient(float time)
        {
#if DEBUG
            if (!IsMultiplayer && !MainGameState.IsServer && Game.CurrentKS['Z'] && !Game.PreviousKS['Z'])
            {
                LoadLevel(CurrentLevel + 1);
            }
#endif

            if (IsMultiplayer && !MainGameState.IsServer)
            {
                lock (MultiplayerClient.PlayerMutex) {
                    OtherPlayers.ForEach(x => {
                        if (x.PositionCounter <= 0f)
                        {
                            x.PositionCounter = .1f;
                        }
                        x.PreviousPositionCounter += time;
                        x.InterpolationCounter    += time;
                        x.InterpolationCounter     = Math.Min(x.InterpolationCounter, x.PositionCounter);
                        x.Position = x.ActualPosition + (x.ActualPosition - x.PreviousPosition) * (x.InterpolationCounter / x.PositionCounter);
                        //x.Position = x.ActualPosition;
                    });
                }
            }

            if (WritingChat)
            {
                foreach (KeyValuePair <char, Buffer2D <uint> > kvp in TextureTools.Font)
                {
                    char ch = kvp.Key;
                    try {
                        if (Game.CurrentKS [ch] && !Game.PreviousKS [ch])
                        {
                            onScreen.Add(ch);
                        }
                    } catch (Exception) {
                        // TODO: add period support
                    }
                }

                if (Game.CurrentKS[Key.Enter] && !Game.PreviousKS[Key.Enter])
                {
                    if (IsMultiplayer)
                    {
                        Client.SendChatMessage(new string(onScreen.ToArray()));
                    }
                    onScreen.Clear();
                    WritingChat = false;
                }

                if (Game.CurrentKS[Key.Backspace] && !Game.PreviousKS[Key.Backspace] && onScreen.Count > 0)
                {
                    onScreen.RemoveAt(onScreen.Count - 1);
                }

                if (Game.CurrentKS[Key.Space] && !Game.PreviousKS[Key.Space])
                {
                    onScreen.Add(' ');
                }
            }

            if (Game.CurrentKS['T'] && !Game.PreviousKS['T'])
            {
                WritingChat = true;
            }

            if (Game.CurrentKS[Key.Escape] && !Game.PreviousKS[Key.Escape])
            {
                Game.CurrentGameState = new AreYouSure(this);
            }

            if (changeToRequest)
            {
                Game.CurrentGameState = new ServerRequestState(Game);
                return;
            }

            if (!IsMultiplayer && CurrentLevel == -1)
            {
                Game.CurrentGameState = new PlotScreen(Game,
                                                       "Hello agent, it's nice to see you awake again, or well, the nearest equivalent to seeing.\n" +
                                                       "Wait, you probably don't even remember who I am, do you? Well, I'm not going to bother explaining the situation, we're already running low on time.\n" +
                                                       "What's important now is that you get out of this room. Blow open the doors with the grenade you have.\n" +
                                                       "How did you get a grenade? You don't even want to know...\n" +
                                                       "I'll contact you again once you're out of this room. Hurry!",
                                                       (sender, e) => {
                    Game.CurrentGameState = this;
                    Glfw.Disable(GlfwEnableCap.MouseCursor);
                },
                                                       (sender, e) => {
                    Game.CurrentGameState = this;
                    Glfw.Disable(GlfwEnableCap.MouseCursor);
                });
                CurrentLevel = 1;
            }

            if (!IsMultiplayer && CurrentLevel == -2)
            {
                CurrentLevel = 2;
            }

            if (!IsMultiplayer && CurrentLevel == -3)
            {
                Game.CurrentGameState = new PlotScreen(Game,
                                                       "Good, we've almost gathered enough energy to warp you to me. A couple of more blue spheres are required though. Keep going like this, you're doing very well!",
                                                       (sender, e) => {
                    Game.CurrentGameState = this;
                    Glfw.Disable(GlfwEnableCap.MouseCursor);
                },
                                                       (sender, e) => {
                    Game.CurrentGameState = this;
                    Glfw.Disable(GlfwEnableCap.MouseCursor);
                });
                CurrentLevel = 3;
            }

            if (!IsMultiplayer && CurrentLevel == -4)
            {
                Game.CurrentGameState = new PlotScreen(Game,
                                                       "Good, we've almost gathered enough energy to warp you to me. A couple of more blue spheres are required though. Keep going like this, you're doing very well!",
                                                       (sender, e) => {
                    Game.CurrentGameState = this;
                    Glfw.Disable(GlfwEnableCap.MouseCursor);
                },
                                                       (sender, e) => {
                    Game.CurrentGameState = this;
                    Glfw.Disable(GlfwEnableCap.MouseCursor);
                });
            }

            if (!IsMultiplayer && Projectiles.Count(proj => proj is CheckPoint) == 0)
            {
                LoadLevel(CurrentLevel + 1);
            }

            if (Flash >= 0f)
            {
                Flash -= time;
            }
            if (Flash < 0)
            {
                Flash = 0f;
            }

            CurrentPlayer.Update(time);

            lock (MultiplayerClient.WorldMutex) {
                foreach (Block b in Blocks)
                {
                    Door d = b as Door;
                    if (d != null)
                    {
                        d.Update(time);
                    }
                }
            }

            for (int i = 0; i < Projectiles.Count; ++i)
            {
                Projectiles[i].Update(this, time);
            }
            Projectiles = Projectiles.Where(p => !p.ShouldBeRemoved).ToList();

            if (!IsMultiplayer)
            {
                int  playerXInt  = (int)CurrentPlayer.X;
                int  playerZInt  = (int)CurrentPlayer.Z;
                bool isOnSpecial = false;
                foreach (Vector2i special in SpecialLocations)
                {
                    if (special.X == playerXInt && special.Y == playerZInt)
                    {
                        isOnSpecial = true;
                        if (!playerPrevOnSpecial)
                        {
                            PlayerStepOnSpecialLoc(playerXInt, playerZInt);
                        }
                        break;
                    }
                }
                playerPrevOnSpecial = isOnSpecial;

                foreach (AmmoCrate crate in Crates)
                {
                    crate.Update(this, time);
                }

                foreach (HealthPack hp in HealthPacks)
                {
                    hp.Update(this, time);
                }
            }

            for (int i = 0; i < DroppedWeapons.Count; ++i)
            {
                DroppedWeapons [i].Update(this, time);
                if (DroppedWeapons[i].ShouldBeRemoved)
                {
                    DroppedWeapons.RemoveAt(i--);
                }
            }

            for (int i = 0; i < Enemies.Count; ++i)
            {
                Enemies [i].Update(this, time);
                if (Enemies[i].ShouldBeRemoved)
                {
                    Enemies.RemoveAt(i--);
                }
            }
        }