Esempio n. 1
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();
        }