public override void Render() { var originGraphicPosition = originPos - new CPos(0, originHeight, -originHeight); var distance = originGraphicPosition - GraphicPosition; var angle = distance.FlatAngle; var fit = distance.FlatDist / renderabledistance; var offset = CPos.FromFlatAngle(angle, renderabledistance); var curFrame = frame; for (int i = 0; i < fit; i++) { var renderable = renderables[curFrame]; var pos = new CPos(offset.X * i, offset.Y * i, 0); renderable.SetRotation(new VAngle(0, 0, 270 - angle)); renderable.SetPosition(originGraphicPosition + pos); renderable.Render(); if (curFrame-- <= 0) { curFrame = renderables.Length - 1; } } if (Settings.DeveloperMode) { rayPhysics.RenderDebug(); } }
public override Particle[] Create(World world, CPos position, int height) { var particles = new Particle[Count]; var length = Radius / (float)Count; for (int i = 0; i < Count; i++) { var angle = WarriorsSnuggery.Angle.ToArc(Angle); var pos = CPos.FromFlatAngle(angle, length * i); particles[i] = ParticleCache.Create(world, Type, position + pos, height); } return(particles); }
void reaimPointer() { var pos = Camera.LookAt + new CPos(0, -2048, 0) - targetedEnemy.GraphicPosition; pointer.Visible = pos.SquaredFlatDist > 8192 * 8192; if (!pointer.Visible) { return; } var angle = pos.FlatAngle; pointer.SetRotation(new VAngle(0, 0, -angle) + new VAngle(0, 0, 270)); pointer.SetPosition(CPos.FromFlatAngle(angle, 2048) - new CPos(0, 2048, 0)); }
public void Move(CPos target, int height) { TargetHeight = height; if (Position == target) { return; } var length = (originPos - target).FlatDist; var oldangle = (originPos - TargetPosition).FlatAngle; var newangle = (originPos - target).FlatAngle; var diff = WarriorsSnuggery.Angle.Diff(oldangle, newangle); diff = Math.Clamp(-diff, -projectile.ArcTurnSpeed, projectile.ArcTurnSpeed); TargetPosition = originPos + CPos.FromFlatAngle(oldangle + diff, length); }
List <Triangle> getTriangles(World world, CPos position, int height, MPos shroudPos, int radius) { var outerRadius = MathF.Sqrt(2) * radius * 1024; var pos1 = (shroudPos - new MPos(radius, radius)) / new MPos(2, 2); // Why MPos(1, 1) here? -> when 7/2=3, but we want 4. Thus (7+1)/2=4. (8+1)/2=4 so works for this case as well. var pos2 = (shroudPos + new MPos(radius, radius) + new MPos(1, 1)) / new MPos(2, 2); var triangles = new List <Triangle>(); var walls = world.WallLayer.GetRange(pos1, pos2); foreach (var wall in walls) { if (wall.Physics.IsEmpty || wall.Type.IsTransparent) { continue; } if (height > wall.Type.Height) { continue; } var angleA = (position - wall.EndPointA).FlatAngle; var angleB = (position - wall.EndPointB).FlatAngle; var pointC = position + CPos.FromFlatAngle(angleA, outerRadius); var pointD = position + CPos.FromFlatAngle(angleB, outerRadius); triangles.Add(new Triangle(wall.EndPointA, wall.EndPointB, pointC)); triangles.Add(new Triangle(wall.EndPointB, pointC, pointD)); } return(triangles); }
protected CPos clampToMaxRange(CPos origin, float angle) { var maxRadius = Type.MaxRange * RangeModifier; return(origin + CPos.FromFlatAngle(angle, maxRadius)); }
public List <Actor> PlacePatrols() { var actors = new List <Actor>(); // TODO: rework in spawnbound areas positions.AddRange(world.Map.PatrolSpawnLocations); for (int a = 0; a < Math.Floor(bounds.X / (float)info.SpawnBounds); a++) { for (int b = 0; b < Math.Floor(bounds.X / (float)info.SpawnBounds); b++) { var pos = new MPos(a * info.SpawnBounds, b * info.SpawnBounds); if (!areaBlocked(a, b) && !positions.Contains(pos)) { positions.Add(pos); } } } var multiplier = bounds.X * bounds.Y / (float)(32 * 32) + (world.Game.Save.Difficulty - 5) / 10f; var count = random.Next((int)(info.MinimumPatrols * multiplier), (int)(info.MaximumPatrols * multiplier)); if (positions.Count < count) { Log.Warning($"Unable to spawn patrol count ({count}) because there are not enough available spawn points ({positions.Count})."); count = positions.Count; } spawns = new MPos[count]; for (int i = 0; i < count; i++) { var posIndex = random.Next(positions.Count); spawns[i] = positions[posIndex]; positions.RemoveAt(posIndex); } var map = world.Map; foreach (var spawn in spawns) { var mid = spawn.ToCPos(); var patrol = getPatrol(); var unitCount = patrol.ActorTypes.Length; var group = new List <Actor>(); for (int j = 0; j < unitCount; j++) { var spawnPosition = CPos.Zero; if (j == 0) { spawnPosition = mid; } else if (j < 7) { var angle = Angle.ToArc(60 * j); spawnPosition = mid + CPos.FromFlatAngle(angle, patrol.DistanceBetweenObjects); } else if (j < 19) { var angle = Angle.ToArc(30 * (j - 6)); spawnPosition = mid + CPos.FromFlatAngle(angle, 2 * patrol.DistanceBetweenObjects); } if (spawnPosition.X < map.TopLeftCorner.X + patrol.DistanceBetweenObjects / 2) { spawnPosition = new CPos(map.TopLeftCorner.X + patrol.DistanceBetweenObjects / 2, spawnPosition.Y, 0); } else if (spawnPosition.X >= map.BottomRightCorner.X - patrol.DistanceBetweenObjects / 2) { spawnPosition = new CPos(map.BottomRightCorner.X - patrol.DistanceBetweenObjects / 2, spawnPosition.Y, 0); } if (spawnPosition.Y < map.TopLeftCorner.Y + patrol.DistanceBetweenObjects / 2) { spawnPosition = new CPos(spawnPosition.X, map.TopLeftCorner.Y + patrol.DistanceBetweenObjects / 2, 0); } else if (spawnPosition.Y >= map.BottomRightCorner.Y - patrol.DistanceBetweenObjects / 2) { spawnPosition = new CPos(spawnPosition.X, map.BottomRightCorner.Y - patrol.DistanceBetweenObjects / 2, 0); } var actor = ActorCache.Create(world, patrol.ActorTypes[j], spawnPosition, patrol.Team, true); group.Add(actor); world.Add(actor); actors.Add(actor); } var groupPatrol = new Patrol(group); foreach (var actor in group) { if (actor.Bot != null) { actor.Bot.Patrol = groupPatrol; } } } return(actors); }
public override void Tick() { if (Disposed || World.Game.Editor) { return; } if (buildupduration-- == 0) { useTexture(projectile.Beam); } if (duration == 0 && projectile.BeamCooldown != null) { useTexture(projectile.BeamCooldown); } if (curTick-- < 0) { if (frame++ >= renderables.Length - 1) { frame = 0; } curTick = tick; } setPosition(); rayPhysics.Target = TargetPosition; rayPhysics.TargetHeight = TargetHeight; rayPhysics.CalculateEnd(new[] { Origin.Physics }); Position = rayPhysics.End; Height = rayPhysics.EndHeight; var dist = (originPos - Position).SquaredFlatDist; if (dist > (Type.MaxRange * RangeModifier) * (Type.MaxRange * RangeModifier)) { Position = clampToMaxRange(originPos, (originPos - TargetPosition).FlatAngle); Height = 0; } if (projectile.Directed && dist > (originPos - TargetPosition).SquaredFlatDist) { Position = TargetPosition; Height = 0; } var distance = originPos - Position; sound?.SetPosition(Position + distance / new CPos(2, 2, 1)); if (duration > 0 && buildupduration <= 0) { if (projectile.BeamParticles != null && duration % projectile.BeamParticleTick == 0) { var angle = distance.FlatAngle; var fit = distance.FlatDist / projectile.BeamParticleDistance; var heightdiff = (originHeight - Height) / projectile.BeamParticleDistance; var offset = CPos.FromFlatAngle(angle, projectile.BeamParticleDistance); for (int i = 0; i < fit; i++) { World.Add(projectile.BeamParticles.Create(World, originPos + new CPos(offset.X * i, offset.Y * i, 0), originHeight + heightdiff * i)); } } if (impactInterval-- <= 0) { Detonate(new Target(Position, Height), false); impactInterval = projectile.ImpactInterval; } } if (buildupduration < 0 && duration-- < 0 && endduration-- < 0) { Dispose(); } }