internal void Draw(System.Windows.Point point, int idx) { int x = (int)point.X / _tileRenderXY; int y = (int)point.Y / _tileRenderXY; // Return if off screen if (y >= _level.mapHeight || x >= _level.mapWidth) { return; } int currCanvas = 0; if (_Layer2_RadioButton.IsChecked == true) { currCanvas = 1; } else if (_Layer3_RadioButton.IsChecked == true) { currCanvas = 2; } // The same tile is already present so no need to draw. if (_layerTiles[currCanvas][(x + y * _level.mapWidth)].tileMapIdx == idx && _layerTiles[currCanvas][(x + y * _level.mapWidth)].spriteSheetIdx == _TabControl_SpriteSheets.SelectedIndex) { return; } // Push Tile onto Undo stack UndoRedo.TilePlacement_Add(_layerTiles[currCanvas][(x + y * _level.mapWidth)]); _layerTiles[currCanvas][(x + y * _level.mapWidth)].tileMapIdx = idx; _layerTiles[currCanvas][(x + y * _level.mapWidth)].spriteSheetIdx = _TabControl_SpriteSheets.SelectedIndex; DrawTile(_layerTiles[currCanvas][(x + y * _level.mapWidth)]); }
public void Initialise(string tileSheetPath) { // Initialise the game properties if (_level.generalGameProperties == null) { _level.generalGameProperties = new GeneralGameProperties(); } // Initialise each sprite sheet _level.tileSheetPath = tileSheetPath; for (int i = 0; i < _spriteSheets.Length; i++) { _spriteSheets[i] = new List <CroppedBitmap>(); } InitialiseSpriteSheet(_level.tileSheetPath, 0); InitialiseSpriteSheet(".../.../images/sheetEnemies.png", 1); InitialiseSpriteSheet(".../.../images/sheetOther.png", 2); // Set the layer width and height for every layer int width = _level.mapWidth * _tileRenderXY; int height = _level.mapHeight * _tileRenderXY; _Layer0.Width = width; _Layer0.Height = height; _Layer1.Width = width; _Layer1.Height = height; _Layer2.Width = width; _Layer2.Height = height; _Layer3.Width = width; _Layer3.Height = height; _LayerGrid.Width = width; _LayerGrid.Height = height; // Clear all of the tiles from every layer _Layer0.Children.Clear(); _Layer1.Children.Clear(); _Layer2.Children.Clear(); _Layer3.Children.Clear(); _LayerGrid.Children.Clear(); _LayerDraw.Children.Clear(); // Clear the layer tile information stored for (int i = 0; i < _layerTiles.Length; i++) { _layerTiles[i] = new List <Tile>(); } // Fill each layer with empty tiles.. int x = 0, y = 0; for (int i = 0; i < _level.mapWidth * _level.mapHeight; i++, x++) { if (x == _level.mapWidth) { x = 0; y++; } Thickness marginThickness = new Thickness(x * _tileRenderXY, y * _tileRenderXY, 0, 0); _Layer0.Children.Add(CreateTileRect(new SolidColorBrush(Colors.White), marginThickness)); _Layer1.Children.Add(CreateTileRect(new SolidColorBrush(Colors.Transparent), marginThickness)); _Layer2.Children.Add(CreateTileRect(new SolidColorBrush(Colors.Transparent), marginThickness)); _Layer3.Children.Add(CreateTileRect(new SolidColorBrush(Colors.Transparent), marginThickness)); _LayerDraw.Children.Add(CreateTileRect(new SolidColorBrush(Colors.Transparent), marginThickness)); // Add the tile information to each layerTile layer for (int layer = 0; layer < _layerTiles.Length; layer++) { Tile newTile = new Tile(); newTile.tileMapIdx = -1; newTile.SetPosition(x, y); newTile.canvasIdx = layer; newTile.spriteSheetIdx = -1; _layerTiles[layer].Add(newTile); } } InitialiseGrid(); // Reset the undo and redo stacks UndoRedo.Reset(); }