Strnad wird nun ums Wasser herum gezeichnet

This commit is contained in:
2014-05-11 23:20:32 +02:00
parent 2755dcdd92
commit 111dfc6634

View File

@@ -26,7 +26,14 @@ namespace WorldOfPeacecraft
private Image Water; private Image Water;
private Image Wall; private Image Wall;
private Image Flowers; private Image Flowers;
private Random random = new Random (); private Image BeachTop;
private Image BeachBottom;
private Image BeachLeft;
private Image BeachRight;
private Image BeachTopLeft;
private Image BeachTopRight;
private Image BeachBottomLeft;
private Image BeachBottomRight;
private int FlowerCounter; private int FlowerCounter;
public MapPanel (IBackend backend) public MapPanel (IBackend backend)
@@ -48,6 +55,21 @@ namespace WorldOfPeacecraft
Water = Image.FromFile (ImagesFolder + "water.jpg"); Water = Image.FromFile (ImagesFolder + "water.jpg");
Wall = Image.FromFile(ImagesFolder + "wall.jpg"); Wall = Image.FromFile(ImagesFolder + "wall.jpg");
Flowers = Image.FromFile(ImagesFolder + "flowers.png"); Flowers = Image.FromFile(ImagesFolder + "flowers.png");
BeachBottom = Image.FromFile (ImagesFolder + "beach.png");
BeachLeft = RotateFlipImage (BeachBottom, RotateFlipType.Rotate90FlipNone);
BeachTop = RotateFlipImage (BeachBottom, RotateFlipType.Rotate180FlipNone);
BeachRight = RotateFlipImage (BeachBottom, RotateFlipType.Rotate270FlipNone);
BeachBottomRight = Image.FromFile (ImagesFolder + "beachcorner.png");
BeachBottomLeft = RotateFlipImage (BeachBottomRight, RotateFlipType.Rotate90FlipNone);
BeachTopLeft = RotateFlipImage (BeachBottomRight, RotateFlipType.Rotate180FlipNone);
BeachTopRight = RotateFlipImage (BeachBottomRight, RotateFlipType.Rotate270FlipNone);
}
private Image RotateFlipImage(Image image, RotateFlipType type)
{
Image rotated = new Bitmap(image);
rotated.RotateFlip (type);
return rotated;
} }
protected override void OnLayout (LayoutEventArgs levent) protected override void OnLayout (LayoutEventArgs levent)
@@ -120,16 +142,54 @@ namespace WorldOfPeacecraft
int y = locy * TileSize; int y = locy * TileSize;
Image image = null; Image image = null;
if (tile.IsWater ()) { if (tile.IsWater ()) {
image = Water; PaintImage(g, x, y, Water);
} else if (tile.IsWall ()) { } else if (tile.IsWall ()) {
image = Wall; PaintImage (g, x, y, Wall);
} else { } else {
image = Walkable; PaintImage (g, x, y, Walkable);
bool beachPlaced = false;
if (locx > 0 && map[locx - 1,locy].IsWater()) {
PaintImage(g, x, y, BeachLeft);
beachPlaced = true;
}
if (locx < map.GetLength(0) - 1 && map[locx + 1,locy].IsWater()) {
PaintImage (g, x, y, BeachRight);
beachPlaced = true;
}
if (locy > 0 && map[locx, locy - 1].IsWater()) {
PaintImage (g, x, y, BeachTop);
beachPlaced = true;
}
if (locy < map.GetLength(1) - 1 && map[locx, locy + 1].IsWater()) {
PaintImage (g, x, y, BeachBottom);
beachPlaced = true;
}
if (!beachPlaced)
{
if (locx > 0)
{
if (locy > 0 && map[locx - 1, locy - 1].IsWater())
{
PaintImage (g, x, y, BeachTopLeft);
}
else if (locy < map.GetLength(1) - 1 && map[locx - 1, locy + 1].IsWater())
{
PaintImage (g, x, y, BeachBottomLeft);
}
}
if (locx < map.GetLength(0) - 1)
{
if (locy > 0 && map[locx + 1, locy - 1].IsWater())
{
PaintImage (g, x, y, BeachTopRight);
}
else if (locy < map.GetLength(1) - 1 && map[locx + 1, locy + 1].IsWater())
{
PaintImage (g, x, y, BeachBottomRight);
}
}
} }
if (image != null) {
PaintImage (g, x, y, image);
} else {
g.FillRectangle (new SolidBrush (Color.Red), x, y, TileSize, TileSize);
} }
if (tile.IsForest ()) { if (tile.IsForest ()) {
PaintImage (g, x, y, Forest); PaintImage (g, x, y, Forest);