public static int GetDist(MyPosition p1, MyPosition p2) { if (!Game.game.OnBoard(p1.X, p1.Y) || !Game.game.OnBoard(p2.X, p2.Y)) { return((int)p1.Dist(p2)); } return(Dists[Game.GetPos((int)p1.X, (int)p1.Y), Game.GetPos((int)p2.X, (int)p2.Y)]); }
public static MyPosition GetHitPos(MyPosition startPos, MyPosition endPos, SimGame game, double bulletSpeed, SimUnit firering, bool stopOnEnd = true) { var dist = endPos.Dist(startPos); var time = GetShootTime(dist, bulletSpeed) * Const.Properties.TicksPerSecond * 15; var dx = (endPos.X - startPos.X) / time; var dy = (endPos.Y - startPos.Y) / time; var x = startPos.X; var y = startPos.Y; var d = startPos.Dist(endPos); for (var i = 0; i < time * 2; i++) { x += dx; y += dy; if (!game.game.OnBoard(x, y)) { return(new MyPosition(x, y)); } var tile = game.GetTileD(x, y); if (tile == Tile.Wall) { return(new MyPosition(x, y)); } tile = game.GetTileD(x - firering.Weapon.Parameters.Bullet.Size * 0.5, y - firering.Weapon.Parameters.Bullet.Size * 0.5); if (tile == Tile.Wall) { return(new MyPosition(x, y)); } tile = game.GetTileD(x + firering.Weapon.Parameters.Bullet.Size * 0.5, y - firering.Weapon.Parameters.Bullet.Size * 0.5); if (tile == Tile.Wall) { return(new MyPosition(x, y)); } var nextD = Math.Sqrt(MyPosition.Pow(x - endPos.X) + MyPosition.Pow(y - endPos.Y)); if (nextD > d && stopOnEnd || nextD < 0.3) { return(endPos); } d = nextD; foreach (var u in game.Units) { if (u == firering || u.unit.PlayerId != firering.unit.PlayerId) { continue; } var unit = u.unit; if (!(Math.Abs(x - unit.Position.X) > firering.Weapon.Parameters.Bullet.Size / 2 + unit.Size.X / 2 || Math.Abs(y - unit.Position.Y) > firering.Weapon.Parameters.Bullet.Size / 2 + unit.Size.Y / 2)) { return(new MyPosition(x, y)); } } } return(endPos); }
public static double GetShootTime(MyPosition pos, MyPosition end, double bulletSpeed) { var dist = end.Dist(pos); return(GetShootTime(dist, bulletSpeed)); }