From 0de9385a69cc3ff565fa81c790c91f6694642f3a Mon Sep 17 00:00:00 2001 From: Kyle <41976328+ImKyle4815@users.noreply.github.com> Date: Fri, 16 Aug 2019 13:43:33 -0700 Subject: [PATCH] Update life.js --- data/life/life.js | 72 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 70 insertions(+), 2 deletions(-) diff --git a/data/life/life.js b/data/life/life.js index 690cf982..2b2a7218 100644 --- a/data/life/life.js +++ b/data/life/life.js @@ -314,7 +314,8 @@ window.addEventListener("mousemove", updateMouseCoordinates, true) window.addEventListener("mouseup", endMouseCoordinates, true) function startMouseCoordinates() { clicking = true - singleClick() + // singleClick() + singleTap() } function updateMouseCoordinates() { touchX[0] = event.clientX @@ -362,6 +363,73 @@ function endTouch() { clearTimers() } } + + + + + + + + +function singleTap() { + var playerBoxBounds = event.target.getBoundingClientRect() + var tappedPlayerBox = playerList[event.target.customVarID - 1] + var lifeAdjust = 0 + if (tappedPlayerBox.rotation == 0 || tappedPlayerBox.rotation == 180) { + if (touchX[touchX.length - 1] > playerBoxBounds.width / 2 + playerBoxBounds.x) { + lifeAdjust = 1 + } else { + lifeAdjust = -1 + } + } else { + if (touchY[touchY.length - 1] > playerBoxBounds.height / 2 + playerBoxBounds.y) { + lifeAdjust = 1 + } else { + lifeAdjust = -1 + } + } + if (tappedPlayerBox.rotation == 180 || tappedPlayerBox.rotation == 270) { + lifeAdjust *= -1 + } + direction = lifeAdjust + "" + tappedPlayerBox.life += lifeAdjust + drawPlayerBox(tappedPlayerBox.id) +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + function singleClick() { @@ -480,4 +548,4 @@ function heldDown() { loop = setTimeout(heldDown, 100) } } -//Updated \ No newline at end of file +//Updated for real \ No newline at end of file