/// <summary> /// update the handler /// </summary> /// <param name="hoverPoint"></param> public void Handle(Microsoft.Xna.Framework.Point hoverPoint) { // left klick and not hovered -> deselect if (FenrirGame.Instance.Properties.Input.LeftClick && FenrirGame.Instance.Properties.Input.MouseRay.Intersects(this.selectedUnit.Boundingbox) == null) { this.scene.DisposeCurrentModeHandler(); } // selected and right click -> move/mine if (FenrirGame.Instance.Properties.Input.RightClick) { // block to mine if needed TileState targetBlockState = this.scene.GetBlockState(hoverPoint); if (targetBlockState == TileState.Solid) { this.selectedUnit.ExecuteTask(new Entities.Units.Tasks.TaskMine(hoverPoint)); } // movin else if (targetBlockState == TileState.Walkable || targetBlockState == TileState.Climbable) { this.selectedUnit.ExecuteTask(new Entities.Units.Tasks.TaskMove(hoverPoint)); } } }
void EntityDrawingOptionsForm_SizeChanged(object sender, Microsoft.Xna.Framework.Point oldSize, Microsoft.Xna.Framework.Point newSize) { leftPanel.Width = Width / 2 - panelMargin / 2; rightPanel.X = leftPanel.Width + panelMargin; rightPanel.Width = leftPanel.Width; }
public override void Draw(Texture2D texture, Point point) { XnaTexture2D xnaTexture = texture.GetTexture as XnaTexture2D; XnaPoint xnaPoint = new XnaPoint(point.X, point.Y); this.spriteBatch.Draw(xnaTexture, xnaPoint.ToVector2()); }
private void TilesetPictureBox_Click(object sender, EventArgs e) { if (tileset == null) { return; } MouseEventArgs mouseArgs = (MouseEventArgs)e; MonoGamePoint mousePoint = new MonoGamePoint(mouseArgs.X, mouseArgs.Y); List <MonoGameRectangle> frameRects = tileset.Frames; for (int i = 0; i < frameRects.Count; i++) { MonoGameRectangle scaledRect = frameRects[i].Scale(zoomLevels[currentZoomLevel]); if (scaledRect.Contains(mousePoint)) { selectedFrameIndex = i; TileSelect?.Invoke(tileset, selectedFrameIndex); RefreshFrames(); } } }
public override void Draw(Texture2D texture, Point point) { XnaTexture2D xnaTexture = texture.GetTexture as XnaTexture2D; XnaPoint xnaPoint = new XnaPoint(point.X, point.Y); this.spriteBatch.Draw(xnaTexture, xnaPoint.ToVector2()); }
public virtual void MoveTo(int x, int y, int width, int height) { Point p = GetParentPosition(); Position = new Point(x - p.X, y - p.Y); Size = new Size(width, height); }
private Point GetRandomEmpty(int roomID = -1) { Point p; int r = roomID; if (roomID == -1) { r = GameConstants.random.Next(Rooms.Count - 1); } Rectangle room = Rooms[r]; //System.Console.WriteLine( "room spawn: " + r.ToString() ); while (true) { int x = GameConstants.random.Next(room.X + 1, room.Right - 1); int y = GameConstants.random.Next(room.Y + 1, room.Bottom - 1); p = new Point(x, y); //foreach ( ActorBase m in ActorBase.actors ) //{ // if ( m.Position == p ) // break; //} break; } //System.Console.WriteLine( "spawn point:" + p.ToString() ); return(p); }
public static Point FromFramework(FrameworkPoint point) { return(new Point() { X = point.X, Y = point.Y }); }
private void init(string name, int width, int height) { for (int i = 0; i < layers.Length; ++i) { layers[i] = new SortedList <string, Tile>(width * height, new MapStringComparer()); } for (int a = 0; a < width; a++) { for (int b = 0; b < height; b++) { AddTile(a, b, LAYERS.Graphic, new GraphicTile(a, b)); AddTile(a, b, LAYERS.Special, new SpecialTile(a, b)); AddTile(a, b, LAYERS.Item, new ItemTile(ItemTileSpec.NONE, a, b)); } } w = width; h = height; PlayerSpawn = new Microsoft.Xna.Framework.Point(0, 0); mapname = name; fileName = ""; isLoaded = false; isSaved = false; this.Warp = -1; this.Type = MapType.TrenchCave; this.PlayerSpawn = new Microsoft.Xna.Framework.Point(0, 0); }
private void Move(Selectable selectable, Microsoft.Xna.Framework.Point target) { if (World.Dimensions[RenderingPipe.Dimension][target.X, target.Y].IsWalkable) { switch (selectable) { case Living living: Microsoft.Xna.Framework.Point start = selectable.MapLocation; if (start != target) { List <PathLink> pth; //Handle reroute if (living.QueuedMovement.Count > 0) { //Get a path to the nearest/next tile so that path finding and the screen location sync up. PathLink previous = living.QueuedMovement.Peek(); living.QueuedMovement.Clear(); living.QueuedMovement.Enqueue(previous); pth = MainPathFinder.GetRoute(RenderingPipe.Dimension, previous.Destination, target); } //No reroute else { pth = MainPathFinder.GetRoute(RenderingPipe.Dimension, living.MapLocation, target); } Extensions.EnqueueCollection(living.QueuedMovement, pth); ClientSendRecieve.Send <RouteCreatedMessage>(new RouteCreatedMessage(pth, living.ID, living.Dimension)); } break; } } }
public static Microsoft.Xna.Framework.Point FromString(this Microsoft.Xna.Framework.Point x, string Value) { Value = Value.Replace("{X=", "").Replace("Y=", "").Replace("}", ""); var _DLS = Value.Split(",".ToCharArray()); return(new Microsoft.Xna.Framework.Point(Convert.ToInt32(_DLS[0]), Convert.ToInt32(_DLS[1]))); }
public MapTransitionText(Action OnContinue, Action OnMenu, Action OnQuitDesktop, Dictionary <string, SoundEffect> sounds) { this.sounds = sounds; this.OnContinue = OnContinue; this.OnMenu = OnMenu; GetStandardSprite(true); SetAnchor(AnchorX.Middle, AnchorY.Middle); childAllignX = AnchorX.Middle; overwriteChildLayout = false; SetFixedSize(500, 500); Padding = new Microsoft.Xna.Framework.Point(10, 10); Margin = 10; textField = new Text(Texts.Get("level0Intro")); textField.wrapText = true; textField.SetFixedSize(400, 300); buttonMenu = new Button("backMenu"); buttonMenu.SetFixedWidth(200); buttonMenu.OnMouseClick = OnMenu + StopSound; Button buttonDesktop = new Button("quit"); buttonDesktop.SetFixedWidth(200); buttonDesktop.OnMouseClick = OnQuitDesktop + StopSound; buttonContinue = new Button("continue"); buttonContinue.SetFixedWidth(200); buttonContinue.OnMouseClick = OnContinue + StopSound; AddChild(textField, buttonContinue, buttonMenu, buttonDesktop); }
public bool Act(Monster monster, CombatSystem combatSystem) { Microsoft.Xna.Framework.Point pLoc = GameWorld.DungeonScreen.MapConsole.Player.Position; FieldOfView monsterFov = new FieldOfView(GameWorld.DungeonScreen.MapConsole.detailedMap); // If the monster has not been alerted, compute a field-of-view // Use the monster's Awareness value for the distance in the FoV check // If the player is in the monster's FoV then alert it // Add a message to the MessageLog regarding this alerted status if (!monster.TurnsAlerted.HasValue) { monsterFov.ComputeFov(monster.Position.X, monster.Position.Y, monster.Awareness, true); if (monsterFov.IsInFov(pLoc.X, pLoc.Y)) { GameWorld.DungeonScreen.MessageConsole.PrintMessage($"{monster.Name} is eager to fight {GameWorld.DungeonScreen.MapConsole.Player.Name}"); monster.TurnsAlerted = 1; } } if (monster.TurnsAlerted.HasValue) { PathFinder pathFinder = new PathFinder(GameWorld.DungeonScreen.MapConsole.detailedMap); Path path = null; try { path = pathFinder.ShortestPath( GameWorld.DungeonScreen.MapConsole.detailedMap.GetCell(monster.Position.X, monster.Position.Y), GameWorld.DungeonScreen.MapConsole.detailedMap.GetCell(pLoc.X, pLoc.Y)); } catch (PathNotFoundException) { // The monster can see the player, but cannot find a path to him // This could be due to other monsters blocking the way // Add a message to the message log that the monster is waiting GameWorld.DungeonScreen.MessageConsole.PrintMessage($"{monster.Name} waits for a turn"); } // In the case that there was a path, tell the CommandSystem to move the monster if (path != null) { try { GameWorld.DungeonScreen.MapConsole.MoveMonster(monster, path.StepForward()); } catch (NoMoreStepsException) { GameWorld.DungeonScreen.MessageConsole.PrintMessage($"{monster.Name} growls in frustration"); } } monster.TurnsAlerted++; if (monster.TurnsAlerted > AlertStatusLength) { monster.TurnsAlerted = null; } } return(true); }
internal MemoryStream caijianneicunliu(Microsoft.Xna.Framework.Point point, int i, int j, GraphicsDevice device) { int w = bm.Width / point.X; int h = bm.Height / point.Y; return(this.huoquneicunliu(i * w, j * h, w, h, device)); }
internal Texture2D caijiandituxiaokuai(Microsoft.Xna.Framework.Point point, int i, int j, GraphicsDevice device) { int w = bm.Width / point.X; int h = bm.Height / point.Y; return(huoqupingmutuxing(i * w, j * h, w, h, device)); }
public void Resize(int width, int height) { var tmp = new Point[width, height]; var frontTmp = new Point[width, height]; var passTmp = new int[width, height]; for (int i = 0; i < tmp.GetLength(0); i++) { for (int j = 0; j < tmp.GetLength(1); j++) { if (i < _backField.GetLength(0) && j < _backField.GetLength(1)) { tmp[i, tmp.GetLength(1) - j - 1] = _backField[i, _backField.GetLength(1) - j - 1]; frontTmp[i, tmp.GetLength(1) - j - 1] = _frontField[i, _backField.GetLength(1) - j - 1]; passTmp[i, tmp.GetLength(1) - j - 1] = _passField[i, _backField.GetLength(1) - j - 1]; } else { tmp[i, tmp.GetLength(1) - j - 1] = new Point(-1, -1); frontTmp[i, tmp.GetLength(1) - j - 1] = new Point(-1, -1); passTmp[i, tmp.GetLength(1) - j - 1] = 0; } } } _backField = tmp; _frontField = frontTmp; _passField = passTmp; _canvas.Width = width * H; _canvas.Height = height * H; }
public static void Load_pet_Info() { if (Game1.player.hasPet() == false) { return; } // DataLoader_Settings(); //loads the data to the variables upon loading the game. string myname = StardewValley.Game1.player.name; string mylocation = Path.Combine(Save_Anywhere_V2.Mod_Core.animal_path, "Pet_Save_Info_"); string mylocation2 = mylocation + myname; string mylocation3 = mylocation2 + ".txt"; if (!File.Exists(mylocation3)) //if not data.json exists, initialize the data variables to the ModConfig data. I.E. starting out. { } else { string[] readtext = File.ReadAllLines(mylocation3); pet_map_name = Convert.ToString(readtext[3]); pet_tile_x = Convert.ToInt32(readtext[5]); pet_tile_y = Convert.ToInt32(readtext[7]); get_pet(); pet_point = new Microsoft.Xna.Framework.Point(); pet_point.X = pet_tile_x; pet_point.Y = pet_tile_y; Game1.warpCharacter((StardewValley.NPC)my_pet, pet_map_name, pet_point, false, true); } }
public PigGuardianFragmentBase(byte PigID) { this.PigID = PigID; Size = GuardianSize.Medium; Age = 15; CompanionSlotWeight = 0.6f; SetBirthday(SEASON_AUTUMN, 14); CompanionContributorName = "Smokey"; //Same animations and settings for all! StandingFrame = 0; WalkingFrames = new int[] { 1, 2, 3, 4, 5, 6, 7, 8 }; JumpFrame = 9; ItemUseFrames = new int[] { 10, 11, 12, 13 }; SittingFrame = 14; ChairSittingFrame = 14; DrawLeftArmInFrontOfHead.AddRange(new int[] { 9, 10, 11, 15 }); ThroneSittingFrame = 16; BedSleepingFrame = 18; DownedFrame = 15; ReviveFrame = 17; BackwardStanding = 27; BackwardRevive = 28; SittingPoint2x = new Microsoft.Xna.Framework.Point(15, 24); SpecificBodyFrontFramePositions = true; BodyFrontFrameSwap.Add(14, 0); BodyFrontFrameSwap.Add(16, 1); BodyFrontFrameSwap.Add(22, 2); BodyFrontFrameSwap.Add(23, 3); //Left Arm LeftHandPoints.AddFramePoint2x(10, 10, 4); LeftHandPoints.AddFramePoint2x(11, 22, 11); LeftHandPoints.AddFramePoint2x(12, 24, 19); LeftHandPoints.AddFramePoint2x(13, 20, 24); LeftHandPoints.AddFramePoint2x(17, 24, 28); //Right Arm RightHandPoints.AddFramePoint2x(10, 16, 4); RightHandPoints.AddFramePoint2x(11, 26, 11); RightHandPoints.AddFramePoint2x(12, 28, 19); RightHandPoints.AddFramePoint2x(13, 24, 24); RightHandPoints.AddFramePoint2x(17, 26, 28); //Headgear HeadVanityPosition.DefaultCoordinate2x = new Microsoft.Xna.Framework.Point(16, 11); HeadVanityPosition.AddFramePoint2x(14, 16, 9); HeadVanityPosition.AddFramePoint2x(17, 23, 18); HeadVanityPosition.AddFramePoint2x(22, 16, 9); HeadVanityPosition.AddFramePoint2x(25, 23, 18); HeadVanityPosition.AddFramePoint2x(23, -1000, -1000); HeadVanityPosition.AddFramePoint2x(24, -1000, -1000); HeadVanityPosition.AddFramePoint2x(26, -1000, -1000); }
private void pb_drawSurface_MouseMove(object sender, MouseEventArgs e) { if (selectedControl != null) { if (resizingControl_TopLeft) { if (selectedControl is ArwicEngine.Forms.Form) { return; } int x = selectedControl.AbsoluteBounds.X + (GetMousePos().ToXNAPoint().X - lastMousePos.X); int y = selectedControl.AbsoluteBounds.Y + (GetMousePos().ToXNAPoint().Y - lastMousePos.Y); int w = selectedControl.AbsoluteBounds.Width - (GetMousePos().ToXNAPoint().X - lastMousePos.X); int h = selectedControl.AbsoluteBounds.Height - (GetMousePos().ToXNAPoint().Y - lastMousePos.Y); selectedControl.AbsoluteBounds = new Microsoft.Xna.Framework.Rectangle(x, y, w, h); } else if (resizingControl_TopRight) { if (selectedControl is ArwicEngine.Forms.Form) { return; } int x = selectedControl.AbsoluteBounds.X; int y = selectedControl.AbsoluteBounds.Y + (GetMousePos().ToXNAPoint().Y - lastMousePos.Y); int w = selectedControl.AbsoluteBounds.Width + (GetMousePos().ToXNAPoint().X - lastMousePos.X); int h = selectedControl.AbsoluteBounds.Height - (GetMousePos().ToXNAPoint().Y - lastMousePos.Y); selectedControl.AbsoluteBounds = new Microsoft.Xna.Framework.Rectangle(x, y, w, h); } else if (resizingControl_BottomLeft) { if (selectedControl is ArwicEngine.Forms.Form) { return; } int x = selectedControl.AbsoluteBounds.X + (GetMousePos().ToXNAPoint().X - lastMousePos.X); int y = selectedControl.AbsoluteBounds.Y; int w = selectedControl.AbsoluteBounds.Width - (GetMousePos().ToXNAPoint().X - lastMousePos.X); int h = selectedControl.AbsoluteBounds.Height + (GetMousePos().ToXNAPoint().Y - lastMousePos.Y); selectedControl.AbsoluteBounds = new Microsoft.Xna.Framework.Rectangle(x, y, w, h); } else if (resizingControl_BottomRight) { int x = selectedControl.AbsoluteBounds.X; int y = selectedControl.AbsoluteBounds.Y; int w = selectedControl.AbsoluteBounds.Width + (GetMousePos().ToXNAPoint().X - lastMousePos.X); int h = selectedControl.AbsoluteBounds.Height + (GetMousePos().ToXNAPoint().Y - lastMousePos.Y); selectedControl.AbsoluteBounds = new Microsoft.Xna.Framework.Rectangle(x, y, w, h); } else if (draggingControl) { if (selectedControl is ArwicEngine.Forms.Form) { return; } selectedControl.AbsoluteLocation = GetMousePos().ToXNAPoint() - dragOffset; } } lastMousePos = GetMousePos().ToXNAPoint(); }
public static Microsoft.Xna.Framework.Vector2 ToVector(this Microsoft.Xna.Framework.Point point) { return(new Microsoft.Xna.Framework.Vector2() { X = (float)point.X, Y = (float)point.Y }); }
/// <summary> /// Mouse move event /// </summary> /// <param name="selectedBoard"></param> /// <param name="oldPos"></param> /// <param name="newPos"></param> /// <param name="currPhysicalPos"></param> void MultiBoard_MouseMoved(Board selectedBoard, Microsoft.Xna.Framework.Point oldPos, Microsoft.Xna.Framework.Point newPos, Microsoft.Xna.Framework.Point currPhysicalPos) { textblock_CursorX.Text = currPhysicalPos.X.ToString(); textblock_CursorY.Text = currPhysicalPos.Y.ToString(); textblock_RCursorX.Text = newPos.X.ToString(); textblock_RCursorY.Text = newPos.Y.ToString(); }
public override void DrawString(SpriteFont font, string text, Point position, Color color) { XnaSpriteFont xnaFont = font.GetSpriteFont as XnaSpriteFont; XnaPoint xnaPoint = new XnaPoint(position.X, position.Y); XnaColor xnaColor = new XnaColor(color.R, color.G, color.B, color.A); this.spriteBatch.DrawString(xnaFont, text, xnaPoint.ToVector2(), xnaColor); }
public unsafe AnimationFrame(GraphicsDevice graphics, uint[] palette, BinaryFileReader reader) { int xCenter = reader.ReadShort(); int yCenter = reader.ReadShort(); int width = reader.ReadUShort(); int height = reader.ReadUShort(); // Fix for animations with no IO. if ((width == 0) || (height == 0)) { m_Texture = null; return; } uint[] data = new uint[width * height]; int header; int xBase = xCenter - 0x200; int yBase = (yCenter + height) - 0x200; fixed(uint *pData = data) { uint *dataRef = pData; int delta = width; int dataRead = 0; dataRef += xBase; dataRef += (yBase * delta); while ((header = reader.ReadInt()) != 0x7FFF7FFF) { header ^= DoubleXor; uint *cur = dataRef + ((((header >> 12) & 0x3FF) * delta) + ((header >> 22) & 0x3FF)); uint *end = cur + (header & 0xFFF); int filecounter = 0; byte[] filedata = reader.ReadBytes(header & 0xFFF); while (cur < end) { *cur++ = palette[filedata[filecounter++]]; } dataRead += header & 0xFFF; } Metrics.ReportDataRead(dataRead); } m_Center = new Microsoft.Xna.Framework.Point(xCenter, yCenter); m_Texture = new Texture2D(graphics, width, height); m_Texture.SetData <uint>(data); }
private void AddPlayer() { Point startPos = GetRandomEmpty(); actors.Add(GameConstants.player, startPos); SetTile(startPos, TileTypes.StairsUp); UpdatePlayerFieldOfView(); MapViewport.needsRedraw = true; }
public MapStatistics(string MapName, Microsoft.Xna.Framework.Point MapSize, Microsoft.Xna.Framework.Point TileSize) { InitializeComponent(); txtMapName.Text = MapName; txtMapWidth.Text = MapSize.X.ToString(); txtMapHeight.Text = MapSize.Y.ToString(); txtTileWidth.Text = TileSize.X.ToString(); txtTileHeight.Text = TileSize.Y.ToString(); }
public void MovePlayerBy(Point amount) { Point newPosition = Player.Position + amount; if (!new Rectangle(0, 0, Width, Height).Contains(newPosition) || !rogueMap.IsWalkable(newPosition.X, newPosition.Y)) { return; } if (Monsters.ContainsKey(newPosition)) { Game.CombatSystem.Attack(Player, Monsters[newPosition]); } else { Player.Position += amount; detailedMap.OpenDoor(Player, Player.Position.X, Player.Position.Y, ref mapData); // TODO: fix this possitioning horror TextSurface.RenderArea = new Rectangle(Player.Position.X - (TextSurface.RenderArea.Width / 2), Player.Position.Y - (TextSurface.RenderArea.Height / 2), TextSurface.RenderArea.Width, TextSurface.RenderArea.Height); // If he view area moved, we'll keep our entity in sync with it. Player.RenderOffset = Position - TextSurface.RenderArea.Location; // Update FoV foreach (var cell in previousFOV) { mapData[cell.X, cell.Y].RemoveCellFromView(this[cell.X, cell.Y]); } previousFOV = rogueFOV.ComputeFov(Player.Position.X, Player.Position.Y, 10, true); foreach (var cell in previousFOV) { rogueMap.SetCellProperties(cell.X, cell.Y, cell.IsTransparent, cell.IsWalkable, true); mapData[cell.X, cell.Y].RenderToCell(this[cell.X, cell.Y], true, rogueMap.GetCell(cell.X, cell.Y).IsExplored); } } GameWorld.DungeonScreen.StatsConsole.Clear(); GameWorld.DungeonScreen.StatsConsole.DrawPlayerStats(Player); int idx = 0; foreach (KeyValuePair <Point, Monster> monster in Monsters) { if (rogueFOV.IsInFov(monster.Value.Position.X, monster.Value.Position.Y)) { monster.Value.InFoV = true; GameWorld.DungeonScreen.StatsConsole.DrawMonsterStats(monster.Value, idx); idx++; } else { monster.Value.InFoV = false; } } }
//Check for Walkable public bool IsTileWalkable(Microsoft.Xna.Framework.Point location) { if (location.X < 0 || location.Y < 0 || location.X >= Width || location.Y >= Height) { return(false); } return(!_tiles[location.Y * Width + location.X].IsBlockingMove); }
public Chunk(Point bottomLeftCornerWorld, Point chunkWorldMapLocationPoint, ChunkData chunkContainer) { ChunkWorldMapLocationPoint = chunkWorldMapLocationPoint; boundingBox = new BoundingBox(new Vector3(bottomLeftCornerWorld.X, bottomLeftCornerWorld.Y, 0), new Vector3(bottomLeftCornerWorld.X + Constants.ChunkSize, bottomLeftCornerWorld.Y + Constants.ChunkSize, 0)); worldPositionBottomLeftCorner = bottomLeftCornerWorld; this.chunkContainer = chunkContainer; isActive = false; }
private void Button1_Click(object sender, EventArgs e) { TelX = (int)numericUpDown1.Value; TelY = (int)numericUpDown2.Value; AutoX = (int)numericUpDown3.Value; AutoY = (int)numericUpDown4.Value; TelDir = IA.OrientationToDirection((NXTEnvironment.Orientation)comboBox1.SelectedIndex); AutoDir = IA.OrientationToDirection((NXTEnvironment.Orientation)comboBox2.SelectedIndex); this.Close(); }
internal static GlyphFontViewModel Create(string filename, string fontName, Point glyphSize, BitmapSource bitmapSource) { return(new GlyphFontViewModel { Filename = filename, FontName = fontName, GlyphSize = glyphSize, BitmapSource = bitmapSource, GlyphCount = (bitmapSource.PixelWidth / glyphSize.X) * (bitmapSource.PixelHeight / glyphSize.Y), IsValid = true }); }
private void textBoxNativeResHeight_Validated(object sender, EventArgs e) { try { int newSize = Int32.Parse(((TextBox)sender).Text, CultureInfo.InvariantCulture); this.NativeResolution = new XnaPoint(this.NativeResolution.X, newSize); } catch { ((TextBox)sender).Text = this.NativeResolution.Y.ToString(CultureInfo.InvariantCulture); } }
public static DrawingPosRectangle GetCenteredDrawingPosRectangle( DrawingVector position, Rectangle rectangle ) { return(new DrawingPosRectangle( position.X - (int)(rectangle.Width / 2), position.Y - (int)(rectangle.Height / 2), rectangle.Width, rectangle.Height )); }
public static bool XNASelfCheck(ref string exceptionResult) { try { Microsoft.Xna.Framework.Point foo = new Microsoft.Xna.Framework.Point(); foo.X = 1337; //to shut VS up; return true; } catch (Exception e) { exceptionResult = e.Message; return false; } }
public Checkers(int m, int n, Point origin, Size square) { if ((m & 1) == (n & 1)) throw new Exception("Checker board must have even/odd M and N or vice versa."); WhiteColor = Color.White; BlackColor = Color.Black; OtherColor = Color.White; M = m; N = n; Square = square; Board = new Rect(origin.X, origin.Y, M * square.Width, N * square.Height); }
public void Calculate(System.Drawing.Size clientSizeInPixels, Size? boardSizeInTiles, Point scrollPositionInPixels) { const int tileWidth = TextAdventure.Xna.Constants.Tile.TileWidth; const int tileHeight = TextAdventure.Xna.Constants.Tile.TileHeight; ScrollPositionInPixels = scrollPositionInPixels; ClientSizeInTiles = new Size( (int)Math.Ceiling((clientSizeInPixels.Width + (scrollPositionInPixels.X % tileWidth)) / (double)tileWidth), (int)Math.Ceiling((clientSizeInPixels.Height + (scrollPositionInPixels.Y % tileHeight)) / (double)tileHeight)); ClientSizeInPixels = clientSizeInPixels; BoardSizeInTiles = new Size(boardSizeInTiles.IfNotNull(arg => (int?)arg.Width) ?? 0, boardSizeInTiles.IfNotNull(arg => (int?)arg.Height) ?? 0); BoardSizeInPixels = new System.Drawing.Size(BoardSizeInTiles.Width * tileWidth, BoardSizeInTiles.Height * tileHeight); TopLeftPoint = new Microsoft.Xna.Framework.Point(-(scrollPositionInPixels.X % tileWidth), -(scrollPositionInPixels.Y % tileHeight)); TopLeftCoordinate = new Coordinate(scrollPositionInPixels.X / tileWidth, scrollPositionInPixels.Y / tileHeight); BottomRightCoordinate = new Coordinate( Math.Min(BoardSizeInTiles.Width - 1, TopLeftCoordinate.X + ClientSizeInTiles.Width), Math.Min(BoardSizeInTiles.Height - 1, TopLeftCoordinate.Y + ClientSizeInTiles.Height)); var visibleCoordinateSize = new Coordinate(BottomRightCoordinate.X - TopLeftCoordinate.X + 1, BottomRightCoordinate.Y - TopLeftCoordinate.Y + 1); VisibleBoardSizeInPixels = new System.Drawing.Size( Math.Min(clientSizeInPixels.Width, TopLeftPoint.X + (visibleCoordinateSize.X * tileWidth)), Math.Min(clientSizeInPixels.Height, TopLeftPoint.Y + (visibleCoordinateSize.Y * tileHeight))); }
private void pnlMouseMove(object sender, MouseEventArgs e) { //Debug.WriteLine(e.X + "," + e.Y); if (e.X == lastx && e.Y == lasty) { //Debug.WriteLine("Ignoring same a last"); //return; } if ((8 +e.X == pCenterRelativeToWindow.X && 30 + e.Y == pCenterRelativeToWindow.Y)) { //Debug.WriteLine("Ignoring Center"); return; } dPos = new Microsoft.Xna.Framework.Point((-8+pCenterRelativeToWindow.X - e.X), (-30+pCenterRelativeToWindow.Y - e.Y)); lastx = e.X; lasty = e.Y; //Debug.WriteLine("=>"+dPos.X +", "+dPos.Y); game.ProcessMouseMove(dPos, e, XnaPanelMain.Bounds); try { pCenter = new System.Drawing.Point(this.Left + (this.Width / 2), this.Top + (this.Height / 2)); pCenterRelativeToWindow = new System.Drawing.Point((this.Width / 2), (this.Height / 2)); } catch (Exception E) { } Cursor.Position = pCenter; }
public static Point FromFramework(FrameworkPoint point) { return new Point() { X = point.X, Y = point.Y }; }
public static Point Plus(this Point location, Point size) { return new Point(location.X + size.X, location.Y + size.Y); }
public static Point Minus(this Point location, Point size) { return new Point(location.X - size.X, location.Y - size.Y); }
// Locking the mouse to this control is actually locking the parent console to the engine, and then // letting the controls console know that this control wants exclusive focus until mouse is unclicked. public override bool ProcessMouse(Input.MouseInfo info) { if (IsEnabled) { base.ProcessMouse(info); if (info.ConsoleLocation.X >= this.Position.X && info.ConsoleLocation.X < this.Position.X + this.Width && info.ConsoleLocation.Y >= this.Position.Y && info.ConsoleLocation.Y < this.Position.Y + this.Height) { var mouseControlPosition = new Microsoft.Xna.Framework.Point(info.ConsoleLocation.X - this.Position.X, info.ConsoleLocation.Y - this.Position.Y); // This becomes the active mouse subject when the bar is being dragged. if (Parent.CapturedControl != this) { if (info.LeftClicked) { if (_barOrientation == System.Windows.Controls.Orientation.Horizontal) { if (mouseControlPosition.X == 0) Value -= Step; if (mouseControlPosition.X == this.Width - 1) Value += Step; } else { if (mouseControlPosition.Y == 0) Value -= Step; if (mouseControlPosition.Y == this.Height - 1) Value += Step; } Parent.FocusedControl = this; } // Need to set a flag signalling that we've locked in a drag. // When the mouse button is let go, clear the flag. if (info.LeftButtonDown) { if (_barOrientation == System.Windows.Controls.Orientation.Horizontal) { if (mouseControlPosition.Y == 0) if (mouseControlPosition.X == _currentSliderPosition + 1) { Parent.CaptureControl(this); } } else { if (mouseControlPosition.X == 0) if (mouseControlPosition.Y == _currentSliderPosition + 1) { Parent.CaptureControl(this); } } Parent.FocusedControl = this; } } else if (Parent.CapturedControl == this) { if (info.LeftButtonDown) { if (_barOrientation == System.Windows.Controls.Orientation.Horizontal) { if (mouseControlPosition.Y == 0) { if (mouseControlPosition.X == _currentSliderPosition + 1) Value -= Step; } if (mouseControlPosition.Y == 0 && mouseControlPosition.X >= 1 && mouseControlPosition.X <= _sliderBarSize) { _currentSliderPosition = mouseControlPosition.X - 1; if (_sliderPositionValues[_currentSliderPosition] != -1) { _value = _sliderPositionValues[_currentSliderPosition]; if (ValueChanged != null) ValueChanged.Invoke(this, EventArgs.Empty); this.IsDirty = true; } } } else { if (mouseControlPosition.X == 0 && mouseControlPosition.Y >= 1 && mouseControlPosition.Y <= _sliderBarSize) { _currentSliderPosition = mouseControlPosition.Y - 1; if (_sliderPositionValues[_currentSliderPosition] != -1) { _value = _sliderPositionValues[_currentSliderPosition]; if (ValueChanged != null) ValueChanged.Invoke(this, EventArgs.Empty); this.IsDirty = true; } } } } else Parent.ReleaseControl(); } return true; } else if(Parent.CapturedControl == this && !info.LeftButtonDown) { Parent.ReleaseControl(); } } return false; }
public static Point UpperLeftCorner(Point center, int width, int height) { return new Point(center.X - width / 2, center.Y - height / 2); }
public abstract Rectangle BuildChildArea(Point size);
/// <summary> /// Get a tile in world /// </summary> /// <param name="point"> Tile location </param> /// <param name="layer"> Layer to get tile from. Default uses current </param> /// <returns> Tile if found </returns> public WorldTile GetTile(Point point, int layer = -1) { return layers[layer == -1 ? SelectedLayer : layer][point.X, point.Y]; }
/// <summary> /// Sets a tile in world /// </summary> /// <param name="point"> Tile location </param> /// <param name="tile"> New tile </param> /// <param name="layerIndex"> Layer to set tile in. Default uses current </param> public void SetTile(Point point, WorldTile tile, int layerIndex = -1) { layers[layerIndex == -1 ? SelectedLayer : layerIndex][point.X, point.Y] = tile; ChangesMade = true; }
public unsafe FrameXNA(GraphicsDevice graphics, uint[] palette, BinaryReader bin) { int xCenter = bin.ReadInt16(); int yCenter = bin.ReadInt16(); int width = bin.ReadUInt16(); int height = bin.ReadUInt16(); // Fix for animations with no data. if ((width == 0) || (height == 0)) { _Texture = null; return; } uint[] data = new uint[width * height]; int header; int xBase = xCenter - 0x200; int yBase = (yCenter + height) - 0x200; fixed (uint* pData = data) { uint* dataRef = pData; int delta = width; int dataRead = 0; dataRef += xBase; dataRef += (yBase * delta); while ((header = bin.ReadInt32()) != 0x7FFF7FFF) { header ^= DoubleXor; uint* cur = dataRef + ((((header >> 12) & 0x3FF) * delta) + ((header >> 22) & 0x3FF)); uint* end = cur + (header & 0xFFF); int filecounter = 0; byte[] filedata = bin.ReadBytes(header & 0xFFF); while (cur < end) *cur++ = palette[filedata[filecounter++]]; dataRead += header & 0xFFF; } ClientVars.Metrics.ReportDataRead(dataRead); } _Center = new Microsoft.Xna.Framework.Point(xCenter, yCenter); _Texture = new Texture2D(graphics, width, height); _Texture.SetData<uint>(data); }
private void DrawSegment(Point center, Graphics g, XNAPoint point) { int rX = SEGMENT_DRAW_SIZE, rY = (int)(SEGMENT_DRAW_SIZE * SEGMENT_RATIO); Point p = new Point((point.Y - point.X) * rX, (point.X + point.Y) * rY); p.Offset(center); Point[] points = new Point[] { new Point(p.X - rX, p.Y), new Point(p.X, p.Y + rY), new Point(p.X + rX, p.Y), new Point(p.X, p.Y - rY), new Point(p.X - rX, p.Y) }; g.DrawLines(Pens.Black, points); g.FillPolygon(new SolidBrush(Color.FromArgb(100, Color.Black)), points); }
public unsafe AnimationFrame(GraphicsDevice graphics, uint[] palette, byte[] frame, int width, int height, int xCenter, int yCenter) { palette[0] = 0xFFFFFFFF; uint[] data = new uint[width * height]; fixed (uint* pData = data) { uint* dataRef = pData; int frameIndex = 0; while (frameIndex < frame.Length) { *dataRef++ = palette[frame[frameIndex++]]; } } m_Center = new Microsoft.Xna.Framework.Point(xCenter, yCenter); m_Texture = new Texture2D(graphics, width, height); m_Texture.SetData<uint>(data); palette[0] = 0; }
public unsafe AnimationFrame(GraphicsDevice graphics, ushort[] palette, BinaryFileReader reader) { int xCenter = reader.ReadShort(); int yCenter = reader.ReadShort(); int width = reader.ReadUShort(); int height = reader.ReadUShort(); // Fix for animations with no IO. if ((width == 0) || (height == 0)) { m_Texture = null; return; } ushort[] data = new ushort[width * height]; int header; int xBase = xCenter - 0x200; int yBase = (yCenter + height) - 0x200; fixed (ushort* pData = data) { ushort* dataRef = pData; int delta = width; int dataRead = 0; dataRef += xBase; dataRef += (yBase * delta); while ((header = reader.ReadInt()) != 0x7FFF7FFF) { header ^= DoubleXor; ushort* cur = dataRef + ((((header >> 12) & 0x3FF) * delta) + ((header >> 22) & 0x3FF)); ushort* end = cur + (header & 0xFFF); int filecounter = 0; byte[] filedata = reader.ReadBytes(header & 0xFFF); while (cur < end) *cur++ = palette[filedata[filecounter++]]; dataRead += header & 0xFFF; } Metrics.ReportDataRead(dataRead); } m_Center = new Microsoft.Xna.Framework.Point(xCenter, yCenter); m_Texture = new Texture2D(graphics, width, height, false, SurfaceFormat.Bgra5551); m_Texture.SetData<ushort>(data); }