public override void Move(Level l) { if (Death) { return; } Position p = l.GetSpritePosition(this); Position[] w = { new Position(p), new Position(p), new Position(p), new Position(p) }; if (Direction == Directions.Left) { w[0].x--; w[3].x++; if (Lastturn == Directions.Left) { w[1].y--; w[2].y++; } else { w[1].y++; w[2].y--; }; } if (Direction == Directions.Right) { w[0].x++; w[3].x--; if (Lastturn == Directions.Left) { w[1].y++; w[2].y--; } else { w[1].y--; w[2].y++; }; } if (Direction == Directions.Up) { w[0].y--; w[3].y++; if (Lastturn == Directions.Left) { w[1].x++; w[2].x--; } else { w[1].x--; w[2].x++; }; } if (Direction == Directions.Down) { w[0].y++; w[3].y--; if (Lastturn == Directions.Left) { w[1].x--; w[2].x++; } else { w[1].x++; w[2].x--; }; } for (int i = 0; i < 4; i++) { if (!p.Equal(w[i])) { Position d = new Position(w[i]); // Digger if (l.GetSprite(d.x, d.y).GetType() == typeof(Digger)) { l.Digger.Die(); } // Nothing if (l.GetSprite(d.x, d.y).GetType() == typeof(Nothing)) { Directions LastDirection = Direction; if (d.x < p.x) { Direction = Directions.Left; } if (d.x > p.x) { Direction = Directions.Right; } if (d.y < p.y) { Direction = Directions.Up; } if (d.y > p.y) { Direction = Directions.Down; } switch (LastDirection) { case Directions.Left: if (Direction == Directions.Down) { Lastturn = Directions.Left; } if (Direction == Directions.Up) { Lastturn = Directions.Right; } break; case Directions.Right: if (Direction == Directions.Down) { Lastturn = Directions.Right; } if (Direction == Directions.Up) { Lastturn = Directions.Left; } break; case Directions.Up: if (Direction == Directions.Left) { Lastturn = Directions.Left; } if (Direction == Directions.Right) { Lastturn = Directions.Right; } break; case Directions.Down: if (Direction == Directions.Left) { Lastturn = Directions.Right; } if (Direction == Directions.Right) { Lastturn = Directions.Left; } break; } l.SetSprite(d.x, d.y, this); l.SetSprite(p.x, p.y, new Nothing()); return; } } } }
public void Move(Level l, int x, int y) { int dx = x; int dy = y; // Follow gravitation if (l.GetSprite(x, y + 1).GetType() == typeof(Marker)) { dy = y + 1; } else { // Falls to the left or to the right if (l.GetSprite(x, y + 1).GetType() == typeof(Stone) || l.GetSprite(x, y + 1).GetType() == typeof(Diamond) || l.GetSprite(x, y + 1).GetType() == typeof(Nothing)) { if (l.GetSprite(x - 1, y + 1).GetType() == typeof(Marker) && (l.GetSprite(x - 1, y).GetType() == typeof(Nothing) || l.GetSprite(x - 1, y).GetType() == typeof(Marker))) { dx = x - 1; dy = y + 1; } else { if (l.GetSprite(x + 1, y + 1).GetType() == typeof(Marker) && (l.GetSprite(x + 1, y).GetType() == typeof(Nothing) || l.GetSprite(x + 1, y).GetType() == typeof(Marker))) { dx = x + 1; dy = y + 1; } } } // Changer if (l.GetSprite(x, y + 1).GetType() == typeof(Changer) && l.GetSprite(x, y).GetType() == typeof(Stone) && l.GetSprite(x, y + 2).GetType() == typeof(Marker)) { dy = y + 2; } } // Move if ((dx != x) || (dy != y)) { if ((dy - y) == 2) { // changer l.SetSprite(dx, dy, new Diamond()); } else { l.SetSprite(dx, dy, l.GetSprite(x, y)); if (l.GetSprite(dx, dy).GetType() == typeof(UvStone)) { l.SetSprite(dx, dy, new Stone()); } } l.SetSprite(x, y, new Nothing()); // Kill digger if necessary if (l.GetSprite(dx, dy + 1).GetType() == typeof(Digger)) { l.Digger.Die(); } if (l.GetSprite(dx, dy + 1).GetType().BaseType == typeof(Ghost)) { Ghost g = (Ghost)l.GetSprite(dx, dy + 1); g.Blast(l); } } }