Exemple #1
0
        /// <summary>
        /// Set the player icon on the map
        /// </summary>
        /// <param name="player"></param>
        private void SetPlayerIcon(ActorItem player)
        {
            // convert to game positions
            double x = MapHelper.ConvertCoordinatesIntoMapPosition((double)Map.SizeFactor, (double)Map.OffsetX, player.Coordinate.X);
            double y = MapHelper.ConvertCoordinatesIntoMapPosition((double)Map.SizeFactor, (double)Map.OffsetY, player.Coordinate.Y);

            // check if a player icon already exists or not
            if (MapPlayer.id == 0)
            {
                // Create new player icon bitmap
                MapPlayer = new MapIcon
                {
                    id = 1
                };
            }

            // reset graphic
            Bitmap bitmap = AppHelper.createBitmap("assets\\player.png");

            MapPlayer.icon   = bitmap;
            MapPlayer.width  = bitmap.Width;
            MapPlayer.height = bitmap.Height;

            // work out pixel position
            int pixelX = Convert.ToInt32((x - 1) * 50 * (double)Map.SizeFactor) - (MapPlayer.icon.Size.Width / 2);
            int pixelY = Convert.ToInt32((y - 1) * 50 * (double)Map.SizeFactor) - (MapPlayer.icon.Size.Height / 2);

            // set position and direction
            MapPlayer.x     = pixelX;
            MapPlayer.y     = pixelY;
            MapPlayer.angle = Math.Abs(player.Heading * (180 / Math.PI) - 180);
            MapPlayer.setRotation();

            // add trail, this is done by just dividing the pixel

            int trailDistance    = 120;
            int trailDistanceMax = 200;
            int xDistance        = 0;
            int yDistance        = 0;

            if (MapTrail.Count > 0)
            {
                xDistance = Math.Abs(MapTrail[MapTrail.Count - 1].x - pixelX);
                yDistance = Math.Abs(MapTrail[MapTrail.Count - 1].y - pixelY);
            }

            // if map trail empty or either x or y distance traved is above 100, draw new trail
            if (MapTrail.Count == 0 || (xDistance > trailDistance || yDistance > trailDistance))
            {
                MapIcon MapTrailIcon = new MapIcon
                {
                    icon  = AppHelper.createBitmap("assets\\trail.png"),
                    id    = (MapTrail.Count + 1),
                    x     = pixelX,
                    y     = pixelY,
                    angle = 0
                };

                MapTrail.Add(MapTrailIcon);

                // set trail sizes
                MapTrailSizeWidth  = MapTrailIcon.icon.Width;
                MapTrailSizeHeight = MapTrailIcon.icon.Height;
            }

            // work out pixel position
            pixelX = Convert.ToInt32((x - 1) * 50 * (double)Map.SizeFactor) - 10;
            pixelY = Convert.ToInt32((y - 1) * 50 * (double)Map.SizeFactor) - 10;

            trailDistance    = 20;
            trailDistanceMax = 35;
            xDistance        = 0;
            yDistance        = 0;

            if (MapTrailMini.Count > 0)
            {
                xDistance = Math.Abs(MapTrailMini[MapTrailMini.Count - 1].x - pixelX);
                yDistance = Math.Abs(MapTrailMini[MapTrailMini.Count - 1].y - pixelY);
            }

            // if map trail empty or either x or y distance traved is above 100, draw new trail
            if (MapTrailMini.Count == 0 || (xDistance > trailDistance || yDistance > trailDistance))
            {
                // Ignore big jumps
                if (xDistance > trailDistanceMax || yDistance > trailDistanceMax)
                {
                    return;
                }

                xPositions.Add(pixelX);
                yPositions.Add(pixelY);

                MapIcon MapTrailMiniIcon = new MapIcon
                {
                    icon  = AppHelper.createBitmap("assets\\trailmini.png"),
                    id    = (MapTrailMini.Count + 1),
                    x     = pixelX,
                    y     = pixelY,
                    angle = 0
                };

                MapTrailMini.Add(MapTrailMiniIcon);

                // set trail sizes
                MapTrailMiniSizeWidth  = MapTrailMiniIcon.icon.Width;
                MapTrailMiniSizeHeight = MapTrailMiniIcon.icon.Height;
            }
        }