private void newToolStripMenuItem_Click(object sender, EventArgs e) { map = new Tile[5, 5]; mapSize = new Size(5, 5); for (int i = 0; i < mapSize.Width; i++) { for (int j = 0; j < mapSize.Height; j++) { map[i, j] = new Tile(-1, 0); } } selectedTile = new Tile(0, 0); selectedPoint = new Point(1, 1); bitmap = Properties.Resources._default; TileGraphic.AutoScrollMinSize = bitmap.Size; //Adjust Graphics g = TileGraphic.CreateGraphics(); bitmap.SetResolution(g.DpiX, g.DpiY); g.Dispose(); graphicsPanel1.AutoScrollMinSize = new Size(mapSize.Width * tileSize.Width, mapSize.Height * tileSize.Height); graphicsPanel1.Invalidate(); TileGraphic.Invalidate(); }
private void modalDialogToolStripMenuItem_Click(object sender, EventArgs e) { ModalDialog dlg = new ModalDialog(); dlg.tileSetSizeHeight = tileSetSize.Height; dlg.tileSetSizeWidth = tileSetSize.Width; dlg.mapSizeHeight = mapSize.Height; dlg.mapSizeWidth = mapSize.Width; dlg.tileSize = tileSize.Width; dlg.myBitmap = bitmap; dlg.Apply += new ApplyEventHandler(dlg_Apply); if (DialogResult.OK == dlg.ShowDialog()) { if (dlg.myBitmap != null) { bitmap = new Bitmap(dlg.myBitmap); } tileSize.Width = dlg.tileSize; tileSize.Height = dlg.tileSize; tileSetSize.Width = dlg.tileSetSizeWidth; tileSetSize.Height = dlg.tileSetSizeHeight; Tile[,] aux = new Tile[dlg.mapSizeWidth, dlg.mapSizeHeight]; Size auxSize = new Size(dlg.mapSizeWidth, dlg.mapSizeHeight); for (int i = 0; i < auxSize.Width; i++) { for (int j = 0; j < auxSize.Height; j++) { if (i < mapSize.Width && j < mapSize.Height) { aux[i, j] = map[i, j]; } else { aux[i, j] = new Tile(0, 0); } } } map = new Tile[dlg.mapSizeWidth, dlg.mapSizeHeight]; mapSize = new Size(dlg.mapSizeWidth, dlg.mapSizeHeight); map = aux; Graphics g = TileGraphic.CreateGraphics(); bitmap.SetResolution(g.DpiX, g.DpiY); g.Dispose(); graphicsPanel1.AutoScrollMinSize = new Size(mapSize.Width * tileSize.Width, mapSize.Height * tileSize.Height); graphicsPanel1.Invalidate(); TileGraphic.Invalidate(); selectedTile = new Tile(0, 0); selectedPoint = new Point(1, 1); } }
public Form1() { InitializeComponent(); TileGraphic.AutoScrollMinSize = bitmap.Size; //Adjust Graphics g = TileGraphic.CreateGraphics(); bitmap.SetResolution(g.DpiX, g.DpiY); g.Dispose(); graphicsPanel1.AutoScrollMinSize = new Size(mapSize.Width * tileSize.Width, mapSize.Height * tileSize.Height); }
public void AddTile(TileGraphic tile) { if (_tiles.Any(t => t.XPos == tile.XPos && t.YPos == tile.YPos)) { //Remove the old one var oldTile = _tiles.FirstOrDefault(t => t.XPos == tile.XPos && t.YPos == tile.YPos); _tiles.Remove(oldTile); } _tiles.Add(tile); }
public void Update(double gameTime) { _mouseState = Mouse.GetState(); if (_mouseState.LeftButton == ButtonState.Pressed && _managerCamera.MouseInsideWindow()) { var x = (int)(_managerCamera.Position.X + _mouseState.X) / 16; var y = (int)(_managerCamera.Position.Y + _mouseState.Y) / 16; //Just for test if (_mainForm.CurrentLayer == CurrentLayer.LayerOne) { foreach (var tilePoint in _mainForm.TilePoints) { var realX = x + (_mainForm.TilePoints[0].X - tilePoint.X) * -1; var realY = y + (_mainForm.TilePoints[0].Y - tilePoint.Y) * -1; var tile = new TileGraphic { ManagerCamera = _managerCamera, XPos = (int)realX, YPos = (int)realY, AnimationSpeed = 0, TextureName = "overworld_tiles", TileFrames = new List <TileFrame> { new TileFrame { TextureXPos = (int)tilePoint.X, TextureYPos = (int)tilePoint.Y } }, ZPos = 0 }; tile.LoadContent(); _tiles.AddTile(tile); } } else { var tileCollision = new TileCollision(true) { ManagerCamera = _managerCamera, XPos = x, YPos = y }; _tiles.AddCollisionTile(tileCollision); } } }
private void TileGraphic_MouseDoubleClick(object sender, MouseEventArgs e) { Rectangle check = new Rectangle(0, 0, tileSetSize.Width * tileSize.Width, tileSetSize.Height * tileSize.Height); Point mouseXY = e.Location; mouseXY.X -= TileGraphic.AutoScrollPosition.X; mouseXY.Y -= TileGraphic.AutoScrollPosition.Y; if (check.Contains(e.Location)) { selectedTile.X = mouseXY.X / tileSize.Width; selectedTile.Y = mouseXY.Y / tileSize.Height; selectedPoint = mouseXY; } TileGraphic.Invalidate(); }
void dlg_Apply(object sender, ApplyEventArgs e) { if (e.Map != null) { bitmap = new Bitmap(e.Map); } tileSetSize.Width = e.TileSetSizeWidth; tileSetSize.Height = e.TileSetSizeHeight; tileSize.Width = e.TileSize; tileSize.Height = e.TileSize; Tile[,] aux = new Tile[e.MapSizeWidth, e.MapSizeHeight]; Size auxSize = new Size(e.MapSizeWidth, e.MapSizeHeight); for (int i = 0; i < auxSize.Width; i++) { for (int j = 0; j < auxSize.Height; j++) { if (i < mapSize.Width && j < mapSize.Height) { aux[i, j] = map[i, j]; } else { aux[i, j] = new Tile(0, 0); } } } map = new Tile[e.MapSizeWidth, e.MapSizeHeight]; mapSize = new Size(e.MapSizeWidth, e.MapSizeHeight); map = aux; TileGraphic.AutoScrollMinSize = bitmap.Size; Graphics g = TileGraphic.CreateGraphics(); bitmap.SetResolution(g.DpiX, g.DpiY); g.Dispose(); graphicsPanel1.AutoScrollMinSize = new Size(mapSize.Width * tileSize.Width, mapSize.Height * tileSize.Height); graphicsPanel1.Invalidate(); TileGraphic.Invalidate(); selectedTile = new Tile(0, 0); selectedPoint = new Point(1, 1); }
public static void DrawTile(RendererDestinationData destData, TileGraphic tileGraphic, int tileX, int tileY, bool useGlobalCamera) { useGlobalCamera = false; if (useGlobalCamera) { destData.Blit(tileGraphic.Tile, new Point(ScreenRenderer.ToTileX(tileX), ScreenRenderer.ToTileY(tileY)));//new Point((tileX * Constants.TILE_WIDTH) /*- (NewPlayerX * Constants.TILE_WIDTH) */- ScreenRenderer.MapXOffset, (tileY * Constants.TILE_HEIGHT) /*- (NewPlayerY * Constants.TILE_HEIGHT)*/ - ScreenRenderer.MapYOffset)); } else { destData.Blit(tileGraphic.Tile, new Point((tileX * Constants.TILE_WIDTH) /*- (NewPlayerX * Constants.TILE_WIDTH) */- ScreenRenderer.MapXOffset, (tileY * Constants.TILE_HEIGHT) /*- (NewPlayerY * Constants.TILE_HEIGHT)*/ - ScreenRenderer.MapYOffset)); } }