public Dictionary <Point, Monster> getMonsters(Microsoft.Xna.Framework.Point renderOffset) { Dictionary <Point, Monster> monsters = new Dictionary <Point, Monster>(); foreach (var room in Rooms) { // Each room has a 60% chance of having monsters if (Dice.Roll("1D10") < 11) { // Generate between 1 and 4 monsters var numberOfMonsters = Dice.Roll("1D4"); for (int i = 0; i < numberOfMonsters; i++) { // Find a random walkable location in the room to place the monster Point?randomRoomLocation = GetRandomWalkableLocationInRoom(room); // It's possible that the room doesn't have space to place a monster // In that case skip creating the monster if (randomRoomLocation != null && !monsters.ContainsKey((Point)randomRoomLocation)) { // Temporarily hard code this monster to be created at level 1 Monster monster = new Kobold(1); monster.Position = (Point)randomRoomLocation; monster.RenderOffset = renderOffset; Game.SchedulingSystem.Add(monster); monsters.Add(monster.Position, monster); } } } } return(monsters); }
public Board CreateBoard(Microsoft.Xna.Framework.Point mapSize, Point centerPoint, System.Windows.Controls.ContextMenu menu) { lock (this) { Board newBoard = new Board(mapSize, centerPoint, this, menu, ApplicationSettings.theoreticalVisibleTypes, ApplicationSettings.theoreticalEditedTypes); boards.Add(newBoard); newBoard.CreateLayers(); return(newBoard); } }
public override void Update(GameTime gameTime) { if (Mouse.GetState().RightButton == ButtonState.Pressed) rightMouseButtonPressed = true; if (Mouse.GetState().RightButton == ButtonState.Released && rightMouseButtonPressed) { rightMouseButtonPressed = false; //if from and to selected, then do undoMove, else do undo select if (selectedElementFrom != null && selectedElementTo != null) { undoMove = true; } else { selectedElementFrom = null; } } if (isBusy) return; //uiConnector.GetBoard().CalculateMovableTiles(); isSelected = false; if (isGameEnded) { TimeSpan timeSpanCurrent = new TimeSpan(0, 0, 0, gameTime.ElapsedGameTime.Seconds); timeSpan.Subtract(timeSpanCurrent); } if (Mouse.GetState().LeftButton == ButtonState.Pressed) leftMouseButtonPressed = true; if (leftMouseButtonPressed && Mouse.GetState().LeftButton == ButtonState.Released) { isSelected = true; leftMouseButtonPressed = false; } Microsoft.Xna.Framework.Point pMouse = new Microsoft.Xna.Framework.Point(Mouse.GetState().X, Mouse.GetState().Y); Vector3 nearUnproject = game.ScreenManager.GraphicsDevice.Viewport.Unproject(new Vector3(pMouse.X, pMouse.Y, 0), game.Projection, game.View, Matrix.Identity); Vector3 farUnproject = game.ScreenManager.GraphicsDevice.Viewport.Unproject(new Vector3(pMouse.X, pMouse.Y, 1), game.Projection, game.View, Matrix.Identity); Vector3 direction = Vector3.Subtract(farUnproject, nearUnproject); direction.Normalize(); Ray ray = new Ray(nearUnproject, direction); BoardElement selected = null; float? smallestIntersect = float.MaxValue; List<BoardElement> intersectList = BoardElements.ToList(); if (PossiblePlaces != null) foreach (BoardElement b in PossiblePlaces) intersectList.Add(b); foreach (BoardElement boardElement in intersectList) { float? intersect = boardElement.Intersect(ray); if (intersect != null) { if (smallestIntersect > intersect) { if (uiConnector.CurrentPlayerNumPieces() < 6 && boardElement is Tile && selectedElementFrom == null) { } else if (boardElement.DefaultColor != Color.Red.ToVector3()) { selected = boardElement; smallestIntersect = intersect; } } } if (selectedElementFrom != boardElement && boardElement != selectedElementTo) { boardElement.IsSelected = false; boardElement.IsMouseOver = false; } } if (selected != null) { if (isSelected) { selected.IsSelected = true; if (selectedElementFrom == null) selectedElementFrom = selected; else if (selectedElementFrom == selected) selectedElementFrom = null; else selectedElementTo = selected; if (FromTileSelected) { if (uiConnector.IsMovable((int)selectedElementFrom.BoardX, (int)selectedElementFrom.BoardY)) { GenerateTargetTiles(); } else if (selectedElementFrom is Piece) { } else { //wrongMoveSound.PlaySound(); } } else { GenerateTargetTiles(false); } } else { selected.IsMouseOver = true; } } if (selectedElementFrom != null && selectedElementTo != null) { doMoveThread = new Thread(new ThreadStart(this.DoMove)); doMoveThread.Start(); } UpdateMinMax(); base.Update(gameTime); }
protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); if (SceneManager.ActiveScene != null) { // update the mouse position (this will update the Scene mouse too) this.RealMousePos = new Vector2(e.X, e.Y); if (SquidEditorForm.Instance.SceneEditorTool == SquidEditorSceneEditorTool.Select) { // if the user is dragging selected item(s) if (_isDraggingItem == true && _selectedItems.Count > 0) { Vector2 dragDistance = SceneMousePos - _dragItemStartPos; Vector2 diffDragDistance = Vector2.Zero; dragDistance.X = (float)Math.Round(dragDistance.X); dragDistance.Y = (float)Math.Round(dragDistance.Y); //Console.WriteLine("dragDistance: " + dragDistance + " start: " + _dragItemStartPos); if (dragDistance.LengthSquared() > 0) { if (shouldMakeCopy == true) { shouldMakeCopy = false; SquidEditorForm.Instance.CopySelectedItems(); List <SceneItem> _newItems = SquidEditorForm.Instance.PasteSelectedItems(); _selectedItems.Clear(); foreach (var item in _newItems) { _selectedItems.Add(item); } } foreach (SceneItem item in _selectedItems) { Vector2 newPos = item.Position + dragDistance; if (Preferences.ShowGrid == true && Preferences.SnapToGrid == true) { #region SnapToGrid Point gridSize = Preferences.GridSizes[Preferences.SelectedGrid - 1]; int snapZone = Preferences.GridAttractionZones[Preferences.SelectedGrid - 1]; int left = item.BoundingRect.Left + (int)dragDistance.X; int right = item.BoundingRect.Right + (int)dragDistance.X; int top = item.BoundingRect.Top + (int)dragDistance.Y; int bottom = item.BoundingRect.Bottom + (int)dragDistance.Y; Vector2 halfGridSize = new Vector2(gridSize.X / 2, gridSize.Y); Vector2 leftSnap = new Vector2( SquidMath.Floor(left / (float)gridSize.X), left % (float)gridSize.X); Vector2 rightSnap = new Vector2( SquidMath.Ceiling(right / (float)gridSize.X), ((float)gridSize.X - right % (float)gridSize.X) % (float)gridSize.X); if (leftSnap.X < 0) { leftSnap.Y = (gridSize.X + leftSnap.Y) % gridSize.X; } if (leftSnap.Y > halfGridSize.X) { leftSnap.X += 1; leftSnap.Y = leftSnap.Y - gridSize.X; } if (rightSnap.Y > halfGridSize.X) { rightSnap.X -= 1; rightSnap.Y = rightSnap.Y - gridSize.X; } Vector2 snapX = Vector2.Zero; if (Math.Abs(leftSnap.Y) <= Math.Abs(rightSnap.Y)) { snapX = leftSnap; } else { snapX = rightSnap; } //Console.WriteLine("L: " + leftSnap + " R: " + rightSnap + " "); if (Math.Abs(snapX.Y) <= (float)snapZone) { float diff = newPos.X - (float)left; float oldPos = newPos.X; newPos.X = snapX.X * gridSize.X + diff; if (snapX != leftSnap) { newPos.X -= right - left; } diffDragDistance.X = newPos.X - oldPos; } Vector2 topSnap = new Vector2( SquidMath.Floor(top / (float)gridSize.Y), top % (float)gridSize.Y); Vector2 bottomSnap = new Vector2( SquidMath.Ceiling(bottom / (float)gridSize.Y), ((float)gridSize.Y - bottom % (float)gridSize.Y) % (float)gridSize.Y); if (topSnap.X < 0) { topSnap.Y = (gridSize.Y + topSnap.Y) % gridSize.Y; } if (topSnap.Y > halfGridSize.X) { topSnap.X += 1; topSnap.Y = topSnap.Y - gridSize.Y; } if (bottomSnap.Y > halfGridSize.X) { bottomSnap.X -= 1; bottomSnap.Y = bottomSnap.Y - gridSize.Y; } Vector2 snapY = Vector2.Zero; if (Math.Abs(topSnap.Y) <= Math.Abs(bottomSnap.Y)) { snapY = topSnap; } else { snapY = bottomSnap; } //Console.WriteLine("T: " + topSnap + " B: " + bottomSnap + " "); if (Math.Abs(snapY.Y) <= (float)snapZone) { float diff = newPos.Y - (float)top; float oldPos = newPos.Y; newPos.Y = snapY.X * gridSize.Y + diff; if (snapY != topSnap) { newPos.Y -= bottom - top; } diffDragDistance.Y = newPos.Y - oldPos; } #endregion } item.Position = newPos; SquidEditorForm.Instance.SceneWasModified = true; } _refreshSceneItemProperties = true; } _dragItemStartPos = SceneMousePos; if (diffDragDistance.X != 0) { _dragItemStartPos.X += diffDragDistance.X; } if (diffDragDistance.Y != 0) { _dragItemStartPos.Y += diffDragDistance.Y; } } else { // check if the mouse is hovering an object // and highlight it _highlightedItem = null; foreach (SceneItem item in SceneManager.ActiveScene.SceneItems) { if (item is PostProcessAnimation) { continue; } Microsoft.Xna.Framework.Point mousePoint = new Microsoft.Xna.Framework.Point((int)SceneMousePos.X, (int)SceneMousePos.Y); if (SquidMath.IsPointInsideRectangle(mousePoint, item.BoundingRect)) { if (item.Visible) { _highlightedItem = item; } } } // check the selected items and give them priority over the others foreach (SceneItem item in _selectedItems) { Microsoft.Xna.Framework.Point mousePoint = new Microsoft.Xna.Framework.Point((int)SceneMousePos.X, (int)SceneMousePos.Y); if (SquidMath.IsPointInsideRectangle(mousePoint, item.BoundingRect)) { if (item.Visible) { _highlightedItem = item; } } } } } // Check for scene dragging with the mouse if (_isDraggingScene == true) { Camera cam = SceneManager.ActiveScene.ActiveCameras[0]; Vector2 dragDistance = -(RealMousePos - _dragSceneStartPos) / cam.Zoom; cam.Position += dragDistance; _refreshSceneItemProperties = true; _dragSceneStartPos = RealMousePos; } } }
protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); if (SceneManager.ActiveScene != null) { // update the mouse position (this will update the Scene mouse too) this.RealMousePos = new Vector2(e.X, e.Y); if (MilkshakeForm.Instance.SceneEditorTool == MilkshakeSceneEditorTool.Select) { // if the user is dragging selected item(s) if (_isDraggingItem == true && _selectedItems.Count > 0) { Vector2 dragDistance = SceneMousePos - _dragItemStartPos; Vector2 diffDragDistance = Vector2.Zero; dragDistance.X = (float)Math.Round(dragDistance.X); dragDistance.Y = (float)Math.Round(dragDistance.Y); //Console.WriteLine("dragDistance: " + dragDistance + " start: " + _dragItemStartPos); if (dragDistance.LengthSquared() > 0) { if (shouldMakeCopy == true) { shouldMakeCopy = false; MilkshakeForm.Instance.CopySelectedItems(); List<SceneItem> _newItems = MilkshakeForm.Instance.PasteSelectedItems(); _selectedItems.Clear(); foreach (var item in _newItems) { _selectedItems.Add(item); } } foreach (SceneItem item in _selectedItems) { Vector2 newPos = item.Position + dragDistance; if (Preferences.ShowGrid == true && Preferences.SnapToGrid == true) { #region SnapToGrid Point gridSize = Preferences.GridSizes[Preferences.SelectedGrid - 1]; int snapZone = Preferences.GridAttractionZones[Preferences.SelectedGrid - 1]; int left = item.BoundingRect.Left + (int)dragDistance.X; int right = item.BoundingRect.Right + (int)dragDistance.X; int top = item.BoundingRect.Top + (int)dragDistance.Y; int bottom = item.BoundingRect.Bottom + (int)dragDistance.Y; Vector2 halfGridSize = new Vector2(gridSize.X / 2, gridSize.Y); Vector2 leftSnap = new Vector2( IceMath.Floor(left / (float)gridSize.X), left % (float)gridSize.X); Vector2 rightSnap = new Vector2( IceMath.Ceiling(right / (float)gridSize.X), ((float)gridSize.X - right % (float)gridSize.X) % (float)gridSize.X); if (leftSnap.X < 0) { leftSnap.Y = (gridSize.X + leftSnap.Y) % gridSize.X; } if (leftSnap.Y > halfGridSize.X) { leftSnap.X += 1; leftSnap.Y = leftSnap.Y - gridSize.X; } if (rightSnap.Y > halfGridSize.X) { rightSnap.X -= 1; rightSnap.Y = rightSnap.Y - gridSize.X; } Vector2 snapX = Vector2.Zero; if (Math.Abs(leftSnap.Y) <= Math.Abs(rightSnap.Y)) { snapX = leftSnap; } else { snapX = rightSnap; } //Console.WriteLine("L: " + leftSnap + " R: " + rightSnap + " "); if (Math.Abs(snapX.Y) <= (float)snapZone) { float diff = newPos.X - (float)left; float oldPos = newPos.X; newPos.X = snapX.X * gridSize.X + diff; if (snapX != leftSnap) { newPos.X -= right - left; } diffDragDistance.X = newPos.X - oldPos; } Vector2 topSnap = new Vector2( IceMath.Floor(top / (float)gridSize.Y), top % (float)gridSize.Y); Vector2 bottomSnap = new Vector2( IceMath.Ceiling(bottom / (float)gridSize.Y), ((float)gridSize.Y - bottom % (float)gridSize.Y) % (float)gridSize.Y); if (topSnap.X < 0) { topSnap.Y = (gridSize.Y + topSnap.Y) % gridSize.Y; } if (topSnap.Y > halfGridSize.X) { topSnap.X += 1; topSnap.Y = topSnap.Y - gridSize.Y; } if (bottomSnap.Y > halfGridSize.X) { bottomSnap.X -= 1; bottomSnap.Y = bottomSnap.Y - gridSize.Y; } Vector2 snapY = Vector2.Zero; if (Math.Abs(topSnap.Y) <= Math.Abs(bottomSnap.Y)) { snapY = topSnap; } else { snapY = bottomSnap; } //Console.WriteLine("T: " + topSnap + " B: " + bottomSnap + " "); if (Math.Abs(snapY.Y) <= (float)snapZone) { float diff = newPos.Y - (float)top; float oldPos = newPos.Y; newPos.Y = snapY.X * gridSize.Y + diff; if (snapY != topSnap) { newPos.Y -= bottom - top; } diffDragDistance.Y = newPos.Y - oldPos; } #endregion } item.Position = newPos; MilkshakeForm.Instance.SceneWasModified = true; } _refreshSceneItemProperties = true; } _dragItemStartPos = SceneMousePos; if (diffDragDistance.X != 0) { _dragItemStartPos.X += diffDragDistance.X; } if (diffDragDistance.Y != 0) { _dragItemStartPos.Y += diffDragDistance.Y; } } else { // check if the mouse is hovering an object // and highlight it _highlightedItem = null; foreach (SceneItem item in SceneManager.ActiveScene.SceneItems) { if (item is PostProcessAnimation) continue; Microsoft.Xna.Framework.Point mousePoint = new Microsoft.Xna.Framework.Point((int)SceneMousePos.X, (int)SceneMousePos.Y); if (IceMath.IsPointInsideRectangle(mousePoint, item.BoundingRect)) { if (item.Visible) _highlightedItem = item; } } // check the selected items and give them priority over the others foreach (SceneItem item in _selectedItems) { Microsoft.Xna.Framework.Point mousePoint = new Microsoft.Xna.Framework.Point((int)SceneMousePos.X, (int)SceneMousePos.Y); if (IceMath.IsPointInsideRectangle(mousePoint, item.BoundingRect)) { if (item.Visible) _highlightedItem = item; } } } } // Check for scene dragging with the mouse if (_isDraggingScene == true) { Camera cam = SceneManager.ActiveScene.ActiveCameras[0]; Vector2 dragDistance = -(RealMousePos - _dragSceneStartPos) / cam.Zoom; cam.Position += dragDistance; _refreshSceneItemProperties = true; _dragSceneStartPos = RealMousePos; } } }