Skip to content

Instantly share code, notes, and snippets.

@ScottLilly ScottLilly/WorldMap.cs Secret
Created Sep 6, 2018

Embed
What would you like to do?
Draw border around current location in world map
using System.Drawing;
using System.IO;
using System.Reflection;
using System.Windows.Forms;
using Engine;
namespace SuperAdventure
{
public partial class WorldMap : Form
{
private readonly Assembly _thisAssembly = Assembly.GetExecutingAssembly();
private readonly Player _player;
private readonly Bitmap _fogImage;
public WorldMap(Player player)
{
InitializeComponent();
_player = player;
_fogImage = FilenameToBitmap("FogLocation");
DisplayImage(pic_0_2, 5, "HerbalistsGarden");
DisplayImage(pic_1_2, 4, "HerbalistsHut");
DisplayImage(pic_2_0, 7, "FarmFields");
DisplayImage(pic_2_1, 6, "Farmhouse");
DisplayImage(pic_2_2, 2, "TownSquare");
DisplayImage(pic_2_3, 3, "TownGate");
DisplayImage(pic_2_4, 8, "Bridge");
DisplayImage(pic_2_5, 9, "SpiderForest");
DisplayImage(pic_3_2, 1, "Home");
}
private void DisplayImage(PictureBox pictureBox, int locationID, string imageName)
{
if(_player.LocationsVisited.Contains(locationID))
{
pictureBox.Image = FilenameToBitmap(imageName);
// Draw a rectangle over the image,
// for the player's current location image
if(_player.CurrentLocation.ID == locationID)
{
using(Graphics g = Graphics.FromImage(pictureBox.Image))
{
int borderWidth = 3;
g.DrawRectangle(new Pen(Brushes.Red, borderWidth),
new Rectangle(0, 0, pictureBox.Image.Width - borderWidth,
pictureBox.Image.Height - borderWidth));
}
}
}
else
{
pictureBox.Image = _fogImage;
}
}
private Bitmap FilenameToBitmap(string imageFileName)
{
string fullFileName =
$"{_thisAssembly.GetName().Name}.Images.{imageFileName}.png";
using(Stream resourceStream =
_thisAssembly.GetManifestResourceStream(fullFileName))
{
if(resourceStream != null)
{
return new Bitmap(resourceStream);
}
}
return null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.