Wände werden nun mit runden ecken gezeichnet
This commit is contained in:
52
src/Gui/Dummytile.cs
Normal file
52
src/Gui/Dummytile.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
namespace WorldOfPeacecraft
|
||||
{
|
||||
// A ITile always returning it is a wall and 0,0 as position
|
||||
public class Dummytile : ITile
|
||||
{
|
||||
private static Dummytile Instance = new Dummytile();
|
||||
|
||||
public Dummytile ()
|
||||
{
|
||||
}
|
||||
|
||||
public static Dummytile GetInstance()
|
||||
{
|
||||
return Instance;
|
||||
}
|
||||
|
||||
public bool IsWall()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool IsWalkable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool IsWater()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool IsForest()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool IsHuntable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public int GetX()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int GetY ()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,8 +24,20 @@ namespace WorldOfPeacecraft
|
||||
private Image Knight;
|
||||
private Image Walkable;
|
||||
private Image Water;
|
||||
private Image Wall;
|
||||
private Image Flowers;
|
||||
private Image WallBase;
|
||||
private Image WallEdgeTopLeft;
|
||||
private Image WallEdgeTopRight;
|
||||
private Image WallEdgeBotRight;
|
||||
private Image WallEdgeBotLeft;
|
||||
private Image WallCornerTopLeft;
|
||||
private Image WallCornerTopRight;
|
||||
private Image WallCornerBotRight;
|
||||
private Image WallCornerBotLeft;
|
||||
private Image WallInnerTopLeft;
|
||||
private Image WallInnerTopRight;
|
||||
private Image WallInnerBotRight;
|
||||
private Image WallInnerBotLeft;
|
||||
private Image BeachTop;
|
||||
private Image BeachBottom;
|
||||
private Image BeachLeft;
|
||||
@@ -53,7 +65,6 @@ namespace WorldOfPeacecraft
|
||||
Knight = Image.FromFile (ImagesFolder + "knight.png");
|
||||
Walkable = Image.FromFile (ImagesFolder + "walkable.jpg");
|
||||
Water = Image.FromFile (ImagesFolder + "water.jpg");
|
||||
Wall = Image.FromFile(ImagesFolder + "wall.jpg");
|
||||
Flowers = Image.FromFile(ImagesFolder + "flowers.png");
|
||||
BeachBottom = Image.FromFile (ImagesFolder + "beach.png");
|
||||
BeachLeft = RotateFlipImage (BeachBottom, RotateFlipType.Rotate90FlipNone);
|
||||
@@ -63,6 +74,19 @@ namespace WorldOfPeacecraft
|
||||
BeachBottomLeft = RotateFlipImage (BeachBottomRight, RotateFlipType.Rotate90FlipNone);
|
||||
BeachTopLeft = RotateFlipImage (BeachBottomRight, RotateFlipType.Rotate180FlipNone);
|
||||
BeachTopRight = RotateFlipImage (BeachBottomRight, RotateFlipType.Rotate270FlipNone);
|
||||
WallBase = Image.FromFile(ImagesFolder + "wall_base.png");
|
||||
WallEdgeBotLeft = Image.FromFile (ImagesFolder + "wall_edge_botleft.png");
|
||||
WallEdgeBotRight = Image.FromFile (ImagesFolder + "wall_edge_botright.png");
|
||||
WallEdgeTopLeft = Image.FromFile (ImagesFolder + "wall_edge_topleft.png");
|
||||
WallEdgeTopRight = Image.FromFile (ImagesFolder + "wall_edge_topright.png");
|
||||
WallCornerBotLeft = Image.FromFile (ImagesFolder + "wall_corner_botleft.png");
|
||||
WallCornerBotRight = Image.FromFile (ImagesFolder + "wall_corner_botright.png");
|
||||
WallCornerTopLeft = Image.FromFile (ImagesFolder + "wall_corner_topleft.png");
|
||||
WallCornerTopRight = Image.FromFile (ImagesFolder + "wall_corner_topright.png");
|
||||
WallInnerBotLeft = Image.FromFile (ImagesFolder + "wall_inner_botleft.png");
|
||||
WallInnerBotRight = Image.FromFile (ImagesFolder + "wall_inner_botright.png");
|
||||
WallInnerTopLeft = Image.FromFile (ImagesFolder + "wall_inner_topleft.png");
|
||||
WallInnerTopRight = Image.FromFile (ImagesFolder + "wall_inner_topright.png");
|
||||
}
|
||||
|
||||
private Image RotateFlipImage(Image image, RotateFlipType type)
|
||||
@@ -140,27 +164,42 @@ namespace WorldOfPeacecraft
|
||||
ITile tile = map [locx, locy];
|
||||
int x = locx * TileSize;
|
||||
int y = locy * TileSize;
|
||||
Image image = null;
|
||||
if (tile.IsWater ()) {
|
||||
if (tile.IsWall ()) {
|
||||
PaintImage(g, x, y, WallBase);
|
||||
ITile top = GetTile(locx, locy - 1, map);
|
||||
ITile topright = GetTile(locx + 1, locy - 1, map);
|
||||
ITile right = GetTile(locx + 1, locy, map);
|
||||
ITile botright = GetTile(locx + 1, locy + 1, map);
|
||||
ITile bot = GetTile(locx, locy + 1, map);
|
||||
ITile botleft = GetTile(locx - 1, locy + 1, map);
|
||||
ITile left = GetTile(locx - 1, locy, map);
|
||||
ITile topleft = GetTile(locx - 1, locy - 1, map);
|
||||
int offset = TileSize - 12;
|
||||
DrawWallEdge(g, CountWater (left, topleft, top), x, y, 0, 0, WallEdgeTopLeft, WallCornerTopLeft);
|
||||
DrawWallEdge(g, CountWater (top, topright, right), x, y, offset, 0, WallEdgeTopRight, WallCornerTopRight);
|
||||
DrawWallEdge(g, CountWater (right, botright, bot), x, y, offset, offset, WallEdgeBotRight, WallCornerBotRight);
|
||||
DrawWallEdge(g, CountWater (bot, botleft, left), x, y, 0, offset, WallEdgeBotLeft, WallCornerBotLeft);
|
||||
} else if (tile.IsWater ()) {
|
||||
PaintImage(g, x, y, Water);
|
||||
} else if (tile.IsWall ()) {
|
||||
PaintImage (g, x, y, Wall);
|
||||
} else {
|
||||
PaintWallInnerEdge(g, locx, locy, x, y, map);
|
||||
}
|
||||
else {
|
||||
PaintImage (g, x, y, Walkable);
|
||||
PaintWallInnerEdge(g, locx, locy, x, y, map);
|
||||
bool beachPlaced = false;
|
||||
if (locx > 0 && map[locx - 1,locy].IsWater()) {
|
||||
if (NullsafeIsWater(locx - 1, locy, map)) {
|
||||
PaintImage(g, x, y, BeachLeft);
|
||||
beachPlaced = true;
|
||||
}
|
||||
if (locx < map.GetLength(0) - 1 && map[locx + 1,locy].IsWater()) {
|
||||
if (NullsafeIsWater(locx + 1, locy, map)) {
|
||||
PaintImage (g, x, y, BeachRight);
|
||||
beachPlaced = true;
|
||||
}
|
||||
if (locy > 0 && map[locx, locy - 1].IsWater()) {
|
||||
if (NullsafeIsWater(locx, locy - 1, map)) {
|
||||
PaintImage (g, x, y, BeachTop);
|
||||
beachPlaced = true;
|
||||
}
|
||||
if (locy < map.GetLength(1) - 1 && map[locx, locy + 1].IsWater()) {
|
||||
if (NullsafeIsWater(locx, locy + 1, map)) {
|
||||
PaintImage (g, x, y, BeachBottom);
|
||||
beachPlaced = true;
|
||||
}
|
||||
@@ -193,16 +232,16 @@ namespace WorldOfPeacecraft
|
||||
}
|
||||
if (tile.IsForest ()) {
|
||||
PaintImage (g, x, y, Forest);
|
||||
if (locx > 0 && map[locx - 1,locy].IsForest()) {
|
||||
if (NullsafeIsForrest(locx - 1, locy, map)) {
|
||||
PaintImage(g, x, y, ForestLeft);
|
||||
}
|
||||
if (locx < map.GetLength(0) - 1 && map[locx + 1,locy].IsForest()) {
|
||||
if (NullsafeIsForrest(locx + 1, locy, map)) {
|
||||
PaintImage (g, x, y, ForestRight);
|
||||
}
|
||||
if (locy > 0 && map[locx, locy - 1].IsForest()) {
|
||||
if (NullsafeIsForrest(locx, locy - 1, map)) {
|
||||
PaintImage (g, x, y, ForestTop);
|
||||
}
|
||||
if (locy < map.GetLength(1) - 1 && map[locx, locy + 1].IsForest()) {
|
||||
if (NullsafeIsForrest(locx, locy + 1, map)) {
|
||||
PaintImage (g, x, y, ForestBottom);
|
||||
}
|
||||
} else if (tile.IsWalkable()) {
|
||||
@@ -219,6 +258,90 @@ namespace WorldOfPeacecraft
|
||||
}
|
||||
}
|
||||
|
||||
private void PaintWallInnerEdge (Graphics g, int locx, int locy, int x, int y, ITile[,] map)
|
||||
{
|
||||
bool topWall = NullsafeIsWall (locx, locy - 1, map);
|
||||
bool rightWall = NullsafeIsWall (locx + 1, locy, map);
|
||||
bool botWall = NullsafeIsWall (locx, locy + 1, map);
|
||||
bool leftWall = NullsafeIsWall (locx - 1, locy, map);
|
||||
if (leftWall) {
|
||||
if (topWall)
|
||||
PaintImage (g, x, y, WallInnerTopLeft);
|
||||
if (botWall)
|
||||
PaintImage (g, x, y, WallInnerBotLeft);
|
||||
}
|
||||
if (rightWall) {
|
||||
if (topWall)
|
||||
PaintImage (g, x, y, WallInnerTopRight);
|
||||
if (botWall)
|
||||
PaintImage (g, x, y, WallInnerBotRight);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawWallEdge (Graphics g, int water, int x, int y, int offsetx, int offsety, Image edgeImage, Image cornerImage)
|
||||
{
|
||||
if (water == -1)
|
||||
PaintImage (g, x, y, edgeImage);
|
||||
else {
|
||||
Rectangle src = new Rectangle(0 + offsetx, 0 + offsety, 12, 12);
|
||||
Rectangle dst = new Rectangle(x + offsetx, y + offsety, 12, 12);
|
||||
if (water == 3) {
|
||||
g.DrawImage(Water, dst, src, GraphicsUnit.Pixel);
|
||||
PaintImage(g, x, y, cornerImage);
|
||||
}
|
||||
else if (water == 0) {
|
||||
g.DrawImage(Walkable, dst, src, GraphicsUnit.Pixel);
|
||||
PaintImage(g, x, y, cornerImage);
|
||||
}
|
||||
else
|
||||
PaintImage (g, x, y, edgeImage);
|
||||
}
|
||||
}
|
||||
|
||||
private static int CountWater (params ITile[] tiles)
|
||||
{
|
||||
int water = 0;
|
||||
foreach (ITile tile in tiles) {
|
||||
if (tile.IsWall())
|
||||
return -1;
|
||||
if (tile.IsWater())
|
||||
water++;
|
||||
}
|
||||
return water;
|
||||
}
|
||||
|
||||
private bool NullsafeIsWater (int x, int y, ITile[,] map)
|
||||
{
|
||||
ITile tile = GetTile (x, y, map);
|
||||
if (tile == null)
|
||||
return false;
|
||||
return tile.IsWater();
|
||||
}
|
||||
|
||||
private bool NullsafeIsWall (int x, int y, ITile[,] map)
|
||||
{
|
||||
ITile tile = GetTile (x, y, map);
|
||||
if (tile == null)
|
||||
return true;
|
||||
return tile.IsWall();
|
||||
}
|
||||
|
||||
private bool NullsafeIsForrest (int x, int y, ITile[,] map)
|
||||
{
|
||||
ITile tile = GetTile (x, y, map);
|
||||
if (tile == null)
|
||||
return false;
|
||||
return tile.IsForest();
|
||||
}
|
||||
|
||||
private static ITile GetTile (int x, int y, ITile[,] map)
|
||||
{
|
||||
if (x >= 0 && x < map.GetLength (0) && y >= 0 && y < map.GetLength (1)) {
|
||||
return map[x,y];
|
||||
}
|
||||
return Dummytile.GetInstance();
|
||||
}
|
||||
|
||||
public void PaintEntities (Graphics g)
|
||||
{
|
||||
IEnumerable<IEntity> dragons = Backend.GetDragons ();
|
||||
|
||||
Reference in New Issue
Block a user