MCPcopy
hub / github.com/Vishal-raj-1/Awesome-JavaScript-Projects / tick

Function tick

assets/js/block_ninja.js:1511–1850  ·  view source on GitHub ↗
(width, height, simTime, simSpeed, lag)

Source from the content-addressed store, hash-verified

1509
1510
1511function tick(width, height, simTime, simSpeed, lag) {
1512 PERF_START('frame');
1513 PERF_START('tick');
1514
1515 state.game.time += simTime;
1516
1517 if (slowmoRemaining > 0) {
1518 slowmoRemaining -= simTime;
1519 if (slowmoRemaining < 0) {
1520 slowmoRemaining = 0;
1521 }
1522 targetSpeed = pointerIsDown ? 0.075 : 0.3;
1523 } else {
1524 const menuPointerDown = isMenuVisible() && pointerIsDown;
1525 targetSpeed = menuPointerDown ? 0.025 : 1;
1526 }
1527
1528 renderSlowmoStatus(slowmoRemaining / slowmoDuration);
1529
1530 gameSpeed += (targetSpeed - gameSpeed) / 22 * lag;
1531 gameSpeed = clamp(gameSpeed, 0, 1);
1532
1533 const centerX = width / 2;
1534 const centerY = height / 2;
1535
1536 const simAirDrag = 1 - (airDrag * simSpeed);
1537 const simAirDragSpark = 1 - (airDragSpark * simSpeed);
1538
1539 // Pointer Tracking
1540 // -------------------
1541
1542 // Compute speed and x/y deltas.
1543 // There is also a "scaled" variant taking game speed into account. This serves two purposes:
1544 // - Lag won't create large spikes in speed/deltas
1545 // - In slow mo, speed is increased proportionately to match "reality". Without this boost,
1546 // it feels like your actions are dampened in slow mo.
1547 const forceMultiplier = 1 / (simSpeed * 0.75 + 0.25);
1548 pointerDelta.x = 0;
1549 pointerDelta.y = 0;
1550 pointerDeltaScaled.x = 0;
1551 pointerDeltaScaled.y = 0;
1552 const lastPointer = touchPoints[touchPoints.length - 1];
1553
1554 if (pointerIsDown && lastPointer && !lastPointer.touchBreak) {
1555 pointerDelta.x = (pointerScene.x - lastPointer.x);
1556 pointerDelta.y = (pointerScene.y - lastPointer.y);
1557 pointerDeltaScaled.x = pointerDelta.x * forceMultiplier;
1558 pointerDeltaScaled.y = pointerDelta.y * forceMultiplier;
1559 }
1560 const pointerSpeed = Math.hypot(pointerDelta.x, pointerDelta.y);
1561 const pointerSpeedScaled = pointerSpeed * forceMultiplier;
1562
1563 // Track points for later calculations, including drawing trail.
1564 touchPoints.forEach(p => p.life -= simTime);
1565
1566 if (pointerIsDown) {
1567 touchPoints.push({
1568 x: pointerScene.x,

Callers 1

frameHandlerFunction · 0.85

Calls 15

PERF_STARTFunction · 0.85
isMenuVisibleFunction · 0.85
renderSlowmoStatusFunction · 0.85
getSpawnDelayFunction · 0.85
returnTargetFunction · 0.85
isInGameFunction · 0.85
isCasualGameFunction · 0.85
incrementScoreFunction · 0.85
incrementCubeCountFunction · 0.85
sparkBurstFunction · 0.85
glueShedSparksFunction · 0.85
updateTargetHealthFunction · 0.85

Tested by

no test coverage detected