Example #1
0
        public double time = 0.0; // tiden för spelat spel

        #endregion Fields

        #region Methods

        //undersöker om skeppet krockat med en asteroid
        public void crash(Skepp skepp, Asteroids asteroid)
        {
            double xDiff = skepp.location[0] - asteroid.location[0]; // hur mycket det diffar i x-led
            double yDiff = skepp.location[1] - asteroid.location[1]; // hur mycket det diffar i y-led

            double radius = 15 + 20; // radien för skeppet och asteroden
            double dist = Math.Sqrt((xDiff * xDiff) + (yDiff * yDiff)); // krockar de? pythagoras
            if (radius > dist)
            {
                gameOver = true; // spelet är s**t om radien mellan dem är mindre än deras gemensamma radie
            }
        }
Example #2
0
 private void WallBounce(Asteroids asteroid)
 {
     if (Background.Left > asteroid.location[0])
     {
         asteroid.speed[0] = -asteroid.speed[0];
         asteroid.location[0] = Background.Left;
     }
     if (Background.Right < asteroid.location[0] + 40)
     {
         asteroid.speed[0] = -asteroid.speed[0];
         asteroid.location[0] = Background.Right - 40;
     }
     if (Background.Top < asteroid.location[1])
     {
         asteroid.speed[1] = -asteroid.speed[1];
         asteroid.location[1] = -Background.Top;
     }
     if (Background.Bottom < -asteroid.location[1] + 40)
     {
         asteroid.speed[1] = -asteroid.speed[1];
         asteroid.location[1] = -Background.Bottom + 40;
     }
 }