/// <summary> /// Update(GameTime) /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">(GameTime) - Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { base.Update(gameTime); // Call built-in MonoGame Update method. if (!form.ContainsFocus) { return; } HandleViewportSizeChange(); // Check for window size change and handle it. MouseStateExtended mouseState = MouseExtended.GetState(); // Get the current state of the mouse Point mousePos = mouseState.Position; // Get current position of the mouse // Get the position of the mouse in the world relative to the absolute screen position. Vector2 worldPos = camera.ScreenToWorld(mousePos.ToVector2()); // Get the Tile and positional data associated with it (if any) at the mouse position in the world. TileLayer.TilePositionDetail tilePositionDetail = worldMap.GetTileAtPosition(worldPos, ActiveLayer); Tile tile = tilePositionDetail.Tile; // Handle User input #region Handle input // if right mouse button is clicked allow the camera to be dragged along with the mouse. if (mouseState.IsButtonDown(MouseButton.Right)) { // move camera with respect to mouse postion and zoom level. camera.Move(mouseState.DeltaPosition.ToVector2() / camera.Zoom); } else if (mouseState.DeltaScrollWheelValue != 0) // if mouse wheel is scrolled, change zoom level { // change the camera zoom level based on scroll wheel direciton // clamped between min and max zoom levels. camera.Zoom = MathHelper.Clamp( camera.Zoom - mouseState.DeltaScrollWheelValue * 0.001f, camera.MinimumZoom, camera.MaximumZoom ); } else if (mouseState.IsButtonDown(MouseButton.Left)) // if left mouse button clicked { if (tile != null && BrushTile != null) // check for tile at the current position and if brush tile selected. { // Set the Tile at the clicked position to the Brush Tile. tile.TilesetIndex = BrushTile.TilesetIndex; tile.TileIndex = BrushTile.TileIndex; } } #endregion // If a brush Tile is selected and is a valid position. Show brush Tile at map position. if (BrushTile != null && tilePositionDetail.IsValidPosition) { // Add the Brush Tile to the Map's selected Tile for display at mouse position. worldMap.AddSelectedTile( tilePositionDetail.Coordinates.X, tilePositionDetail.Coordinates.Y, BrushTile ); } }
public override void Paint(Map map, KeyboardStateExtended keyboardState, TileLayer.TilePositionDetail tilePosition, CollisionLayer.CellPositionDetail cellPosition) { if (keyboardState.IsControlDown()) { map.CollisionLayer.UpdateCell(false, cellPosition.Coordinates.X, cellPosition.Coordinates.Y); } else { map.CollisionLayer.UpdateCell(true, cellPosition.Coordinates.X, cellPosition.Coordinates.Y); } }
protected override void Update(GameTime gameTime) { base.Update(gameTime); if (!form.ContainsFocus) { return; } HandleViewportSizeChange(); MouseStateExtended mouseState = MouseExtended.GetState(); KeyboardStateExtended keyboardState = KeyboardExtended.GetState(); Point mousePosition = mouseState.Position; Vector2 worldPosition = camera.ScreenToWorld(mousePosition.ToVector2()); TileLayer.TilePositionDetail tilePositionDetail = myMap.GetTileAtPosition(worldPosition, ActiveLayer); CollisionLayer.CellPositionDetail cellPositionDetail = myMap.GetCellAtPosition(worldPosition); Tile tile = tilePositionDetail.Tile; if (mouseState.IsButtonDown(MouseButton.Right)) { camera.Move(mouseState.DeltaPosition.ToVector2() / camera.Zoom); } else if (mouseState.DeltaScrollWheelValue != 0) { camera.Zoom = MathHelper.Clamp(camera.Zoom - mouseState.DeltaScrollWheelValue * 0.001f, camera.MinimumZoom, camera.MaximumZoom); } if (ActivePaintingTool != null) { if (ActivePaintingTool.IsValidPosition(myMap, keyboardState, tilePositionDetail, cellPositionDetail)) { if (mouseState.IsButtonDown(MouseButton.Left)) { ActivePaintingTool.Paint(myMap, keyboardState, tilePositionDetail, cellPositionDetail); } else { ActivePaintingTool.Hover(myMap, keyboardState, tilePositionDetail, cellPositionDetail); } } } }
protected override void Update(GameTime gameTime) { base.Update(gameTime); if (!form.ContainsFocus) { return; } HandleViewportSizeChange(); MouseStateExtended mouseState = MouseExtended.GetState(); Point mousePosition = mouseState.Position; Vector2 worldPosition = camera.ScreenToWorld(mousePosition.ToVector2()); TileLayer.TilePositionDetail tilePositionDetail = myMap.GetTileAtPosition(worldPosition, ActiveLayer); Tile tile = tilePositionDetail.Tile; if (mouseState.IsButtonDown(MouseButton.Right)) { camera.Move(mouseState.DeltaPosition.ToVector2() / camera.Zoom); } else if (mouseState.DeltaScrollWheelValue != 0) { camera.Zoom = MathHelper.Clamp(camera.Zoom - mouseState.DeltaScrollWheelValue * 0.001f, camera.MinimumZoom, camera.MaximumZoom); } else if (mouseState.IsButtonDown(MouseButton.Left)) { if (tile != null && BrushTile != null) { tile.TilesetIndex = BrushTile.TilesetIndex; tile.TileIndex = BrushTile.TileIndex; } } if (BrushTile != null && tilePositionDetail.IsValidPosition) { myMap.AddImmediateTile(tilePositionDetail.Coordinates.X, tilePositionDetail.Coordinates.Y, BrushTile); } }
public override bool IsValidPosition(Map map, KeyboardStateExtended keyboardState, TileLayer.TilePositionDetail tilePosition, CollisionLayer.CellPositionDetail cellPosition) { return(cellPosition.IsValidPosition); }
public override void Hover(Map map, KeyboardStateExtended keyboardState, TileLayer.TilePositionDetail tilePosition, CollisionLayer.CellPositionDetail cellPosition) { }
public abstract void Paint(Map map, KeyboardStateExtended keyboardState, TileLayer.TilePositionDetail tilePosition, CollisionLayer.CellPositionDetail cellPosition);
public abstract bool IsValidPosition(Map map, KeyboardStateExtended keyboardState, TileLayer.TilePositionDetail tilePosition, CollisionLayer.CellPositionDetail cellPosition);
public override void Paint(Map map, KeyboardStateExtended keyboardState, TileLayer.TilePositionDetail tilePosition, CollisionLayer.CellPositionDetail cellPosition) { tilePosition.Tile.TilesetIndex = BrushTile.TilesetIndex; tilePosition.Tile.TileIndex = BrushTile.TileIndex; }
public override void Hover(Map map, KeyboardStateExtended keyboardState, TileLayer.TilePositionDetail tilePosition, CollisionLayer.CellPositionDetail cellPosition) { map.AddImmediateTile(tilePosition.Coordinates.X, tilePosition.Coordinates.Y, BrushTile); }