/// <summary> /// 显示风中粒子 /// </summary> /// <param name="role">所修饰角色</param> /// <param name="equipType">所参照的装备</param> /// <param name="particleType">粒子类型</param> /// <param name="color">颜色</param> /// <param name="amount">量</param> public void ShowWindParticles(RoleBase role, EquipTypes equipType, ParticleTypes particleType, double color, double amount) { ObjectBase equip = role.EquipEntity(equipType); if (!equip.IsVisible) { return; } int distance = 0; double speed = 0; if (role.Action == Actions.Stop) { distance = 40; speed = RandomSeed.Next(2000, 3000) * 0.01; } else { distance = 40; speed = RandomSeed.Next(1000, 1500) * 0.01; } int halfDistance = distance / 2; int obliqueDistance = distance * 2 / 3; Dispatcher.BeginInvoke(delegate { WriteableBitmap writeableBitmap = new WriteableBitmap(equip, null); if (writeableBitmap.Pixels.Count() != 0) { lock (writeableBitmap) { writeableBitmap.Invalidate(); int z = 0; if (equipType == EquipTypes.Weapon) { if (role.State == States.Riding && role.Direction != Directions.South) { z = role.Z + equip.Z + 5; } else { z = role.Z + equip.Z; } } else { z = (role.Direction == Directions.North || role.Direction == Directions.NorthEast || role.Direction == Directions.NorthWest) ? role.Z : role.Z - 20; } z -= role.ZAddition; Point position = equipType == EquipTypes.Overall ? role.Center : equip.Position; Point2D destination = new Point2D(); EffectBase effect = null; if (color == 0) { effect = new MonoChrome() { FilterColor = Colors.White }; } else if (color == 1) { effect = new MonoChrome() { FilterColor = Colors.Black }; } else { effect = new ShiftHue() { HueShift = color }; } switch (role.Direction) { case Directions.North: destination.X = 0; destination.Y = RandomSeed.Next(halfDistance, distance); break; case Directions.NorthEast: destination.X = -RandomSeed.Next(halfDistance, obliqueDistance); destination.Y = RandomSeed.Next(halfDistance, obliqueDistance); break; case Directions.East: destination.X = -RandomSeed.Next(halfDistance, distance); destination.Y = 0; break; case Directions.SouthEast: destination.X = -RandomSeed.Next(halfDistance, obliqueDistance); destination.Y = -RandomSeed.Next(halfDistance, obliqueDistance); break; case Directions.South: destination.X = 0; destination.Y = -RandomSeed.Next(halfDistance, distance); break; case Directions.SouthWest: destination.X = RandomSeed.Next(halfDistance, obliqueDistance); destination.Y = -RandomSeed.Next(halfDistance, obliqueDistance); break; case Directions.West: destination.X = RandomSeed.Next(halfDistance, distance); destination.Y = 0; break; case Directions.NorthWest: destination.X = RandomSeed.Next(halfDistance, obliqueDistance); destination.Y = RandomSeed.Next(halfDistance, obliqueDistance); break; } for (int i = 0; i < amount; i++) { int x = RandomSeed.Next(0, writeableBitmap.PixelWidth); int y = RandomSeed.Next(0, writeableBitmap.PixelHeight); byte[] bytes = BitConverter.GetBytes(writeableBitmap.Pixels[writeableBitmap.PixelWidth * y + x]); if (bytes[3] != 0) { Particle particle = new Particle() { SpaceLayer = role.SpaceLayer, Z = z, Effect = effect, Source = GlobalMethod.GetImage(string.Format("Particle/{0}{1}.png", particleType, RandomSeed.Next(0, 3)), UriType.Project) }; space.Children.Add(particle); EventHandler handler = null; particle.Disposed += handler = (s, e) => { Particle p = s as Particle; p.Disposed -= handler; space.Children.Remove(p); }; double pX = (position.X - x) * particle.Scale; double pY = (position.Y - y) * particle.Scale; particle.Move(new Point(role.Position.X - pX, role.Position.Y - pY), new Point(role.Position.X - pX + destination.X * particle.Scale, role.Position.Y - pY + destination.Y * particle.Scale), speed, MoveModes.Opacity); } } } } }); }
/// <summary> /// 根据中心点矩阵范X*Y围铺设地图地砖 /// </summary> /// <param name="center">中心点(通常为主角/英雄位置)</param> /// <param name="force">是否强制铺设(针对场景切换后角色所处地块不变)</param> public void LayingMap(Point center, bool force) { Point2D newTile = new Point2D((int)((center.X + offset.X) / tileSize.X), (int)((center.Y + offset.Y) / tileSize.Y)); if (force || newTile.X != lastTile.X || newTile.Y != lastTile.Y) { lastTile = newTile; //根据主角当前位置来加载周边屏幕分辨率下的地砖 int startX, startY, endX, endY; if (newTile.X == 0) { startX = 0; endX = tileRange.X * 2; } else if (newTile.X == tileLimit.X) { startX = tileLimit.X - tileRange.X * 2; endX = tileLimit.X; } else { startX = newTile.X - tileRange.X; endX = newTile.X + tileRange.X; } if (startX < 0) { startX = 0; } if (endX > tileLimit.X) { endX = tileLimit.X; } if (newTile.Y == 0) { startY = 0; endY = tileRange.Y * 2; } else if (newTile.Y == tileLimit.Y) { startY = tileLimit.Y - tileRange.Y * 2; endY = tileLimit.Y; } else { startY = newTile.Y - tileRange.Y; endY = newTile.Y + tileRange.Y; } if (startY < 0) { startY = 0; } //越界处理 if (endY > tileLimit.Y) { endY = tileLimit.Y; } //越界处理 int index = 0; //取回已经超出主角周围N块范围的地砖(x,y初始为-1,第一次加载N块) tile[] tempTiles = tileList.Where(c => c.X < startX || c.X > endX || c.Y < startY || c.Y > endY).ToArray(); for (int x = startX; x <= endX; x++) { for (int y = startY; y <= endY; y++) { //N点位中假如已经有该点位的地砖在则检查下一个 if (tileList.Where(c => c.X == x && c.Y == y).Count() > 0) { continue; } else { //将超出范围的地砖填充到新的位置上,并重置它们的x,y点位坐标值 tempTiles[index].Code = Code; tempTiles[index].X = x; tempTiles[index].Y = y; //下载实际图片 OpenReadCompletedEventHandler handler = null; ParallelDownloader downloader = new ParallelDownloader(); downloader.OpenReadCompleted += handler = (s, e) => { (s as ParallelDownloader).OpenReadCompleted -= handler; string[] args = e.UserState.ToString().Split('_'); int tempIndex = Convert.ToInt32(args[0]), tempX = Convert.ToInt32(args[1]), tempY = Convert.ToInt32(args[2]); if (tempTiles[tempIndex].Code == Code && tempTiles[tempIndex].X == tempX && tempTiles[tempIndex].Y == tempY) { tiles[tempTiles[tempIndex].Num].Source = GlobalMethod.GetImage(string.Format("Space/{0}/Map/{1}_{2}.jpg", Code, tempX, tempY),UriType.Web); Canvas.SetLeft(tiles[tempTiles[tempIndex].Num], tempX * tileSize.X); Canvas.SetTop(tiles[tempTiles[tempIndex].Num], tempY * tileSize.Y); } }; downloader.OpenReadAsync(GlobalMethod.WebPath(string.Format("Space/{0}/Map/{1}_{2}.jpg", Code, x, y)), DownloadPriority.Highest, string.Format("{0}_{1}_{2}", index, x, y), true, 3000); index++; } } } //按区域显示/隐藏动画和遮挡 SetAnimationVisibleTo(leader); SetMaskVisibleTo(leader); } }