Example #1
0
        protected override void Initialize()
        {
            base.Initialize();
            screenWidth  = GraphicsDevice.Viewport.Width;
            screenHeight = GraphicsDevice.Viewport.Height;

            Random random = new Random();

            helicopters = new List <Helicopter>();
            for (var i = 0; i < 4; i++)
            {
                var maxX     = screenWidth - Helicopter.frameWidth;
                var maxY     = screenHeight - Helicopter.frameHeight;
                var velocity = new Vector2(2f + 2f * (float)random.NextDouble(), 1.5f + 1.5f * (float)random.NextDouble());

                for (var j = 0; j < 20; j++)
                {
                    var position   = new Vector2(random.Next(maxX), random.Next(0, maxY));
                    var helicopter = new Helicopter(
                        this,
                        position,
                        velocity
                        );
                    if (!helicopter.collidesWith(helicopters))
                    {
                        helicopter.LoadContent();
                        helicopters.Add(helicopter);
                        break;
                    }
                }
            }
        }
Example #2
0
 public void collideWith(Helicopter other)
 {
     // TODO: Improve collision behavior, f.ex. http://en.wikipedia.org/wiki/Elastic_collision#Two-Dimensional_Collision_With_Two_Moving_Objects
     this.velocity *= -1;
 }
Example #3
0
 public Boolean collidesWith(Helicopter other)
 {
     return(this.getRectangle().Intersects(other.getRectangle()));
 }