DateTime _lastTick = DateTime.Now; // when did we last tell the sprites that time had passed?

        #endregion Fields

        #region Constructors

        public SpaceControl()
        {
            DoubleBuffered = true;  // keeps redraws and screen refresh from happening at the same time

            InitializeComponent();  // standard Windows Forms control init function

            Ship ship = new Ship();  // create the player's ship
            ship.Position = new Vector2F(100, 100);

            aiship = new AIShip();
            aiship.Position = new Vector2F(800, 100);

            Planet planet = new Planet();  // create the big Planet
            planet.Position = new Vector2F(400, 300);

            float orbit = 200;  // how far from the planet's center are the targets?
            List<Planet> targets = new List<Planet>();
            for (int i = 0; i < NumTargets; ++i)
            {
                // Create a target.  We're using "Planet", but we could use Sprite or a custom Target class.
                Planet target = new Planet();
                target.ImageFileName = "Images/FlatTarget.gif";  // standard target art
                target.Space = this;  // add the target to the simulation

                // Divide the targets uniformly around the planet.
                double angle = i * 2 * Math.PI / NumTargets;
                Vector2F offset = new Vector2F(Math.Cos(angle), Math.Sin(angle));
                target.Position = planet.Position + offset * orbit;
            }

            // Add planet, AIShip and ship to simulation.
            planet.Space = this;
            ship.Space = this;
            aiship.Space = this;
        }
        // For AI ship.
        public Missile(AIShip firer)
        {
            firerID = 1;

            // Create a missile.
            RotationInDegrees = firer.RotationInDegrees;
            RotationalVelocityInDegrees = 1080;  // spin 3 times per second!
            ImageFileName = "Images/Missile2.gif";  // default missile graphics

            float delta_v = 100;  // speed relative to firing ship

            Position = firer.Position;

            // Angle of zero has the sprite facing the top of the screen.
            Velocity = firer.Velocity + new Vector2F(delta_v * Math.Sin(RotationInRadians),
                                                     -delta_v * Math.Cos(RotationInRadians));
        }
        // For AI ship.
        public Missile(AIShip firer)
        {
            firerID = 1;

            // Create a missile.
            RotationInDegrees           = firer.RotationInDegrees;
            RotationalVelocityInDegrees = 1080;    // spin 3 times per second!
            ImageFileName = "Images/Missile2.gif"; // default missile graphics

            float delta_v = 100;                   // speed relative to firing ship

            Position = firer.Position;

            // Angle of zero has the sprite facing the top of the screen.
            Velocity = firer.Velocity + new Vector2F(delta_v * Math.Sin(RotationInRadians),
                                                     -delta_v * Math.Cos(RotationInRadians));
        }
示例#4
0
        public SpaceControl()
        {
            DoubleBuffered = true;  // keeps redraws and screen refresh from happening at the same time

            InitializeComponent();  // standard Windows Forms control init function

            Ship ship = new Ship(); // create the player's ship

            ship.Position = new Vector2F(100, 100);

            aiship          = new AIShip();
            aiship.Position = new Vector2F(800, 100);

            Planet planet = new Planet();  // create the big Planet

            planet.Position = new Vector2F(400, 300);

            float         orbit   = 200; // how far from the planet's center are the targets?
            List <Planet> targets = new List <Planet>();

            for (int i = 0; i < NumTargets; ++i)
            {
                // Create a target.  We're using "Planet", but we could use Sprite or a custom Target class.
                Planet target = new Planet();
                target.ImageFileName = "Images/FlatTarget.gif"; // standard target art
                target.Space         = this;                    // add the target to the simulation

                // Divide the targets uniformly around the planet.
                double   angle  = i * 2 * Math.PI / NumTargets;
                Vector2F offset = new Vector2F(Math.Cos(angle), Math.Sin(angle));
                target.Position = planet.Position + offset * orbit;
            }


            // Add planet, AIShip and ship to simulation.
            planet.Space = this;
            ship.Space   = this;
            aiship.Space = this;
        }