示例#1
0
        // MainModelView Constructor
        public MainModelView()
        {
            Random rand = new Random();

            numAsteroids = NUM_ROCKS;

            // Initialize a Ship pointing up, no velocity in middle of the board
            Player1Ship = new SpaceObject('S', 600, 400, 25, 0, -90);
            Player2Ship = new SpaceObject('E', 800, 400, 25, 0, -90);

            // Make a list of space objects and add player1 and player 2
            listOfSpaceObjects = new ObservableCollection <SpaceObject>();
            ListOfSpaceObjects.Add(Player1Ship);
            ListOfSpaceObjects.Add(Player2Ship);

            // Variables to initialize the array of asteroids
            double startX, startY, angle;

            // initialize the asteroids position and direction
            for (int i = 0; i < numAsteroids; i++)
            {
                startX = WINDOWWIDTH * (rand.NextDouble());
                startY = WINDOWHEIGHT * (rand.NextDouble());
                angle  = 360 * (rand.NextDouble());
                var rock = new SpaceObject('R', startX, startY, HEIGHT, VELOCITY / 2, angle);
                listOfSpaceObjects.Add(rock);
            }
            EstablishConnections();
            SetTimer();
        }
示例#2
0
 public void RemoveSpaceObject(SpaceObject so)
 {
     Application.Current.Dispatcher.Invoke(new Action(() =>
     {
         ListOfSpaceObjects.Remove(so);
         // If the rock is not at its smallest size....
         if (so.Type == 'R' && so.NumberOfHits < 2)
         {
             var rock = new SpaceObject('R', so.XCoordinate, so.YCoordinate, so.Height / 2, so.Velocity * 1.5, so.Theta + 30);
             rock.CollisionBoxSize = (int)so.Height / 2;
             rock.NumberOfHits     = so.NumberOfHits + 1;
             listOfSpaceObjects.Add(rock);
             rock = new SpaceObject('R', so.XCoordinate, so.YCoordinate, so.Height / 2, so.Velocity * 1.5, so.Theta - 30);
             rock.CollisionBoxSize = (int)so.Height / 2;
             rock.NumberOfHits     = so.NumberOfHits + 1;
             listOfSpaceObjects.Add(rock);
         }
     }));
 }