Beispiel #1
0
 /// <summary>
 /// Will find the next obstacle in the beam's way
 /// </summary>
 /// <param name="obstacles">the array where to look for objects</param>
 /// <param name="start">the starting point of the beam</param>
 /// <param name="direction">the way in which we go on the direction</param>
 /// <param name="angle">the angle of the path to look for an object</param>
 /// <returns>the closest obstacle on the given path</returns>
 private Obstacle FindObject(Obstacle[] obstacles, Vector2 start, short direction, float angle)
 {
     //update 1300 with MaxWidth
     //the beam of light
     RotatedRectangle beam = new RotatedRectangle(new Rectangle((int)start.X, (int)start.Y, 1300, 2), angle);
     beam.Origin = new Vector2(beam.X, beam.Y);
     float dmin = 1300;
     float distance;
     Obstacle colidedObstacle = null;
     foreach (var obstacle in obstacles)
     {
         distance = Vector2.Distance(start, obstacle.Center);
         if (beam.Intersects(obstacle) && distance < dmin && distance > 0)
         {
             dmin = Vector2.Distance(start, obstacle.Center);
             colidedObstacle = obstacle;
         }
     }
     return colidedObstacle;
 }
Beispiel #2
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // Load texture
            lightTexture = Content.Load<Texture2D>("light_tex");

            // Initialize obstacles
            obstacles[0] = new Obstacle(Obstacle.ObjectType.MIRROR, new Vector2(150.0f, 30f), 5, 15, (float)Math.PI / 6);
            obstacles[1] = new Obstacle(Obstacle.ObjectType.MIRROR, new Vector2(300, 30), 5, 15, 0f);
            obstacles[2] = new Obstacle(Obstacle.ObjectType.MIRROR, new Vector2(100), 5, 15, 0f);

            // TODO: use this.Content to load your game content here
        }