From 20501a0253b4b5bd346f61c28e396d5eab7a2c85 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sat, 2 Dec 2023 09:58:36 -0500 Subject: experimental tracing changes --- app/assets/javascripts/trace2.js | 86 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 78 insertions(+), 8 deletions(-) (limited to 'app/assets') diff --git a/app/assets/javascripts/trace2.js b/app/assets/javascripts/trace2.js index 000e60b..20d050d 100644 --- a/app/assets/javascripts/trace2.js +++ b/app/assets/javascripts/trace2.js @@ -521,6 +521,8 @@ window.onTraceStart = function(puzzle, pos, svg, start, symStart=null) { data.sym = puzzle.getSymmetricalPos(pos.x, pos.y) data.puzzle = puzzle data.path = [] + data.x_momentum = 0 + data.y_momentum = 0 puzzle.startPoint = {'x': pos.x, 'y': pos.y} if (pos.x % 2 === 1) { // Start point is on a horizontal segment @@ -732,9 +734,9 @@ function push(dx, dy, dir, targetDir) { // Fraction of movement to redirect in the other direction var movementRatio = null if (targetDir === 'left' || targetDir === 'top') { - movementRatio = -3 + movementRatio = -1 } else if (targetDir === 'right' || targetDir === 'bottom') { - movementRatio = 3 + movementRatio = 1 } if (window.settings.disablePushing === true) movementRatio *= 1000 @@ -779,6 +781,43 @@ function push(dx, dy, dir, targetDir) { // Redirect momentum from pushing against walls, so that all further moment steps // will be strictly linear. Returns a string for logging purposes only. function pushCursor(dx, dy) { + //if (Math.abs(dx) > Math.abs(dy)) { + // //data.y_momentum = 0 + // if (dx > 0) { + // data.x_momentum = 1 + // } else { + // data.x_momentum = -1 + // } + //} else { + // //data.x_momentum = 0 + // if (dy > 0) { + // data.y_momentum = 1 + // } else { + // data.y_momentum = -1 + // } + //} + var minimumMove = 0 + if (Math.abs(dx) > minimumMove) { + //data.y_momentum = 0 + if (dx > 0) { + data.x_momentum = 1 + } else { + data.x_momentum = -1 + } + } else if (Math.abs(dx) <= 1) { + data.x_momentum = 0 + } + if (Math.abs(dy) > minimumMove) { + //data.x_momentum = 0 + if (dy > 0) { + data.y_momentum = 1 + } else { + data.y_momentum = -1 + } + } else if (Math.abs(dy) <= 1) { + data.y_momentum = 0 + } + // Outer wall collision var cell = data.puzzle.getCell(data.pos.x, data.pos.y) if (cell == null) return 'nothing' @@ -787,29 +826,45 @@ function pushCursor(dx, dy) { if ([undefined, 'top', 'bottom'].includes(cell.end)) { var leftCell = data.puzzle.getCell(data.pos.x - 1, data.pos.y) if (leftCell == null || leftCell.gap === window.GAP_FULL) { - if (push(dx, dy, 'left', 'top')) return 'left outer wall' + if (data.y_momentum > 0) { + if (push(dx, dy, 'left', 'bottom')) return 'left outer wall, down' + } else { + if (push(dx, dy, 'left', 'top')) return 'left outer wall' + } } var rightCell = data.puzzle.getCell(data.pos.x + 1, data.pos.y) if (rightCell == null || rightCell.gap === window.GAP_FULL) { - if (push(dx, dy, 'right', 'top')) return 'right outer wall' + if (data.y_momentum > 0) { + if (push(dx, dy, 'right', 'bottom')) return 'right outer wall, down' + } else { + if (push(dx, dy, 'right', 'top')) return 'right outer wall' + } } } // Only consider non-endpoints or endpoints which are parallel if ([undefined, 'left', 'right'].includes(cell.end)) { var topCell = data.puzzle.getCell(data.pos.x, data.pos.y - 1) if (topCell == null || topCell.gap === window.GAP_FULL) { - if (push(dx, dy, 'top', 'right')) return 'top outer wall' + if (data.x_momentum < 0) { + if (push(dx, dy, 'top', 'left')) return 'top outer wall, left' + } else { + if (push(dx, dy, 'top', 'right')) return 'top outer wall' + } } var bottomCell = data.puzzle.getCell(data.pos.x, data.pos.y + 1) if (bottomCell == null || bottomCell.gap === window.GAP_FULL) { - if (push(dx, dy, 'bottom', 'right')) return 'bottom outer wall' + if (data.x_momentum < 0) { + if (push(dx, dy, 'bottom', 'left')) return 'bottom outer wall, left' + } else { + if (push(dx, dy, 'bottom', 'right')) return 'bottom outer wall' + } } } // Inner wall collision if (cell.end == null) { if (data.pos.x%2 === 1 && data.pos.y%2 === 0) { // Horizontal cell - if (data.x < data.bbox.middle.x) { + if (data.x_momentum < 0 || (data.x_momentum == 0 && data.x < data.bbox.middle.x)) { push(dx, dy, 'topbottom', 'left') return 'topbottom inner wall, moved left' } else { @@ -817,7 +872,7 @@ function pushCursor(dx, dy) { return 'topbottom inner wall, moved right' } } else if (data.pos.x%2 === 0 && data.pos.y%2 === 1) { // Vertical cell - if (data.y < data.bbox.middle.y) { + if (data.y_momentum < 0 || (data.y_momentum == 0 && data.y < data.bbox.middle.y)) { push(dx, dy, 'leftright', 'top') return 'leftright inner wall, moved up' } else { @@ -832,6 +887,7 @@ function pushCursor(dx, dy) { var turnMod = 2 if ((data.pos.x%2 === 0 && data.pos.y%2 === 0) || cell.end != null) { if (data.x < data.bbox.middle.x) { + //if (data.x_momentum < 0 || (data.x_momentum == 0 && data.x < data.bbox.middle.x)) { push(dx, dy, 'topbottom', 'right') // Overshot the intersection and appears to be trying to turn if (data.x > data.bbox.middle.x && Math.abs(dy) * turnMod > Math.abs(dx)) { @@ -841,6 +897,7 @@ function pushCursor(dx, dy) { } return 'intersection moving right' } else if (data.x > data.bbox.middle.x) { + //} else if (data.x_momentum > 0 || (data.x_momentum == 0 && data.x > data.bbox.middle.x)) { push(dx, dy, 'topbottom', 'left') // Overshot the intersection and appears to be trying to turn if (data.x < data.bbox.middle.x && Math.abs(dy) * turnMod > Math.abs(dx)) { @@ -851,6 +908,7 @@ function pushCursor(dx, dy) { return 'intersection moving left' } if (data.y < data.bbox.middle.y) { + //if (data.y_momentum < 0 || (data.y_momentum == 0 && data.y < data.bbox.middle.y)) { push(dx, dy, 'leftright', 'bottom') // Overshot the intersection and appears to be trying to turn if (data.y > data.bbox.middle.y && Math.abs(dx) * turnMod > Math.abs(dy)) { @@ -860,6 +918,7 @@ function pushCursor(dx, dy) { } return 'intersection moving down' } else if (data.y > data.bbox.middle.y) { + //} else if (data.y_momentum > 0 || (data.y_momentum == 0 && data.y > data.bbox.middle.y)) { push(dx, dy, 'leftright', 'top') // Overshot the intersection and appears to be trying to turn if (data.y < data.bbox.middle.y && Math.abs(dx) * turnMod > Math.abs(dy)) { @@ -923,6 +982,9 @@ function hardCollision() { } else if (lastDir === MOVE_BOTTOM) { data.y = Math.min(data.y, data.bbox.middle.y - gapSize) } + + data.x_momentum = 0 + data.y_momentum = 0 } // Check to see if we've gone beyond the edge of puzzle cell, and if the next cell is safe, @@ -947,6 +1009,8 @@ function move() { } } if (data.x < data.bbox.x1) { + //data.x_momentum = -1 + //data.y_momentum = 0 return MOVE_LEFT } } else if (data.x > data.bbox.x2 - 12) { // Moving right @@ -965,6 +1029,8 @@ function move() { } } if (data.x > data.bbox.x2) { + //data.x_momentum = 1 + //data.y_momentum = 0 return MOVE_RIGHT } } else if (data.y < data.bbox.y1 + 12) { // Moving up @@ -983,6 +1049,8 @@ function move() { } } if (data.y < data.bbox.y1) { + //data.x_momentum = 0 + //data.y_momentum = -1 return MOVE_TOP } } else if (data.y > data.bbox.y2 - 12) { // Moving down @@ -1001,6 +1069,8 @@ function move() { } } if (data.y > data.bbox.y2) { + //data.x_momentum = 0 + //data.y_momentum = 1 return MOVE_BOTTOM } } -- cgit 1.4.1