private Bitmap DrawBullet(Bitmap image, Animation animation, bool flip, int zoom) { var width = image.Width; var height = image.Height; var xOff = Constants.SpriteWidth * zoom; var yOff = Constants.SpriteHeight * zoom; var newImage = new MyBitmap(width + xOff * 2, height + yOff * 2, this.pictureBox.BackColor); newImage.DrawImage(MyBitmap.FromBitmap(image), xOff, yOff); if (animation.Offsets.GunXOff >= 0) { var bullet = this.bulletConfig.Bullets.First(b => b.BulletId == animation.BulletId); var flipFlags = bullet.GetFlipFlags(flip); var bulletBitmap = bullet.Sprite.GetSprite( this.applyPaletteCheckbox.Checked, flipFlags.HasFlag(ImageFlags.VFlip), flipFlags.HasFlag(ImageFlags.HFlip), this.pictureBox.BackColor).Clone(); var scaled = bulletBitmap.Scale(zoom); if (flip) { newImage.DrawImage( scaled, xOff + animation.Offsets.GunXOffFlip * zoom, yOff + animation.Offsets.GunYOffFlip * zoom); } else { newImage.DrawImage( scaled, xOff + animation.Offsets.GunXOff * zoom, yOff + animation.Offsets.GunYOff * zoom); } } return(newImage.ToBitmap()); }
private void LoadButtonClick(object sender, EventArgs e) { var fileName = this.inputTextBox.Text; if (!File.Exists(fileName)) { MessageBox.Show("File doesn't exit"); } this.bitmap = MyBitmap.FromFile(fileName); if (this.bitmap.Width != Constants.BgWidth || this.bitmap.Height != Constants.BgHeight) { MessageBox.Show($"Incorrect size, should be {Constants.BgWidth}x{Constants.BgHeight}"); } this.tiles = new List <MyBitmap>(); this.positions = new List <Point>(); var indices = new int[32, 24]; for (var y = 0; y < this.bitmap.Height / Constants.NesTileSize; y++) { for (var x = 0; x < this.bitmap.Width / Constants.NesTileSize; x++) { var smallImage = bitmap.GetPart(x * Constants.NesTileSize, y * Constants.NesTileSize, Constants.NesTileSize, Constants.NesTileSize); if (this.tiles.Any(v => v.Equals(smallImage))) { indices[x, y] = this.tiles.IndexOf(smallImage); } else { this.tiles.Add(smallImage); this.positions.Add(new Point(x * Constants.NesTileSize, y * Constants.NesTileSize)); indices[x, y] = this.tiles.Count - 1; } } } const int entryWidth = 65; const int horizontalSpacing = 8; const int entriesInRow = 7; const int leftPadding = 12; const int imageWidth = entryWidth + (entryWidth + horizontalSpacing) * (entriesInRow - 1) + leftPadding; const int entryHeight = 33; const int verticalSpacing = 2; const int topPadding = 12; var rowCount = (this.tiles.Count + entriesInRow - 1) / entriesInRow; var imageHeight = rowCount * entryHeight + (rowCount - 1) * verticalSpacing + topPadding; this.smallImagesBitmap = new MyBitmap(imageWidth, imageHeight); var font = new Font("Calibri", 8); for (var i = 0; i < this.tiles.Count; i++) { var x = (i % entriesInRow) * (entryWidth + horizontalSpacing) + leftPadding; var y = (i / entriesInRow) * (entryHeight + verticalSpacing) + topPadding; var tile = this.tiles[i].Scale(2); var subImage = new MyBitmap(entryWidth, entryHeight); subImage.DrawImage(tile, (entryWidth - tile.Width) / 2, 0); var tempBitmap = subImage.ToBitmap(); using (var g = Graphics.FromImage(tempBitmap)) { g.DrawString(string.Format("{0:D3}: {1:D3}/{2:D3}", i, this.positions[i].X, this.positions[i].Y), font, Brushes.Black, 0, 18); } this.smallImagesBitmap.DrawImage(MyBitmap.FromBitmap(tempBitmap), x, y); } this.smallImagesPanel.BackgroundImage = this.smallImagesBitmap.ToBitmap(); var str = string.Empty; for (var y = 0; y < this.bitmap.Height / Constants.NesTileSize; y++) { for (var x = 0; x < this.bitmap.Width / Constants.NesTileSize; x++) { str += indices[x, y].ToString("D3") + " "; } str += Environment.NewLine; } this.textBox.Text = str; this.UpdateImage(); }