public override void Update(FrameTick elapsedTime) { Loc movediff = Destination - CurPos; int movelen = movediff.Length(); //Get the difference between the current position and destination double x = movediff.X / Math.Sqrt(movediff.DistSquared()); double y = movediff.Y / Math.Sqrt(movediff.DistSquared()); //Ignore translation on a given axis if its already at the correct position on that axis. // Mainly because we're rounding the values to the nearest integer, and might overshoot otherwise. if (movediff.X == 0) { x = 0; } if (movediff.Y == 0) { y = 0; } //Convert the floating point number to the biggest nearby integer value, and keep its sign Loc movevec = new Loc(); movevec.X = (int)(Math.Ceiling(Math.Abs(x)) * Math.Sign(x)); movevec.Y = (int)(Math.Ceiling(Math.Abs(y)) * Math.Sign(y)); Loc checkedmove = new Loc(); //Constrain the move vector components to the components of the position difference vector to // ensure we don't overshoot because of the move rate checkedmove.X = Math.Min(Math.Abs(movediff.X), Math.Abs(movevec.X * moveRate)) * Math.Sign(movevec.X); checkedmove.Y = Math.Min(Math.Abs(movediff.Y), Math.Abs(movevec.Y * moveRate)) * Math.Sign(movevec.Y); //Update facing direction. Ignore none, since it crashes the game. Dir8 newdir = movevec.ApproximateDir8(); if (newdir != Dir8.None) { CharDir = newdir; } Move = checkedmove; CurPos += Move; //Increment our internal current position, since we have no ways of knowing where we are otherwise.. }
public override void Update(BaseScene scene, FrameTick elapsedTime) { CurrentBurstTime += elapsedTime; while (CurrentBurstTime >= Math.Max(1, BurstTime)) { CurrentBurstTime -= Math.Max(1, BurstTime); for (int ii = 0; ii < ParticlesPerBurst; ii++) { List <int> openDirs = getOpenDirs(); int openIndex = openDirs[MathUtils.Rand.Next(openDirs.Count)]; Coverages[openIndex] = true; double angle = (openIndex + MathUtils.Rand.NextDouble()) * Math.PI / 4; int dist = Math.Min(Range, MathUtils.Rand.Next(StartDistance + 1)); Loc startDelta = new Loc((int)Math.Round(Math.Cos(angle) * dist), (int)Math.Round(Math.Sin(angle) * dist)); if (AreaLimit == Dungeon.Hitbox.AreaLimit.Cone) { angle = (45 * (int)Dir + 45) * Math.PI / 180 + angle / 4; } else if (AreaLimit == Dungeon.Hitbox.AreaLimit.Sides) { if (Dir.IsDiagonal()) { //either +135 or -135 from the direction if (MathUtils.Rand.Next(2) == 0) { angle = (45 * (int)Dir + 90 + 135) * Math.PI / 180; } else { angle = (45 * (int)Dir + 90 - 135) * Math.PI / 180; } } else { //either +90 or -90 from the direction if (MathUtils.Rand.Next(2) == 0) { angle = (45 * (int)Dir + 90 + 90) * Math.PI / 180; } else { angle = (45 * (int)Dir + 90 - 90) * Math.PI / 180; } } } Loc particleSpeed = new Loc((int)(Math.Cos(angle) * Speed), (int)(Math.Sin(angle) * Speed)); if (Anims.Count > 0) { //pixels int resultRange = MathUtils.Rand.Next(dist, Range + RangeDiff) + 1; int totalTime = resultRange - dist; if (Speed > 0) { totalTime *= GraphicsManager.MAX_FPS; totalTime /= Speed; } float maxHeight = HeightRatio * resultRange; float velocity = 4 * maxHeight * GraphicsManager.MAX_FPS / totalTime; float acceleration = -8 * maxHeight * GraphicsManager.MAX_FPS * GraphicsManager.MAX_FPS / totalTime / totalTime; IParticleEmittable chosenAnim = Anims[MathUtils.Rand.Next(Anims.Count)]; scene.Anims[(int)Layer].Add(chosenAnim.CreateParticle(totalTime, Origin + startDelta, particleSpeed, Loc.Zero, 0, (int)Math.Round(velocity), (int)Math.Round(acceleration), particleSpeed.ApproximateDir8())); } } CurrentBursts++; if (CurrentBursts >= Bursts) { break; } } }
public override void Update(BaseScene scene, FrameTick elapsedTime) { CurrentBurstTime += elapsedTime; while (CurrentBurstTime >= Math.Max(1, BurstTime)) { CurrentBurstTime -= Math.Max(1, BurstTime); for (int ii = 0; ii < ParticlesPerBurst; ii++) { if (Anims.Count > 0) { List <int> openDirs = getOpenDirs(); int openIndex = openDirs[MathUtils.Rand.Next(openDirs.Count)]; Coverages[openIndex] = true; double angle = (openIndex + MathUtils.Rand.NextDouble()) * Math.PI / 4; int dist = StartDistance + MathUtils.Rand.Next(StartVariance + 1); Loc startDelta = new Loc((int)Math.Round(Math.Cos(angle) * dist), (int)Math.Round(Math.Sin(angle) * dist)); double endAngle = MathUtils.Rand.NextDouble() * Math.PI * 2; int endDist = MathUtils.Rand.Next(EndDistance + 1); Loc endDelta = new Loc((int)Math.Round(Math.Cos(endAngle) * endDist), (int)Math.Round(Math.Sin(endAngle) * endDist)); Loc particleSpeed = ((UseDest ? Destination : Origin) + endDelta - (Origin + startDelta)) * GraphicsManager.MAX_FPS / TravelTime; Loc startLoc = Origin + startDelta; { AnimData animData = Anims[MathUtils.Rand.Next(Anims.Count)]; AnimData scaledAnim = new AnimData(animData); DirSheet fxSheet = GraphicsManager.GetAttackSheet(animData.AnimIndex); scaledAnim.FrameTime = (int)Math.Ceiling((float)TravelTime / scaledAnim.GetTotalFrames(fxSheet.TotalFrames) / Math.Max(1, Cycles)); ParticleAnim anim = new ParticleAnim(scaledAnim, 0, TravelTime); anim.SetupEmitted(startLoc, particleSpeed, Loc.Zero, 0, 0, 0, particleSpeed.ApproximateDir8()); scene.Anims[(int)Layer].Add(anim); } } } CurrentBursts++; if (CurrentBursts >= Math.Max(1, Bursts)) { break; } } }
protected override void ReleaseAnim(BaseScene scene, int dist, Loc startLoc, Loc speed) { int totalTime = Range - dist; if (Speed > 0) { totalTime *= GraphicsManager.MAX_FPS; totalTime /= Speed; } IParticleEmittable chosenAnim = Anims[MathUtils.Rand.Next(Anims.Count)]; scene.Anims[(int)Layer].Add(chosenAnim.CreateParticle(totalTime, startLoc, speed, Loc.Zero, LocHeight, 0, 0, speed.ApproximateDir8())); }
protected virtual void ReleaseAnim(BaseScene scene, int dist, Loc startLoc, Loc speed) { IParticleEmittable chosenAnim = Anims[MathUtils.Rand.Next(Anims.Count)]; scene.Anims[(int)Layer].Add(chosenAnim.CreateParticle(startLoc, speed, Loc.Zero, LocHeight, 0, 0, speed.ApproximateDir8())); }