public void receiveInformationFromGameServer() { string[] messages = localGameClient.readIncomingAsString().Split(GameServer.messageSeparator); foreach (string b in messages) { string[] data = b.Split(GameServer.dataSeparator); if (data[0] == ((int)GameServer.NetworkKeyword.mapInfo).ToString()) { //Map related message Game1.currentMap.interpretServerMessage(data); } if (data[0] == ((int)GameServer.NetworkKeyword.playerInfo).ToString()) { OtherPlayer.interpretPlayerServerMessage(data); } } }
public void mouseController(MouseState mouseState, GameTime gameTime, KeyboardState keyboardState) { //Optimize if (!playerGUI.mouseInput(mouseState, keyboardState)) { Point mouseNonRelativeLocation = new Point((int)(mouseState.X - relativeOffset.X), (int)(mouseState.Y - relativeOffset.Y)); int[] tilePosContainedIn = new int[] { (int)Math.Floor((float)mouseNonRelativeLocation.X / Game1.currentMap.tileSize), (int)Math.Floor((float)mouseNonRelativeLocation.Y / Game1.currentMap.tileSize) }; //Clamp to keep in bounds tilePosContainedIn[0] = (int)GameMath.clamp(tilePosContainedIn[0], 0, Game1.currentMap.tileMap.GetLength(0) - 1); tilePosContainedIn[1] = (int)GameMath.clamp(tilePosContainedIn[1], 0, Game1.currentMap.tileMap.GetLength(1) - 1); //LEFT if (mouseState.LeftButton == ButtonState.Pressed) { //Attempt break if (Game1.currentMap.tileMap[tilePosContainedIn[0], tilePosContainedIn[1]] != null && GameMath.distance(offsetRectangle(Game1.currentMap.tileMap[tilePosContainedIn[0], tilePosContainedIn[1]].rectangle).Center, rigidBody.collisionRectangle.Center) <= tileInteractionRadius) { Game1.currentMap.tileMap[tilePosContainedIn[0], tilePosContainedIn[1]].attemptBreakTile(gameTime, this); if (tileTryingToBreak != Game1.currentMap.tileMap[tilePosContainedIn[0], tilePosContainedIn[1]]) { if (tileTryingToBreak != null) { tileTryingToBreak.currentBreakTime = 0; tileTryingToBreak.currentBreakOverlay = null; //Update server Game1.networkManager.messagesToSendToServer += ((int)GameServer.NetworkKeyword.mapInfo).ToString() + GameServer.dataSeparator + ((int)GameServer.NetworkKeyword.tileInfo).ToString() + GameServer.dataSeparator + ((int)GameServer.NetworkKeyword.tileBreakOverlay).ToString() + GameServer.dataSeparator + tileTryingToBreak.mapPosition[0] + GameServer.dataSeparator + tileTryingToBreak.mapPosition[1] + GameServer.dataSeparator + (-1).ToString() + GameServer.messageSeparator; } tileTryingToBreak = Game1.currentMap.tileMap[tilePosContainedIn[0], tilePosContainedIn[1]]; } } else { if (tileTryingToBreak != null) { tileTryingToBreak.currentBreakTime = 0; tileTryingToBreak.currentBreakOverlay = null; //Update server Game1.networkManager.messagesToSendToServer += ((int)GameServer.NetworkKeyword.mapInfo).ToString() + GameServer.dataSeparator + ((int)GameServer.NetworkKeyword.tileInfo).ToString() + GameServer.dataSeparator + ((int)GameServer.NetworkKeyword.tileBreakOverlay).ToString() + GameServer.dataSeparator + tileTryingToBreak.mapPosition[0] + GameServer.dataSeparator + tileTryingToBreak.mapPosition[1] + GameServer.dataSeparator + (-1).ToString() + GameServer.messageSeparator; tileTryingToBreak = null; } } } else { if (tileTryingToBreak != null) { tileTryingToBreak.currentBreakTime = 0; tileTryingToBreak.currentBreakOverlay = null; //Update server Game1.networkManager.messagesToSendToServer += ((int)GameServer.NetworkKeyword.mapInfo).ToString() + GameServer.dataSeparator + ((int)GameServer.NetworkKeyword.tileInfo).ToString() + GameServer.dataSeparator + ((int)GameServer.NetworkKeyword.tileBreakOverlay).ToString() + GameServer.dataSeparator + tileTryingToBreak.mapPosition[0] + GameServer.dataSeparator + tileTryingToBreak.mapPosition[1] + GameServer.dataSeparator + (-1).ToString() + GameServer.messageSeparator; tileTryingToBreak = null; } } //RIGHT if (mouseState.RightButton == ButtonState.Released && pastMouseState.RightButton == ButtonState.Pressed && !ducking) { if (Game1.currentMap.tileMap[tilePosContainedIn[0], tilePosContainedIn[1]] == null || (Game1.currentMap.tileMap[tilePosContainedIn[0], tilePosContainedIn[1]] != null && Game1.currentMap.tileMap[tilePosContainedIn[0], tilePosContainedIn[1]].overridable) && (playerGUI.playerInventory.selectedCell != null && playerGUI.playerInventory.selectedCell.isContainingTiles())) { Rectangle tileRectangle = new Rectangle((int)((tilePosContainedIn[0] * Game1.currentMap.tileSize) + Game1.mainPlayer.relativeOffset.X), (int)((tilePosContainedIn[1] * Game1.currentMap.tileSize) + Game1.mainPlayer.relativeOffset.Y), Game1.currentMap.tileSize, Game1.currentMap.tileSize); if (!tileRectangle.Intersects(rigidBody.collisionRectangle) && GameMath.distance(tileRectangle.Center, rigidBody.collisionRectangle.Center) <= tileInteractionRadius && !Game1.currentMap.isContainingEntities(new Rectangle(tilePosContainedIn[0] * Game1.currentMap.tileSize, tilePosContainedIn[1] * Game1.currentMap.tileSize, Game1.currentMap.tileSize, Game1.currentMap.tileSize)) && !OtherPlayer.intersectsOtherPlayers(tileRectangle)) { //Null tile has been right clicked placeTile(new[] { tilePosContainedIn[0], tilePosContainedIn[1] }); } } else if (playerGUI.playerInventory.selectedCell != null && !playerGUI.playerInventory.selectedCell.isContainingTiles()) { //Completes the item's right click action playerGUI.playerInventory.selectedCell.useItem(InventoryCell.useEventType.rightClick); } } } pastMouseState = mouseState; }