Example #1
0
        /// <summary>
        /// Creates new instance of the tank object.
        /// </summary>
        /// <param name="game">Associated game object.</param>
        /// <param name="spriteBatch">A sprite batch that can be used to draw on the display.</param>
        /// <param name="tankTexture">The tank's texture.</param>
        /// <param name="viewer">Associated <see cref="BingMapsViewer"/> over which the tank navigates.</param>
        /// <param name="startUpPosition">The tank's initial on-screen position.</param>
        /// <param name="pushPins">List of push-pins that the tank needs to follow.</param>
        public Tank(Game game, SpriteBatch spriteBatch, Texture2D tankTexture, BingMapsViewer viewer,
                    Vector2 startUpPosition, LinkedList <PushPin> pushPins)
            : base(game)
        {
            this.spriteBatch = spriteBatch;
            this.viewer      = viewer;
            this.tankTexture = tankTexture;
            this.pushPins    = pushPins;

            // Gets the center point of the map displayed
            Vector2 positionOnMap = TileSystem.LatLongToPixelXY(viewer.CenterGeoCoordinate, viewer.ZoomLevel)
                                    - viewer.Offset;

            // Calculate the distance between the center of the screen and the tank's initial position
            Vector2 distance          = startUpPosition - BingMapsViewer.ScreenCenter;
            Vector2 startUpPointOnMap = positionOnMap + distance + new Vector2(32, 32);

            // Gets the tank's initial geo-coordinate
            currentGeoPosition = TileSystem.PixelXYToLatLong(startUpPointOnMap, viewer.ZoomLevel);

            RoutingMode     = BingRoutingMode.Driving;
            ShouldDrawRoute = false;

            routeRender = new RouteRender(game.GraphicsDevice);

            tankOrigin = new Vector2(tankTexture.Width / 2, tankTexture.Height / 2);
        }
Example #2
0
 /// <summary>
 /// Creates a new push-pin instance.
 /// </summary>
 /// <param name="bingMapsViewer">The associated <see cref="BingMapsViewer"/> that will draw the
 /// pushpin.</param>
 /// <param name="location">The geo-coordinate where the push-pin should be placed.</param>
 /// <param name="texture">The texture used to render the push-pin.</param>
 public PushPin(BingMapsViewer bingMapsViewer, GeoCoordinate location, Texture2D texture)
 {
     this.ID             = Guid.NewGuid();
     this.bingMapsViewer = bingMapsViewer;
     Location            = location;
     this.texture        = texture;
     screenBounds        = bingMapsViewer.SpriteBatch.GraphicsDevice.Viewport.Bounds;
 }
        /// <summary>
        /// Load Bing maps assets.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // Loads assets
            blank            = Content.Load <Texture2D>("blank");
            buttonFont       = Content.Load <SpriteFont>("Font");
            tankTexture2D    = Content.Load <Texture2D>("tank");
            pushPinTexture2D = Content.Load <Texture2D>("pushpin");
            Texture2D defaultImage     = Content.Load <Texture2D>("noImage");
            Texture2D unavailableImage = Content.Load <Texture2D>("noImage");

            // Creates the button that allows the user to switch between maps
            switchViewButton = new Button("Switch to\nRoad View", buttonFont, Color.White,
                                          new Rectangle(10, 10, 110, 60), Color.Black, blank, spriteBatch);
            switchViewButton.Click += switchViewButton_Click;

            // The coordinate that the app will focus
            startingCoordinate = new GeoCoordinate(47.639597, -122.12845);

            bingMapsViewer = new BingMapsViewer(BingAppKey, defaultImage, unavailableImage,
                                                startingCoordinate, 5, ZoomLevel, spriteBatch);

            tank = new Tank(this, spriteBatch, tankTexture2D, bingMapsViewer, new Vector2(400, 240), pushPins);
            Components.Add(tank);

            changeRotuingModeButton = new Button(string.Format("Switch to\n{0}", Tank.BingRoutingMode.Walking),
                                                 buttonFont, Color.White, new Rectangle(10, 80, 110, 60), Color.Black, blank, spriteBatch);
            changeRotuingModeButton.Click += new EventHandler(changeRotuingModeButton_Click);

            serachButton = new Button("Search",
                                      buttonFont, Color.White, new Rectangle(680, 10, 110, 60), Color.Black, blank, spriteBatch);
            serachButton.Click += new EventHandler(serachButton_Click);

            drawRouteButton = new Button("Show\nRoute",
                                         buttonFont, Color.White, new Rectangle(680, 80, 110, 60), Color.Black, blank, spriteBatch);
            drawRouteButton.Click += new EventHandler(drawRouteButton_Click);

            clearPushPinsButton = new Button("Clear Road",
                                             buttonFont, Color.White, new Rectangle(680, 160, 110, 60), Color.Black, blank, spriteBatch);
            clearPushPinsButton.Click += new EventHandler(clearPushPinsButton_Click);
        }
Example #4
0
        /// <summary>
        /// Load Bing maps assets.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures
            spriteBatch = new SpriteBatch(GraphicsDevice);

            blank      = Content.Load <Texture2D>("blank");
            buttonFont = Content.Load <SpriteFont>("Font");

            switchViewButton = new Button("Switch to\nRoad view", buttonFont, Color.White,
                                          new Rectangle(10, 10, 100, 60), Color.Black, blank, spriteBatch);
            switchViewButton.Click += switchViewButton_Click;

            startingCoordinate = new GeoCoordinate(47.639597, -122.12845);

            Texture2D defaultImage     = Content.Load <Texture2D>("noImage");
            Texture2D unavailableImage = Content.Load <Texture2D>("noImage");

            bingMapsViewer = new BingMapsViewer(BingAppKey, defaultImage, unavailableImage,
                                                startingCoordinate, 5, 15, spriteBatch);
        }