示例#1
0
 public abstract bool Over(PolygonHitbox other);
示例#2
0
        private void DrawPrediction(SpriteBatch sb)
        {
            var    simWorld = _turnStart.Clone();
            double dt       = 1 / 60.0;

            if (_popup != null)
            {
                _commands[_popup.ShipId] = _popup.CurrentCommands();
            }
            foreach (var ship in simWorld.Ships)
            {
                GetShipCommands(ship);
            }
            var controllers = _commands.ToDictionary(c => c.Key, c => (IShipController) new PlayerShipController(c.Value));

            var predictionPoints = new Dictionary <Guid, List <Vector> >();

            foreach (var ship in simWorld.Ships)
            {
                predictionPoints[ship.Uid] = new List <Vector>();
            }

            var shipCheckpoints = new List <Ship>();

            var lasers = new List <Tuple <Vector, Vector> >();

            for (double time = 0; time < World.TurnLength; time += dt)
            {
                simWorld.Update(dt, controllers);
                if (time < 1 && time + dt >= 1 || time < 2 && time + dt >= 2 || time < 3 && time + dt >= 3)
                {
                    foreach (var ship in simWorld.Ships)
                    {
                        shipCheckpoints.Add(ship.Clone());
                    }
                }
                foreach (var ship in simWorld.Ships)
                {
                    predictionPoints[ship.Uid].Add(ship.Position / Game1.ScaleHack);
                    if (ship.ShotTimer > 0)
                    {
                        var len   = ship.LazerLength();
                        var start = ship.Position;
                        var d     = Vector.AtAngle(ship.Angle) * len;
                        var angle = Math.Atan2(d.Y, d.X);
                        var end   = d + start;
                        lasers.Add(new Tuple <Vector, Vector>(start / Game1.ScaleHack, end / Game1.ScaleHack));
                    }
                }
            }
            foreach (var entry in predictionPoints)
            {
                var points = entry.Value;
                for (int i = 0; i < points.Count - 1; i++)
                {
                    PolygonHitbox.DrawLine(sb, points[i], points[i + 1], Color.White, 2);
                }
                if (simWorld.Ships.All(s => s.Uid != entry.Key))
                {
                    var lastPoint = points[points.Count - 1];
                    sb.Draw(
                        Resources.Pixel,
                        new Rectangle((int)lastPoint.X, (int)lastPoint.Y, 3, 3),
                        Color.Red
                        );
                }
            }
            foreach (var laser in lasers)
            {
                PolygonHitbox.DrawLine(sb, laser.Item1, laser.Item2, Color.Red * 0.1f, 2);
            }
            foreach (var ship in shipCheckpoints)
            {
                ship.Scale(Game1.ScaleHack);
                ship.Draw(sb);
            }
        }