void TestPlot02(PointD startPos, double angle, double drift, double timeDegradeModifier, double hardness) { string fnId = FnId(clsName, "TestPlot02"); double calcAngle = 0; double driftFactor = 0; pathList.RemoveRange(0, pathList.Count); PointD tmp = new PointD(); tmp.Set(startPos); // for testing, i can represent time, ex 0 sec, 1 sec ... driftFactor = (angle - drift); driftFactor *= hardness; for (int i = 0; i < points; i++) { calcAngle = (angle - (driftFactor * i)); tmp.X = tmp.X + distance * Math.Cos(calcAngle); tmp.Y = tmp.Y + distance * Math.Sin(calcAngle); pathList.Add(new PointD(tmp.X, tmp.Y)); DbgFuncs.AddStr($"{fnId} calcAngle: {calcAngle}"); } }
private void DrawToBuffer() { backbuffer = new Bitmap(width, height); Graphics g = Graphics.FromImage(backbuffer); SolidBrush sb = new SolidBrush(Color.CornflowerBlue); g.FillRectangle(sb, 0, 0, width, height); DrawBlockList(g); if (ball != null) { ball.Draw(g); } if (ball2 != null) { ball2.Draw(g); } if (ball4 != null) { ball4.Draw(g); } DrawCollisionPointList(g); DbgFuncs.DrawDbgStrList(g); sb.Dispose(); g.Dispose(); }
public void DbgTxt() { string fnId = $"[{clsName}.DbgTxt]"; DbgFuncs.AddStr($"{fnId} elapsed: {elapsed}"); DbgFuncs.AddStr($"{fnId} lastFrameTime: {lastFrameTime}"); }
public void DbgText() { string fnId = $"[{clsName}.DbgText]"; DbgFuncs.AddStr($"{fnId} angle: {angle} ({(angle * 180 / Math.PI):N3})"); DbgFuncs.AddStr($"{fnId} drift: {drift} ({(drift * 180 / Math.PI):N3})"); DbgFuncs.AddStr($"{fnId} driftHardness: {driftHardness}"); DbgFuncs.AddStr($"{fnId} driftFactor: {driftFactor} ({(driftFactor * 180 / Math.PI):N3})"); }
protected override void _Update(double x, double y, double radius, double rotation) { base._Update(x, y, radius, rotation); UpdateCollisionPointList(x, y, radius, rotation); if (DrawDbgTxt) { DbgFuncs.AddStr($"[{clsName}._Update]: middleCpidx: {middleCpidx}"); DbgFuncs.AddStr($"[{clsName}._Update]: spaceBetween: {spaceBetween * 180 / Math.PI}"); DbgFuncs.AddStr($"[{clsName}._Update]: firstCpAngle: {firstCpAngle * 180 / Math.PI}"); DbgFuncs.AddStr($"[{clsName}._Update]: cpBoxSize: {cpBoxSize}"); } }
public void DbgPrint() { string fnId = FnId(clsName, "DbgPrint"); for (int i = 0; i < trackedKeys.Count; i++) { DbgFuncs.AddStr($"{fnId} {trackedKeys[i].Key}({trackedKeys[i].Value})"); DbgFuncs.AddStr($"{fnId} state/lastState: {trackedKeys[i].State}/{trackedKeys[i].LastState}"); DbgFuncs.AddStr($"{fnId} action/lastAction: {trackedKeys[i].Action}/{trackedKeys[i].LastAction}"); DbgFuncs.AddStr($"{fnId} EventThisFrame: {trackedKeys[i].EventThisFrame}"); DbgFuncs.AddStr($"{fnId} DefaultState: {trackedKeys[i].DefaultState}"); } }
public void Update(double adjustRotation = 0) { if (adjustRotation != 0) { rot += adjustRotation; rot = rot % (2 * Math.PI); if (rot < 0) { angleDegrees = (2 * Math.PI) + rot; } SetEndPoint(); } DbgFuncs.AddStr($"CollisionLine.rot(deg): {(angleDegrees * 180 / Math.PI):N2}"); }
// TODO: rework CalculatedAngle so that ball does not go in circle if adjusted over 0/360 line. see either TestPlot2d5 or TestPlot03 or TestPlot03_GOOD_PROGRESS ///----- CalculatedAngle ----- public double CalculatedAngle(double currentAngle, double elapsedTime = 0) { bool dbgtxt = false; string fnId = FnId(clsName, "CalculatedAngle"); double tmpAngle = 0; if (dbgtxt) { dbgPrintAngle(fnId, "currentAngle", currentAngle); } angle = aimTraj.Rotation; drift = spinTraj.Rotation; tmpAngle = angle - (driftFactor * elapsedTime); if (dbgtxt) { dbgPrintAngle(fnId, "angle", angle); } if (dbgtxt) { dbgPrintAngle(fnId, "drift", drift); } if (dbgtxt) { dbgPrintAngle(fnId, "tmpAngle", tmpAngle); } if (dbgtxt) { dbgPrintAngle(fnId, "driftFactor", driftFactor); } if (dbgtxt) { DbgFuncs.AddStr($"{fnId} elapsedTime: {elapsedTime}"); } return(tmpAngle); }
//void Bounce3() //{ // string fnId = $"[GameBall.Bounce]"; // bounceCount++; // //cpHitIdx = circ2.CollisionPointHit(); // //cpHitIdx = circ2.CollisionPointHit2(); // //fpAngle = (320 * Math.PI / 180); // timesIn90 = (int)(fpAngle / south); // toPrev90 = fpAngle - (timesIn90 * south); // toNext90 = ((timesIn90 + 1) * south) - fpAngle; // bounceAngle = 0; // angleAfterBounce = 0; // if (fpAngle > east && fpAngle < south) // { // if (cpHitIdx < circ2.MiddleCPIdx) // { // bounceAngle = toPrev90 * 2; // angleAfterBounce = (fpAngle + bounceAngle) % fullCircle; // } // if (cpHitIdx > circ2.MiddleCPIdx) // { // bounceAngle = toPrev90 * 2; // angleAfterBounce = (fpAngle - bounceAngle) % fullCircle; // } // } // if (fpAngle > south && fpAngle < west) // { // if (cpHitIdx < circ2.MiddleCPIdx) // { // bounceAngle = toNext90 * 2; // angleAfterBounce = (fpAngle + bounceAngle) % fullCircle; // } // if (cpHitIdx > circ2.MiddleCPIdx) // { // bounceAngle = toPrev90 * 2; // angleAfterBounce = (fpAngle - bounceAngle) % fullCircle; // } // } // if (fpAngle > west && fpAngle < north) // { // if (cpHitIdx < circ2.MiddleCPIdx) // { // bounceAngle = toNext90 * 2; // angleAfterBounce = (fpAngle + bounceAngle) % fullCircle; // } // if (cpHitIdx > circ2.MiddleCPIdx) // { // bounceAngle = (toPrev90 * 2); // angleAfterBounce = (fpAngle - bounceAngle) % fullCircle; // } // } // if (fpAngle > north && fpAngle < fullCircle) // { // if (cpHitIdx < circ2.MiddleCPIdx) // { // bounceAngle = toNext90 * 2; // angleAfterBounce = (fpAngle + bounceAngle) % fullCircle; // } // if (cpHitIdx > circ2.MiddleCPIdx) // { // bounceAngle = toPrev90 * 2; // angleAfterBounce = (fpAngle - bounceAngle) % fullCircle; // } // } // //DbgFuncs.AddStr($"{fnId} fpAngle: {fpAngle:N3} ({(fpAngle * 180 / Math.PI):N2})"); // //DbgFuncs.AddStr($"timeIn90: {timesIn90}"); // //DbgFuncs.AddStr($"{fnId} toNext90: {toNext90:N3} ({(toNext90 * 180 / Math.PI):N2})"); // //DbgFuncs.AddStr($"{fnId} toPrev90: {toPrev90:N3} ({(toPrev90 * 180 / Math.PI):N2})"); // //DbgFuncs.AddStr($"{fnId} bounceAngle: {bounceAngle:N3} ({(bounceAngle * 180 / Math.PI):N2})"); // //DbgFuncs.AddStr($"{fnId} angleAfterBounce: {angleAfterBounce:N3} ({(angleAfterBounce * 180 / Math.PI):N2})"); // fpAngle = angleAfterBounce; //} #endregion Bounce 3 versions void AddUpdateDebugMsgs() { string fnId = $"[{clsName}.AddUpdateDebugMsgs]"; if (DrawDbgTxt) { //DbgFuncs.AddStr($"game window size: {{ {gameScreenSize.Width}, {gameScreenSize.Height} }}"); DbgFuncs.AddStr($"{fnId} ballLaunched: {ballLaunched}"); DbgFuncs.AddStr($"{fnId} angle(degrees) from flightpath: {(fpAngle * 180 / Math.PI):N2}"); DbgFuncs.AddStr($"{fnId} drift(degrees) from flightpath: {fpDrift * 180 / Math.PI:N2}"); DbgFuncs.AddStr($"{fnId} driftFactor(degrees): {driftFactor * 180 / Math.PI:N2}"); DbgFuncs.AddStr($"{fnId} speed(of ball): {speed:N2}"); DbgFuncs.AddStr($"{fnId} angle(of ball degrees): {(calculatedAngle * 180 / Math.PI):N2}"); DbgFuncs.AddStr($"{fnId} flightTime: {flightTime.ToString(@"mm\:ss\:fff")}"); DbgFuncs.AddStr($"{fnId} ydriftModifier: {timedriftModifier:N2}"); DbgFuncs.AddStr($"{fnId} secondsRemaining: {(secondsRemaining):N3}"); //DbgFuncs.AddStr($"east: {east:N3} ({(east * 180 / Math.PI)})"); //DbgFuncs.AddStr($"south: {south:N3} ({(south * 180 / Math.PI)})"); //DbgFuncs.AddStr($"west: {west:N3} ({(west * 180 / Math.PI)})"); //DbgFuncs.AddStr($"north: {north:N3} ({(north * 180 / Math.PI)})"); } }
public void Update() { string fnId = $"[{clsName}.Update]: "; if (!ballLaunched) { fpAngle = flightPath.Angle; fpDrift = flightPath.Drift; driftFactor = (fpAngle - fpDrift) * drifthardness; calculatedAngle = fpAngle - (driftFactor * timedriftModifier); } //AddUpdateDebugMsgs(); if (ballLaunched && !pause) { flightTime = DateTime.Now - startTime; totalMs = flightTime.TotalMilliseconds; secondsElapsed = flightTime.TotalSeconds; secondsRemaining = roundTime - secondsElapsed; timedriftModifier = totalMs / 250; // bounce logic if (collided) { cpHitIdx = circ2.CollisionPointHit2(); cpIdxHitList = circ2.TriggeredHitPointIdxList(); SetInfoCpIdxHit(cpIdxHitList); if (cpIdxHitList.Count > 0) { Bounce3(cpHitIdx); } //if (cpHitIdx > -1) //{ // Bounce3(cpHitIdx); //} collided = false; } // starts looping if angle gets too high calculatedAngle = fpAngle - (driftFactor * timedriftModifier); dx = dx + speed * Math.Cos(calculatedAngle); dy = dy + speed * Math.Sin(calculatedAngle); // commented out for testing. commenting this out should prevent reset based of time //if (secondsRemaining <= 0) { secondsRemaining = 0; Reset(); } if (dy <= 0 || dy >= gameScreenSize.Height) { Reset(); } if (dx <= 0 || dx >= gameScreenSize.Width) { Reset(); } } if (DrawDbgTxt) { DbgFuncs.AddStr($"{fnId} collisionPointHit (index): {cpHitIdx}"); DbgFuncs.AddStr($"{fnId} outerAngle: {(outerAngle * 180 / Math.PI):N2}"); DbgFuncs.AddStr($"{fnId} calculatedBouneAngle: {(calculatedBounceAngle * 180 / Math.PI):N2}"); DbgFuncs.AddStr($"{fnId} middle cp hit idx: {circ2.MiddleCPIdx}"); } circ2.Update(dx, dy, width / 2, calculatedAngle); #region testing logic for bounce if (DrawDbgTxt) { DbgFuncs.AddStr($"{fnId} fpAngle: {fpAngle:N3} ({(fpAngle * 180 / Math.PI):N2})"); DbgFuncs.AddStr($"timeIn90: {timesIn90}"); DbgFuncs.AddStr($"{fnId} toNext90: {toNext90:N3} ({(toNext90 * 180 / Math.PI):N2})"); DbgFuncs.AddStr($"{fnId} toPrev90: {toPrev90:N3} ({(toPrev90 * 180 / Math.PI):N2})"); DbgFuncs.AddStr($"{fnId} bounceAngle: {bounceAngle:N3} ({(bounceAngle * 180 / Math.PI):N2})"); DbgFuncs.AddStr($"{fnId} angleAfterBounce: {angleAfterBounce:N3} ({(angleAfterBounce * 180 / Math.PI):N2})"); DbgFuncs.AddStr($"{fnId} dbgInfoCpIdxHit: {dbgtxtCpIdxHit}"); } #endregion testing logic for bounce }
public void Update(MouseControls mc, List <CollisionPoint> blockCpList) { bool dbgtxt = true; string fnId = FnId(clsName, "Update"); HandleMouseInput(mc); if (dbgtxt) { DbgFuncs.AddStr($"{fnId} launched: {launched}"); } if (!launched) { if (adjustingPosition) { position.Set(mousePos); startPosition.Set(mousePos); } if (adjustingAim) { aimTraj.SetEndPoint(mousePos); } if (adjustingSpin) { spinTraj.SetEndPoint(mousePos); } SetInitialTrajectory(); CalculateDriftFactor(aimTraj.Rotation, spinTraj.Rotation); CalculateInitialDriftPerSecond(); } CheckForBlockCollision(blockCpList); ApplyDriftPerSecond(gtimer.TotalSeconds); if (launched) { gtimer.Update(); // 2020-01-01 Going to try applying bounce logic here. Collision is determined in the previous frame currently. CalculateBounceAngle(); rotation += bounceAngle; position.X = position.X + speed * Math.Cos(rotation); position.Y = position.Y + speed * Math.Sin(rotation); if (bounceAngle != 0) { lastBounceAngle = bounceAngle; bounceAngle = 0; } } MoveCollisionPoints(position.X, position.Y, radius, rotation); if (dbgtxt && DrawDbgTxt) { //gtimer.DbgTxt(); dbgPrintAngle(fnId, "driftFactor", driftFactor); dbgPrintAngle(fnId, "rotation", rotation); dbgPrintAngle(fnId, "initialDriftPerSecond", initialDriftPerSecond); DbgFuncs.AddStr($"{fnId} gtimer.TotalSeconds: {gtimer.TotalSeconds}"); DbgFuncs.AddStr($"{fnId} ~~~~ CHECK FOR BOUNCE DBG LOGIC ~~~"); DbgFuncs.AddStr($"{fnId} shouldBounce: {shouldBounce}"); DbgFuncs.AddStr($"{fnId} firstPointHit (index): {firstPointHit}"); dbgPrintAngle(fnId, "bounceAngle", bounceAngle); dbgPrintAngle(fnId, "lastBounceAngle", lastBounceAngle); dbgPrintAngle(fnId, "testBounceAngle", testBounceAngle); DbgFuncs.AddStr($"{fnId} hz: {hz}"); //if (firstPointHit > -1) { launched = aimTraj.Visible = spinTraj.Visible = false; } // For testing, stopping ball and hiding aim and spin markers } if (firstPointHit > -1) { launched = aimTraj.Visible = spinTraj.Visible = false; } // For testing, stopping ball and hiding aim and spin markers }
void HandleMouseInput(MouseControls mc) { bool dbgtxt = true; string fnId = $"[{clsName}.HandleMouseInput]"; if (dbgtxt) { DbgFuncs.AddStr($"{fnId} mc.LeftButtonState: {mc.LeftButtonState}"); } if (dbgtxt) { DbgFuncs.AddStr($"{fnId} mc.LastLeftButtonState: {mc.LastLeftButtonState}"); } mousePos.Set(mc.X, mc.Y); // Reset game screen if (mc.RightButtonState == UpDownState.Down && mc.LastRightButtonState == UpDownState.Up) { Reset(); return; } // Prevents aim and spin boxes from continuing to drag if mouse is not down if (mc.LeftButtonState == UpDownState.Up && mc.LastLeftButtonState == UpDownState.Up && (adjustingAim || adjustingSpin || adjustingPosition)) { adjustingAim = adjustingSpin = adjustingPosition = false; return; } // Setting up the shot if (!launched) { // Building logic to move ball before the aim marker is placed (aimTraj.Placed) if (mc.LeftButtonState == UpDownState.Down && mc.LastLeftButtonState == UpDownState.Up && !aimTraj.Placed && InCircle(mc.Position.X, mc.Position.Y)) { adjustingPosition = true; return; } // Place aim marker if (!aimTraj.Placed && mc.LeftButtonState == UpDownState.Down && mc.LastLeftButtonState == UpDownState.Up) { aimTraj.SetStartPoint(position); aimTraj.SetEndPoint(mc.Position); spinTraj.SetStartPoint(position); PointD spinStartPos = new PointD(); spinStartPos = position.HalfWayTo(mc.Position.X, mc.Position.Y); spinTraj.SetEndPoint(spinStartPos); return; } // Adjust aim or spin if (aimTraj.Placed && (!adjustingAim || !adjustingSpin) && mc.LeftButtonState == UpDownState.Down && mc.LastLeftButtonState == UpDownState.Up) { if (aimTraj.InEndRect(mc.X, mc.Y)) { adjustingAim = true; return; } if (spinTraj.InEndRect(mc.X, mc.Y)) { adjustingSpin = true; return; } } // Stop adjusting aim or spin if ((adjustingAim || adjustingSpin) && mc.LeftButtonState == UpDownState.Up && mc.LastLeftButtonState == UpDownState.Down) { adjustingAim = adjustingSpin = false; return; } // Launch the ball and start the timer (when launch button is clicked) if ((!adjustingAim && !adjustingSpin) && mc.LastLeftButtonState == UpDownState.Up && mc.LeftButtonState == UpDownState.Down //&& InLaunchButtonRect(mc.X, mc.Y) && btnLaunch.InBoundingRect(mc.X, mc.Y)) { launched = true; gtimer.Start(); } } }