Esempio n. 1
0
        public void Update(float msElapsed)
        {
            if (RestartInterval.Left > 1 || !RestartInterval.IsRunning)
            {
                foreach (KeyValuePair <int, Player> entry in PlayerIndex.ToArray())
                {
                    Player player = entry.Value;
                    player.Update(msElapsed, WorldMap, RedTent.Position, BlueTent.Position);
                    if (player.Y >= WorldMap.Height * Universal.TILE_SIZE - Universal.TILE_SIZE * 3)
                    {
                        network.SendKilledPlayer(-1, entry.Key, player);
                        player.DeathAction(false);
                        network.SendServerMove(entry.Key, player);
                        player.RespondMove = false;
                        network.CheckWinCondition();
                    }
                }
                foreach (KeyValuePair <int, Mob> entry in MobIndex.ToArray())
                {
                    if (entry.Value.Dead)
                    {
                        foreach (ItemDrop drop in entry.Value.Drops)
                        {
                            int id = 0;
                            foreach (KeyValuePair <int, ItemDrop> dropEntry in DropIndex.ToArray())
                            {
                                if (dropEntry.Key == id)
                                {
                                    id++;
                                }
                            }
                            DropIndex.TryAdd(id, drop);
                        }
                        network.SendRemoveMob(entry.Key, entry.Value.Drops);
                        Universal.TryDictRemove(MobIndex, entry.Key);
                    }
                    else
                    {
                        entry.Value.Update(msElapsed, WorldMap);
                    }
                }
                foreach (KeyValuePair <int, ItemDrop> entry in DropIndex.ToArray())
                {
                    entry.Value.Update(msElapsed, WorldMap);
                }
                foreach (KeyValuePair <int, FallingBlock> entry in FallingBlockIndex.ToArray())
                {
                    FallingBlock fallingBlock = entry.Value;
                    fallingBlock.Update(msElapsed, WorldMap);
                    if (Math.Abs(fallingBlock.DY) > 70)
                    {
                        foreach (KeyValuePair <int, Mob> mobEntry in MobIndex.ToArray())
                        {
                            Mob mob = mobEntry.Value;
                            if (fallingBlock.CollideBox.Intersects(mob.CollideBox))
                            {
                                mob.Damage(2);
                                network.SendHitMob(mobEntry.Key, 2);
                            }
                        }
                        foreach (KeyValuePair <int, Player> playerEntry in PlayerIndex.ToArray())
                        {
                            Player targetPlayer = playerEntry.Value;
                            if (fallingBlock.CollideBox.Intersects(targetPlayer.CollideBox))
                            {
                                targetPlayer.Damage(2);
                                network.SendHitPlayer(playerEntry.Key, 2, targetPlayer.DX, targetPlayer.DY);
                                if (targetPlayer.HP <= 0)
                                {
                                    Player killer;
                                    if (fallingBlock.PlayerID != playerEntry.Key &&
                                        PlayerIndex.TryGetValue(fallingBlock.PlayerID, out killer) &&
                                        (targetPlayer.PlayerTeam.Name == "No Team" || killer.PlayerTeam.Name != targetPlayer.PlayerTeam.Name))
                                    {
                                        killer.Kills++;
                                        network.SendKilledPlayer(fallingBlock.PlayerID, playerEntry.Key, targetPlayer);
                                    }
                                    else
                                    {
                                        network.SendKilledPlayer(-1, playerEntry.Key, targetPlayer);
                                    }
                                    targetPlayer.DeathAction(false);
                                    network.SendServerMove(playerEntry.Key, targetPlayer);
                                    targetPlayer.RespondMove = false;
                                    network.CheckWinCondition();
                                }
                            }
                        }
                    }
                    if (fallingBlock.CanDestroy)
                    {
                        network.SendRemoveFallingBlock(entry.Key);
                        Universal.TryDictRemove(FallingBlockIndex, entry.Key);
                    }
                }
                if (ServerMode == GameMode.TeamDeathmatch || ServerMode == GameMode.CaptureTheFlag)
                {
                    RedTent.Update(msElapsed, WorldMap);
                    BlueTent.Update(msElapsed, WorldMap);
                }
            }

            TimeRemaining.Update(msElapsed);
            RestartInterval.Update(msElapsed);
        }
Esempio n. 2
0
        public void Update(GameTime gameTime, KeyboardState lastKeyState, MouseState lastMouseState, bool chatting)
        {
            MouseState mouseState = Mouse.GetState();
            bool       playerTeam = MainPlayer.PlayerTeam.Name == "Red Team";

            if (online)
            {
                foreach (KeyValuePair <int, Player> entry in PlayerIndex.ToArray())
                {
                    if (!chatting)
                    {
                        entry.Value.Update(gameTime, lastKeyState, lastMouseState, DrawBlockOutline, entry.Value == MainPlayer);
                    }
                    else
                    {
                        entry.Value.Update(gameTime, lastKeyState, lastMouseState, DrawBlockOutline, false);
                    }
                }
            }
            foreach (KeyValuePair <int, Mob> entry in MobIndex.ToArray())
            {
                entry.Value.Update(gameTime, WorldMap);
            }
            foreach (KeyValuePair <int, ItemDrop> entry in DropIndex.ToArray())
            {
                entry.Value.Update(gameTime, WorldMap, MainPlayer.Items, new Vector2(MainPlayer.X + MainPlayer.BoundWidth, MainPlayer.Y + MainPlayer.BoundHeight), playerTeam);
            }
            foreach (KeyValuePair <int, FallingBlock> entry in FallingBlockIndex.ToArray())
            {
                FallingBlock fallingBlock = entry.Value;
                fallingBlock.Update(gameTime, WorldMap);
                if (fallingBlock.CanDestroy)
                {
                    Universal.TryDictRemove(FallingBlockIndex, entry.Key);
                }
            }
            if (ServerMode == GameMode.TeamDeathmatch || ServerMode == GameMode.CaptureTheFlag)
            {
                RedTent.Update(gameTime, WorldMap, MainPlayer.Items, MainPlayer.Position, playerTeam);
                BlueTent.Update(gameTime, WorldMap, MainPlayer.Items, MainPlayer.Position, playerTeam);
            }
            foreach (GameObject gameObject in objectList.ToArray())
            {
                gameObject.Update(gameTime);
                if (gameObject.Dead)
                {
                    objectList.Remove(gameObject);
                }
            }

            int  blockX       = (camera.CX + mouseState.X) / 16;
            int  blockY       = (camera.CY + mouseState.Y) / 16;
            Item selectedItem = MainPlayer.SelectedItem;

            if (MainPlayer.Motion != Vector2.Zero ||
                mouseState.LeftButton != lastMouseState.LeftButton ||
                mouseState.RightButton != lastMouseState.RightButton || blockX != lastBlockX || blockY != lastBlockY)
            {
                DrawBlockOutline = false;
                if (blockX >= 0 && blockX < WorldMap.Width &&
                    blockY >= 0 && blockY < WorldMap.Height &&
                    Vector2.Distance(new Vector2(MainPlayer.X + MainPlayer.BoundWidth, MainPlayer.Y + MainPlayer.BoundHeight / 2), new Vector2(camera.CX + mouseState.X, camera.CY + mouseState.Y)) <= Universal.TILE_SIZE * Universal.PLACE_DISTANCE)
                {
                    if (mouseState.RightButton == ButtonState.Pressed && WorldMap.Tiles[0, blockX, blockY].ID >= 0)
                    {
                        DrawBlockOutline = true;
                    }
                    else if (selectedItem.Type == ItemType.Block && mouseState.RightButton == ButtonState.Released && WorldMap.Tiles[0, blockX, blockY].ID == -1)
                    {
                        if (blockX >= 0 && blockX < WorldMap.Width)
                        {
                            if (blockY - 1 >= 0 && WorldMap.Tiles[0, blockX, blockY - 1].ID >= 0)
                            {
                                DrawBlockOutline = true;
                            }
                            if (blockY + 1 < WorldMap.Height && WorldMap.Tiles[0, blockX, blockY + 1].ID >= 0)
                            {
                                DrawBlockOutline = true;
                            }
                        }
                        if (blockY >= 0 && blockY < WorldMap.Height)
                        {
                            if (blockX - 1 >= 0 && WorldMap.Tiles[0, blockX - 1, blockY].ID >= 0)
                            {
                                DrawBlockOutline = true;
                            }
                            if (blockX + 1 < WorldMap.Width && WorldMap.Tiles[0, blockX + 1, blockY].ID >= 0)
                            {
                                DrawBlockOutline = true;
                            }
                        }
                        if (blockX == 0 || blockX == WorldMap.Width - 1 ||
                            blockY == 0 || blockY == WorldMap.Height - 1)
                        {
                            DrawBlockOutline = true;
                        }
                    }
                }
            }

            if (network != null &&
                (mouseState.RightButton != lastMouseState.RightButton || blockX != lastBlockX || blockY != lastBlockY))
            {
                network.SendHitBlock(DrawBlockOutline, mouseState.X, mouseState.Y);
            }

            lastBlockX = blockX;
            lastBlockY = blockY;

            if (!MainPlayer.RespawnInterval.IsRunning)
            {
                camera.Position = MainPlayer.Position;
            }
            if (camera.X < Universal.SCREEN_WIDTH / 2)
            {
                camera.X = Universal.SCREEN_WIDTH / 2;
            }
            else if (camera.X > WorldMap.Width * Universal.TILE_SIZE - Universal.SCREEN_WIDTH / 2)
            {
                camera.X = WorldMap.Width * Universal.TILE_SIZE - Universal.SCREEN_WIDTH / 2;
            }
            if (camera.Y < Universal.SCREEN_HEIGHT / 2)
            {
                camera.Y = Universal.SCREEN_HEIGHT / 2;
            }
            else if (camera.Y > WorldMap.Height * Universal.TILE_SIZE - Universal.SCREEN_HEIGHT / 2)
            {
                camera.Y = WorldMap.Height * Universal.TILE_SIZE - Universal.SCREEN_HEIGHT / 2;
            }

            WorldMap.CheckRender();
        }