コード例 #1
0
        private void TestForDanger(Missile missile)
        {
            Vector2 delta = missile.Velocity;
            delta.Normalize();
            delta *= Vector2.Subtract(missile.Position, this.Position).Length();

            IDoodad doodad = null;
            float minFraction = float.MaxValue;
            this.world.RayCast((f, p, n, fr) =>
                                   {
                                       if (!(f.Body.UserData is Pit))
                                       {
                                           if (fr < minFraction)
                                           {
                                               minFraction = fr;
                                               doodad = f.Body.UserData as IDoodad;
                                           }

                                           return 1;
                                       }
                                       else
                                       {
                                           return -1;
                                       }
                                   },
                                   missile.Position,
                                   missile.Position + delta);

            // in the calling method we established there was a missle near us.
            // after the ray cast finishes we know whether the missile is on a
            // collision course with this tank. If it is try to shoot it down!
            if (doodad != null && doodad.Equals(this))
            {
                if (this.CanFireMissile(missile.Position))
                {
                    Vector2 missileDelta = Vector2.Subtract(missile.Position, this.Position);
                    float theta = (float)Math.Atan2(missileDelta.Y, missileDelta.X);
                    float noise = MathHelper.PiOver4 / 4;
                    theta += (float)(noise - this.random.NextDouble() * 2 * noise);
                    this.FireAtTarget(theta);
                }
            }
        }
コード例 #2
0
        public IDoodad CreateDoodad(DoodadPlacement doodadPlacement)
        {
            IDoodad doodad;
            switch (doodadPlacement.DoodadType)
            {
                case DoodadType.Tile:
                    doodad = new TileDoodad(doodadPlacement.Position, doodadPlacement.Rotation, doodadPlacement.Source);
                    break;
                case DoodadType.Tank:
                    if (doodadPlacement.Team == Team.Green)
                    {
                        doodad = new PlayerControlledTank(
                            this.soundManager,
                            this,
                            this.world,
                            this.doodads,
                            doodadPlacement.Team,
                            this.random,
                            doodadPlacement.Position,
                            doodadPlacement.Rotation);
                    }
                    else
                    {
                        doodad = new ComputerControlledTank(
                            this.soundManager,
                            this.world,
                            this.doodads,
                            doodadPlacement.Team,
                            doodadPlacement.Position,
                            doodadPlacement.Rotation,
                            this.random,
                            this,
                            this.waypoints.Where(waypoint => waypoint.Color.ToLowerInvariant() == doodadPlacement.WaypointColor.ToLowerInvariant()));
                    }

                    break;
                case DoodadType.Wall:
                    doodad = new Wall(this.world, doodadPlacement.Position, doodadPlacement.Rotation, doodadPlacement.Source);
                    break;
                case DoodadType.Missile:
                    doodad = new Missile(
                        this.soundManager,
                        this.world,
                        this.doodads,
                        doodadPlacement.NumberOfBounces,
                        doodadPlacement.Team,
                        doodadPlacement.Position,
                        doodadPlacement.Rotation,
                        this);
                    break;
                case DoodadType.Pit:
                    doodad = new Pit(
                        this.world,
                        doodadPlacement.Position,
                        doodadPlacement.Rotation,
                        doodadPlacement.Source);
                    break;
                case DoodadType.Waypoint:
                    doodad = new Waypoint(doodadPlacement.Position, doodadPlacement.WaypointColor, this.waypoints);
                    break;
                case DoodadType.BlastMark:
                    doodad = new BlastMark(doodadPlacement.Position, this.random);
                    break;
                case DoodadType.TreadMark:
                    doodad = new TreadMark(doodadPlacement.Position, doodadPlacement.Rotation, this.doodads);
                    break;
                case DoodadType.PowerUp:
                    doodad = new PowerUp(
                        this.soundManager,
                        this.world,
                        this.random,
                        this.doodads,
                        doodadPlacement.Position,
                        this);
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }

            this.doodads.Add(doodad);
            return doodad;
        }
コード例 #3
0
 public MissileView(Missile missile)
 {
     this.missile = missile;
 }