当前位置: 首页>>代码示例>>C#>>正文


C# WPos类代码示例

本文整理汇总了C#中WPos的典型用法代码示例。如果您正苦于以下问题:C# WPos类的具体用法?C# WPos怎么用?C# WPos使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


WPos类属于命名空间,在下文中一共展示了WPos类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ActorsInBox

 public IEnumerable<Actor> ActorsInBox(WPos a, WPos b)
 {
     var left = Math.Min(a.X, b.X);
     var top = Math.Min(a.Y, b.Y);
     var right = Math.Max(a.X, b.X);
     var bottom = Math.Max(a.Y, b.Y);
     var region = BinRectangleCoveringWorldArea(left, top, right, bottom);
     var minCol = region.Left;
     var minRow = region.Top;
     var maxCol = region.Right;
     var maxRow = region.Bottom;
     for (var row = minRow; row <= maxRow; row++)
     {
         for (var col = minCol; col <= maxCol; col++)
         {
             foreach (var actor in BinAt(row, col).Actors)
             {
                 if (actor.IsInWorld)
                 {
                     var c = actor.CenterPosition;
                     if (left <= c.X && c.X <= right && top <= c.Y && c.Y <= bottom)
                         yield return actor;
                 }
             }
         }
     }
 }
开发者ID:zombie-einstein,项目名称:OpenRA,代码行数:27,代码来源:ActorMap.cs

示例2: SpriteEffect

		public SpriteEffect(WPos pos, World world, string sprite, string palette)
		{
			this.pos = pos;
			this.palette = palette;
			anim = new Animation(world, sprite);
			anim.PlayThen("idle", () => world.AddFrameEndTask(w => w.Remove(this)));
		}
开发者ID:JackKucan,项目名称:OpenRA,代码行数:7,代码来源:SpriteEffect.cs

示例3: FallDown

		public FallDown(Actor self, WPos dropPosition, int fallRate, Actor ignoreActor = null)
		{
			pos = self.TraitOrDefault<IPositionable>();
			IsInterruptible = false;
			fallVector = new WVec(0, 0, fallRate);
			this.dropPosition = dropPosition;
		}
开发者ID:GraionDilach,项目名称:OpenRA.Mods.AS,代码行数:7,代码来源:FallDown.cs

示例4: TextRenderable

        public TextRenderable(SpriteFont font, WPos pos, int zOffset, Color color, string text)
            : this(font, pos, zOffset, color,
			       ChromeMetrics.Get<Color>("TextContrastColorDark"),
			       ChromeMetrics.Get<Color>("TextContrastColorLight"),
			       text)
        {
        }
开发者ID:pchote,项目名称:OpenRA,代码行数:7,代码来源:TextRenderable.cs

示例5: GetImpactType

		public static ImpactType GetImpactType(World world, CPos cell, WPos pos)
		{
			// Missiles need a margin because they sometimes explode a little above ground
			// due to their explosion check triggering slightly too early (because of CloseEnough).
			// TODO: Base ImpactType on target altitude instead of explosion altitude.
			var airMargin = new WDist(128);

			var dat = world.Map.DistanceAboveTerrain(pos);
			var isAir = dat.Length > airMargin.Length;
			var isWater = dat.Length <= 0 && world.Map.GetTerrainInfo(cell).IsWater;
			var isDirectHit = GetDirectHit(world, cell, pos);

			if (isAir && !isDirectHit)
				return ImpactType.Air;
			else if (isWater && !isDirectHit)
				return ImpactType.Water;
			else if (isAir && isDirectHit)
				return ImpactType.AirHit;
			else if (isWater && isDirectHit)
				return ImpactType.WaterHit;
			else if (isDirectHit)
				return ImpactType.GroundHit;

			return ImpactType.Ground;
		}
开发者ID:Roger-luo,项目名称:OpenRA,代码行数:25,代码来源:CreateEffectWarhead.cs

示例6: GpsSatellite

        public GpsSatellite(World world, WPos pos)
        {
            this.pos = pos;

            anim = new Animation(world, "sputnik");
            anim.PlayRepeating("idle");
        }
开发者ID:gitTerebi,项目名称:OpenRA,代码行数:7,代码来源:GpsSatellite.cs

示例7: NukeLaunch

        public NukeLaunch(Player firedBy, string weapon, WPos launchPos, WPos targetPos, WDist velocity, int delay, bool skipAscent, string flashType)
        {
            this.firedBy = firedBy;
            this.weapon = weapon;
            this.delay = delay;
            this.turn = delay / 2;
            this.flashType = flashType;

            var offset = new WVec(WDist.Zero, WDist.Zero, velocity * turn);
            ascendSource = launchPos;
            ascendTarget = launchPos + offset;
            descendSource = targetPos + offset;
            descendTarget = targetPos;

            anim = new Animation(firedBy.World, weapon);
            anim.PlayRepeating("up");

            pos = launchPos;
            var weaponRules = firedBy.World.Map.Rules.Weapons[weapon.ToLowerInvariant()];
            if (weaponRules.Report != null && weaponRules.Report.Any())
                Sound.Play(weaponRules.Report.Random(firedBy.World.SharedRandom), pos);

            if (skipAscent)
                ticks = turn;
        }
开发者ID:rhamilton1415,项目名称:OpenRA,代码行数:25,代码来源:NukeLaunch.cs

示例8: ActorsInBox

        public IEnumerable<Actor> ActorsInBox(WPos a, WPos b)
        {
            var left = Math.Min(a.X, b.X);
            var top = Math.Min(a.Y, b.Y);
            var right = Math.Max(a.X, b.X);
            var bottom = Math.Max(a.Y, b.Y);
            var i1 = (left / info.BinSize).Clamp(0, cols - 1);
            var i2 = (right / info.BinSize).Clamp(0, cols - 1);
            var j1 = (top / info.BinSize).Clamp(0, rows - 1);
            var j2 = (bottom / info.BinSize).Clamp(0, rows - 1);

            for (var j = j1; j <= j2; j++)
            {
                for (var i = i1; i <= i2; i++)
                {
                    foreach (var actor in bins[j * cols + i].Actors)
                    {
                        if (actor.IsInWorld)
                        {
                            var c = actor.CenterPosition;
                            if (left <= c.X && c.X <= right && top <= c.Y && c.Y <= bottom)
                                yield return actor;
                        }
                    }
                }
            }
        }
开发者ID:RobotCaleb,项目名称:OpenRA,代码行数:27,代码来源:ActorMap.cs

示例9: MinimumPointLineProjection

        /// <summary>
        /// Find the point (D) on a line (A-B) that is closest to the target point (C).
        /// </summary>
        /// <param name="lineStart">The source point (tail) of the line</param>
        /// <param name="lineEnd">The target point (head) of the line</param>
        /// <param name="point">The target point that the minimum distance should be found to</param>
        /// <returns>The WPos that is the point on the line that is closest to the target point</returns>
        public static WPos MinimumPointLineProjection(WPos lineStart, WPos lineEnd, WPos point)
        {
            var squaredLength = (lineEnd - lineStart).HorizontalLengthSquared;

            // Line has zero length, so just use the lineEnd position as the closest position.
            if (squaredLength == 0)
                return lineEnd;

            // Consider the line extending the segment, parameterized as target + t (source - target).
            // We find projection of point onto the line.
            // It falls where t = [(point - target) . (source - target)] / |source - target|^2
            // The normal DotProduct math would be (xDiff + yDiff) / dist, where dist = (target - source).LengthSquared;
            // But in order to avoid floating points, we do not divide here, but rather work with the large numbers as far as possible.
            // We then later divide by dist, only AFTER we have multiplied by the dotproduct.
            var xDiff = ((long)point.X - lineEnd.X) * (lineStart.X - lineEnd.X);
            var yDiff = ((long)point.Y - lineEnd.Y) * (lineStart.Y - lineEnd.Y);
            var t = xDiff + yDiff;

            // Beyond the 'target' end of the segment
            if (t < 0)
                return lineEnd;

            // Beyond the 'source' end of the segment
            if (t > squaredLength)
                return lineStart;

            // Projection falls on the segment
            return WPos.Lerp(lineEnd, lineStart, t, squaredLength);
        }
开发者ID:pchote,项目名称:OpenRA,代码行数:36,代码来源:WorldExtensions.cs

示例10: AirstrikePowerASEffect

		public AirstrikePowerASEffect(World world, Player p, WPos pos, IEnumerable<Actor> planes, AirstrikePowerASInfo info)
		{
			this.info = info;
			this.world = world;
			this.Owner = p;
			this.pos = pos;
			this.planes = planes;

			if (info.DisplayBeacon)
			{
				var distance = (planes.First().OccupiesSpace.CenterPosition - pos).HorizontalLength;

				beacon = new Beacon(
					Owner,
					pos - new WVec(WDist.Zero, WDist.Zero, world.Map.DistanceAboveTerrain(pos)),
					info.BeaconPaletteIsPlayerPalette,
					info.BeaconPalette,
					info.BeaconImage,
					info.BeaconPoster,
					info.BeaconPosterPalette,
					info.ArrowSequence,
					info.CircleSequence,
					info.ClockSequence,
						() => 1 - ((planes.First().OccupiesSpace.CenterPosition - pos).HorizontalLength - info.BeaconDistanceOffset.Length) * 1f / distance);

				world.AddFrameEndTask(w => w.Add(beacon));
			}
		}
开发者ID:GraionDilach,项目名称:OpenRA.Mods.AS,代码行数:28,代码来源:AirstrikePowerASEffect.cs

示例11: FindActorsOnLine

        /// <summary>
        /// Finds all the actors of which their health radius is intersected by a line (with a definable width) between two points.
        /// </summary>
        /// <param name="world">The engine world the line intersection is to be done in.</param>
        /// <param name="lineStart">The position the line should start at</param>
        /// <param name="lineEnd">The position the line should end at</param>
        /// <param name="lineWidth">How close an actor's health radius needs to be to the line to be considered 'intersected' by the line</param>
        /// <returns>A list of all the actors intersected by the line</returns>
        public static IEnumerable<Actor> FindActorsOnLine(this World world, WPos lineStart, WPos lineEnd, WDist lineWidth, WDist targetExtraSearchRadius)
        {
            // This line intersection check is done by first just finding all actors within a square that starts at the source, and ends at the target.
            // Then we iterate over this list, and find all actors for which their health radius is at least within lineWidth of the line.
            // For actors without a health radius, we simply check their center point.
            // The square in which we select all actors must be large enough to encompass the entire line's width.
            var xDir = Math.Sign(lineEnd.X - lineStart.X);
            var yDir = Math.Sign(lineEnd.Y - lineStart.Y);

            var dir = new WVec(xDir, yDir, 0);
            var overselect = dir * (1024 + lineWidth.Length + targetExtraSearchRadius.Length);
            var finalTarget = lineEnd + overselect;
            var finalSource = lineStart - overselect;

            var actorsInSquare = world.ActorMap.ActorsInBox(finalTarget, finalSource);
            var intersectedActors = new List<Actor>();

            foreach (var currActor in actorsInSquare)
            {
                var actorWidth = 0;
                var healthInfo = currActor.Info.TraitInfoOrDefault<HealthInfo>();
                if (healthInfo != null)
                    actorWidth = healthInfo.Shape.OuterRadius.Length;

                var projection = MinimumPointLineProjection(lineStart, lineEnd, currActor.CenterPosition);
                var distance = (currActor.CenterPosition - projection).HorizontalLength;
                var maxReach = actorWidth + lineWidth.Length;

                if (distance <= maxReach)
                    intersectedActors.Add(currActor);
            }

            return intersectedActors;
        }
开发者ID:pchote,项目名称:OpenRA,代码行数:42,代码来源:WorldExtensions.cs

示例12: SelectionBoxRenderable

 public SelectionBoxRenderable(WPos pos, Rectangle bounds, float scale, Color color)
 {
     this.pos = pos;
     this.bounds = bounds;
     this.scale = scale;
     this.color = color;
 }
开发者ID:RobotCaleb,项目名称:OpenRA,代码行数:7,代码来源:SelectionBoxRenderable.cs

示例13: IsValidImpact

		public bool IsValidImpact(WPos pos, Actor firedBy)
		{
			var world = firedBy.World;
			var targetTile = world.Map.CellContaining(pos);
			if (!world.Map.Contains(targetTile))
				return false;

			var impactType = GetImpactType(world, targetTile, pos, firedBy);
			var validImpact = false;
			switch (impactType)
			{
				case ImpactType.TargetHit:
					validImpact = true;
					break;
				case ImpactType.Air:
					validImpact = IsValidTarget(new string[] { "Air" });
					break;
				case ImpactType.Ground:
					var tileInfo = world.Map.GetTerrainInfo(targetTile);
					validImpact = IsValidTarget(tileInfo.TargetTypes);
					break;
			}

			return validImpact;
		}
开发者ID:GraionDilach,项目名称:OpenRA.Mods.AS,代码行数:25,代码来源:WarheadAS.cs

示例14: NukeLaunch

        public NukeLaunch(Player firedBy, string name, WeaponInfo weapon, string weaponPalette, string upSequence, string downSequence,
			WPos launchPos, WPos targetPos, WDist velocity, int delay, bool skipAscent, string flashType)
        {
            this.firedBy = firedBy;
            this.weapon = weapon;
            this.weaponPalette = weaponPalette;
            this.downSequence = downSequence;
            this.delay = delay;
            turn = delay / 2;
            this.flashType = flashType;

            var offset = new WVec(WDist.Zero, WDist.Zero, velocity * turn);
            ascendSource = launchPos;
            ascendTarget = launchPos + offset;
            descendSource = targetPos + offset;
            descendTarget = targetPos;

            anim = new Animation(firedBy.World, name);
            anim.PlayRepeating(upSequence);

            pos = launchPos;
            if (weapon.Report != null && weapon.Report.Any())
                Game.Sound.Play(weapon.Report.Random(firedBy.World.SharedRandom), pos);

            if (skipAscent)
                ticks = turn;
        }
开发者ID:OpenRA,项目名称:OpenRA,代码行数:27,代码来源:NukeLaunch.cs

示例15: SatelliteLaunch

        public SatelliteLaunch(Actor a)
        {
            doors.PlayThen("active",
                () => a.World.AddFrameEndTask(w => w.Remove(this)));

            pos = a.CenterPosition;
        }
开发者ID:Generalcamo,项目名称:OpenRA,代码行数:7,代码来源:SatelliteLaunch.cs


注:本文中的WPos类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。