//also do this for rectangle beams (use three of them) public static bool IsInMovingCircle(Loc loc, Loc origin1, Loc origin2, int radius) { if (origin1 == origin2) { return(IsInCircleSquareHitbox(loc, origin1, radius, radius, AreaLimit.Full, Dir8.Down)); } //vector from origin1 to origin2 Loc va = origin2 - origin1; //vector from first origin to test point Loc ab = loc - origin1; //get closest point on the line int a = Loc.Dot(va, ab); //check collision depending on where the point is projected on the line segment if (a < 0) { return(ab.DistSquared() <= radius); //check first origin collision } else if (a > Loc.Dot(va, va)) { return((loc - origin2).DistSquared() <= radius); //check last origin collision } else { //right-angle vector Loc ortho = new Loc(-va.Y, va.X); int dist = Loc.Dot(ortho, ab); return(dist <= radius && dist >= -radius); } }
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) { base.Update(scene, elapsedTime); //a=EndLoc - StartLoc //b=(-a.y, a.x)/||a||*r*||a|| //b=(-a.y, a.x)*r //Va=t*a //Vb=4*b*t*(1-t) FrameTick midTime = ActionTime; Loc majorVector = EndLoc - StartLoc; Loc minorVector = new Loc(-majorVector.Y, majorVector.X); Loc majorDiff = majorVector * ActionTime.ToFrames() / MovingTime; double div = Math.Sqrt(majorDiff.DistSquared()); Loc minorDiff = 4 * minorVector * ActionTime.ToFrames() * (MovingTime - ActionTime.ToFrames()) / MovingTime / MovingTime; mapLoc = StartLoc + majorDiff + new Loc((int)(minorDiff.X * AxisRatio), (int)(minorDiff.Y * AxisRatio)); }