mirror of
https://github.com/Investigamer/cardconjurer.git
synced 2025-07-27 13:21:41 -05:00
life
This commit is contained in:
@@ -82,7 +82,6 @@ function startGame() {
|
|||||||
}
|
}
|
||||||
drawAllPlayerBoxes()
|
drawAllPlayerBoxes()
|
||||||
}
|
}
|
||||||
|
|
||||||
function playerBox(playerBoxID, canvasRotation, wide) {
|
function playerBox(playerBoxID, canvasRotation, wide) {
|
||||||
//Actually needed vars
|
//Actually needed vars
|
||||||
this.id = playerBoxID
|
this.id = playerBoxID
|
||||||
@@ -184,85 +183,6 @@ document.getElementById("mainGrid").addEventListener("touchmove", function(event
|
|||||||
function rollRNG() {
|
function rollRNG() {
|
||||||
document.getElementById("rngOutput").innerHTML = Math.floor(Math.random() * (parseInt(document.getElementById("inputRNGMax").value) - parseInt(document.getElementById("inputRNGMin").value) + 1) + parseInt(document.getElementById("inputRNGMin").value))
|
document.getElementById("rngOutput").innerHTML = Math.floor(Math.random() * (parseInt(document.getElementById("inputRNGMax").value) - parseInt(document.getElementById("inputRNGMin").value) + 1) + parseInt(document.getElementById("inputRNGMin").value))
|
||||||
}
|
}
|
||||||
function updatePlayerBoxes() {
|
|
||||||
// alert("did I click?")
|
|
||||||
if (clicking) {
|
|
||||||
// alert("yes I did!")
|
|
||||||
//Make a list of the touch locations
|
|
||||||
for (var i = 0; i < touchX.length; i++) {
|
|
||||||
for (var n = 1; n <= playerList.length; n ++) {
|
|
||||||
var playerBoxBounds = playerList[n - 1].canvas.getBoundingClientRect()
|
|
||||||
if (touchX[i] >= playerBoxBounds.left && touchX[i] <= playerBoxBounds.right && touchY[i] >= playerBoxBounds.top && touchY[i] <= playerBoxBounds.bottom) {
|
|
||||||
//This canvas is being clicked on! Do something about it.
|
|
||||||
var direction = "", lifeAdjust = 0
|
|
||||||
if (playerList[n - 1].rotation == 0) {
|
|
||||||
if (touchX[i] > playerBoxBounds.width / 2 + playerBoxBounds.x) {
|
|
||||||
direction = "up"
|
|
||||||
lifeAdjust = 1
|
|
||||||
} else {
|
|
||||||
direction = "down"
|
|
||||||
lifeAdjust = -1
|
|
||||||
}
|
|
||||||
} else if (playerList[n - 1].rotation == 90) {
|
|
||||||
if (touchY[i] > playerBoxBounds.height / 2 + playerBoxBounds.y) {
|
|
||||||
direction = "up"
|
|
||||||
lifeAdjust = 1
|
|
||||||
} else {
|
|
||||||
direction = "down"
|
|
||||||
lifeAdjust = -1
|
|
||||||
}
|
|
||||||
} else if (playerList[n - 1].rotation == 180) {
|
|
||||||
if (touchX[i] > playerBoxBounds.width / 2 + playerBoxBounds.x) {
|
|
||||||
direction = "down"
|
|
||||||
lifeAdjust = -1
|
|
||||||
} else {
|
|
||||||
direction = "up"
|
|
||||||
lifeAdjust = 1
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (touchY[i] > playerBoxBounds.height / 2 + playerBoxBounds.y) {
|
|
||||||
direction = "down"
|
|
||||||
lifeAdjust = -1
|
|
||||||
} else {
|
|
||||||
direction = "up"
|
|
||||||
lifeAdjust = 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
playerList[n - 1].holdTime += 1
|
|
||||||
if (playerList[n - 1].direction != direction) {
|
|
||||||
playerList[n - 1].holdTime = 0
|
|
||||||
playerList[n - 1].direction = direction
|
|
||||||
}
|
|
||||||
if (playerList[n - 1].holdTime != 0 && playerList[n - 1].holdTime < 5) {
|
|
||||||
lifeAdjust = 0
|
|
||||||
} else if (playerList[n - 1].holdTime > 28) {
|
|
||||||
lifeAdjust *= 5
|
|
||||||
if (playerList[n - 1].holdTime >= 60) {
|
|
||||||
lifeAdjust *= 2
|
|
||||||
}
|
|
||||||
}
|
|
||||||
playerList[n - 1].life += lifeAdjust
|
|
||||||
activePlayerBoxes[activePlayerBoxes.length] = n
|
|
||||||
drawPlayerBox(n)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (var i = 1; i <= playerList.length; i ++) {
|
|
||||||
if (!activePlayerBoxes.includes(i)) {
|
|
||||||
playerList[i - 1].firection = "none"
|
|
||||||
playerList[i - 1].holdTime = 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
activePlayerBoxes = []
|
|
||||||
setTimeout(updatePlayerBoxes, 100)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function clearTimers() {
|
|
||||||
for (var i = 1; i <= playerList.length; i ++) {
|
|
||||||
playerList[i - 1].direction = 0
|
|
||||||
playerList[i - 1].holdTime = 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function drawPlayerBox(playerBoxID) {
|
function drawPlayerBox(playerBoxID) {
|
||||||
var currentPlayerBox = playerList[playerBoxID - 1]
|
var currentPlayerBox = playerList[playerBoxID - 1]
|
||||||
var context = currentPlayerBox.canvas.customVarContext
|
var context = currentPlayerBox.canvas.customVarContext
|
||||||
@@ -314,20 +234,16 @@ document.getElementById("mainGrid").addEventListener("mousedown", startMouseCoor
|
|||||||
window.addEventListener("mousemove", updateMouseCoordinates, true)
|
window.addEventListener("mousemove", updateMouseCoordinates, true)
|
||||||
window.addEventListener("mouseup", endMouseCoordinates, true)
|
window.addEventListener("mouseup", endMouseCoordinates, true)
|
||||||
function startMouseCoordinates() {
|
function startMouseCoordinates() {
|
||||||
clicking = true
|
playerList[event.target.customVarID - 1].touchId = 1
|
||||||
singleTap(event.target)
|
singleTap(event.target)
|
||||||
}
|
}
|
||||||
function updateMouseCoordinates() {
|
function updateMouseCoordinates() {
|
||||||
touchX[0] = event.clientX
|
touchX[0] = event.clientX
|
||||||
touchY[0] = event.clientY
|
touchY[0] = event.clientY}
|
||||||
// touchX[1] = 50
|
|
||||||
// touchY[1] = 50 //For testing purposes only
|
|
||||||
}
|
|
||||||
function endMouseCoordinates() {
|
function endMouseCoordinates() {
|
||||||
clearTimeout(loop)
|
for (var i = 1; i <= playerList.length; i++) {
|
||||||
loop = false
|
playerList[i - 1].touchId = 0.5
|
||||||
clearTimers()
|
}
|
||||||
clicking = false
|
|
||||||
}
|
}
|
||||||
window.addEventListener("touchstart", switchToTouchEvents, true)
|
window.addEventListener("touchstart", switchToTouchEvents, true)
|
||||||
function switchToTouchEvents() {
|
function switchToTouchEvents() {
|
||||||
@@ -342,7 +258,6 @@ function switchToTouchEvents() {
|
|||||||
function startTouch() {
|
function startTouch() {
|
||||||
playerList[event.changedTouches[0].target.customVarID - 1].touchId = event.changedTouches[0].identifier
|
playerList[event.changedTouches[0].target.customVarID - 1].touchId = event.changedTouches[0].identifier
|
||||||
moveTouch()
|
moveTouch()
|
||||||
clicking = true
|
|
||||||
singleTap(event.changedTouches[0].target)
|
singleTap(event.changedTouches[0].target)
|
||||||
}
|
}
|
||||||
function moveTouch() {
|
function moveTouch() {
|
||||||
@@ -359,20 +274,8 @@ function endTouch() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
moveTouch()
|
moveTouch()
|
||||||
if (event.touches.length == 0) {
|
|
||||||
clicking = false
|
|
||||||
clearTimeout(loop)
|
|
||||||
clearTimers()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
//Tap (and click) functions
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function singleTap(targetPlayerBox) {
|
function singleTap(targetPlayerBox) {
|
||||||
var playerBoxBounds = targetPlayerBox.getBoundingClientRect()
|
var playerBoxBounds = targetPlayerBox.getBoundingClientRect()
|
||||||
var tappedPlayerBox = playerList[targetPlayerBox.customVarID - 1]
|
var tappedPlayerBox = playerList[targetPlayerBox.customVarID - 1]
|
||||||
@@ -398,15 +301,14 @@ function singleTap(targetPlayerBox) {
|
|||||||
drawPlayerBox(tappedPlayerBox.id)
|
drawPlayerBox(tappedPlayerBox.id)
|
||||||
setTimeout(clockCheck.bind(null, tappedPlayerBox), 500)
|
setTimeout(clockCheck.bind(null, tappedPlayerBox), 500)
|
||||||
}
|
}
|
||||||
|
|
||||||
function clockCheck(tappedPlayerBox) {
|
function clockCheck(tappedPlayerBox) {
|
||||||
if (tappedPlayerBox.touchId != 0.5) {
|
if (tappedPlayerBox.touchId != 0.5) {
|
||||||
tappedPlayerBox.life += tappedPlayerBox.direction
|
tappedPlayerBox.life += tappedPlayerBox.direction
|
||||||
drawPlayerBox(tappedPlayerBox.id)
|
drawPlayerBox(tappedPlayerBox.id)
|
||||||
if (tappedPlayerBox.holdTime >= 300) {
|
if (tappedPlayerBox.holdTime >= 150) {
|
||||||
setTimeout(clockCheck.bind(null, tappedPlayerBox), 10)
|
setTimeout(clockCheck.bind(null, tappedPlayerBox), 10)
|
||||||
} else if (tappedPlayerBox.holdTime >= 50) {
|
} else if (tappedPlayerBox.holdTime >= 50) {
|
||||||
setTimeout(clockCheck.bind(null, tappedPlayerBox), 20)
|
setTimeout(clockCheck.bind(null, tappedPlayerBox), 50)
|
||||||
} else {
|
} else {
|
||||||
setTimeout(clockCheck.bind(null, tappedPlayerBox), 100)
|
setTimeout(clockCheck.bind(null, tappedPlayerBox), 100)
|
||||||
}
|
}
|
||||||
@@ -415,153 +317,4 @@ function clockCheck(tappedPlayerBox) {
|
|||||||
tappedPlayerBox.holdTime = 0
|
tappedPlayerBox.holdTime = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function singleClick() {
|
|
||||||
for (var i = 1; i <= playerList.length; i ++) {
|
|
||||||
var playerBoxBounds = playerList[i - 1].canvas.getBoundingClientRect()
|
|
||||||
if (touchX[touchX.length - 1] >= playerBoxBounds.left && touchX[touchX.length - 1] <= playerBoxBounds.right && touchY[touchY.length - 1] >= playerBoxBounds.top && touchY[touchY.length - 1] <= playerBoxBounds.bottom) {
|
|
||||||
//This canvas is being clicked on! Do something about it.
|
|
||||||
var direction = "", lifeAdjust = 0
|
|
||||||
if (playerList[i - 1].rotation == 0) {
|
|
||||||
if (touchX[touchX.length - 1] > playerBoxBounds.width / 2 + playerBoxBounds.x) {
|
|
||||||
direction = "up"
|
|
||||||
lifeAdjust = 1
|
|
||||||
} else {
|
|
||||||
direction = "down"
|
|
||||||
lifeAdjust = -1
|
|
||||||
}
|
|
||||||
} else if (playerList[i - 1].rotation == 90) {
|
|
||||||
if (touchY[touchY.length - 1] > playerBoxBounds.height / 2 + playerBoxBounds.y) {
|
|
||||||
direction = "up"
|
|
||||||
lifeAdjust = 1
|
|
||||||
} else {
|
|
||||||
direction = "down"
|
|
||||||
lifeAdjust = -1
|
|
||||||
}
|
|
||||||
} else if (playerList[i - 1].rotation == 180) {
|
|
||||||
if (touchX[touchX.length - 1] > playerBoxBounds.width / 2 + playerBoxBounds.x) {
|
|
||||||
direction = "down"
|
|
||||||
lifeAdjust = -1
|
|
||||||
} else {
|
|
||||||
direction = "up"
|
|
||||||
lifeAdjust = 1
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (touchY[touchY.length - 1] > playerBoxBounds.height / 2 + playerBoxBounds.y) {
|
|
||||||
direction = "down"
|
|
||||||
lifeAdjust = -1
|
|
||||||
} else {
|
|
||||||
direction = "up"
|
|
||||||
lifeAdjust = 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
playerList[i - 1].life += lifeAdjust
|
|
||||||
drawPlayerBox(i)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (loop == false) {
|
|
||||||
loop = setTimeout(heldDown, 100)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
function heldDown() {
|
|
||||||
if (clicking) {
|
|
||||||
for (var i = 0; i < touchX.length; i++) {
|
|
||||||
for (var n = 1; n <= playerList.length; n ++) {
|
|
||||||
var playerBoxBounds = playerList[n - 1].canvas.getBoundingClientRect()
|
|
||||||
if (touchX[i] >= playerBoxBounds.left && touchX[i] <= playerBoxBounds.right && touchY[i] >= playerBoxBounds.top && touchY[i] <= playerBoxBounds.bottom) {
|
|
||||||
//This canvas is being clicked on! Do something about it.
|
|
||||||
var direction = "", lifeAdjust = 0
|
|
||||||
if (playerList[n - 1].rotation == 0) {
|
|
||||||
if (touchX[i] > playerBoxBounds.width / 2 + playerBoxBounds.x) {
|
|
||||||
direction = "up"
|
|
||||||
lifeAdjust = 1
|
|
||||||
} else {
|
|
||||||
direction = "down"
|
|
||||||
lifeAdjust = -1
|
|
||||||
}
|
|
||||||
} else if (playerList[n - 1].rotation == 90) {
|
|
||||||
if (touchY[i] > playerBoxBounds.height / 2 + playerBoxBounds.y) {
|
|
||||||
direction = "up"
|
|
||||||
lifeAdjust = 1
|
|
||||||
} else {
|
|
||||||
direction = "down"
|
|
||||||
lifeAdjust = -1
|
|
||||||
}
|
|
||||||
} else if (playerList[n - 1].rotation == 180) {
|
|
||||||
if (touchX[i] > playerBoxBounds.width / 2 + playerBoxBounds.x) {
|
|
||||||
direction = "down"
|
|
||||||
lifeAdjust = -1
|
|
||||||
} else {
|
|
||||||
direction = "up"
|
|
||||||
lifeAdjust = 1
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (touchY[i] > playerBoxBounds.height / 2 + playerBoxBounds.y) {
|
|
||||||
direction = "down"
|
|
||||||
lifeAdjust = -1
|
|
||||||
} else {
|
|
||||||
direction = "up"
|
|
||||||
lifeAdjust = 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
playerList[n - 1].holdTime += 1
|
|
||||||
if (playerList[n - 1].direction != direction) {
|
|
||||||
playerList[n - 1].holdTime = 0
|
|
||||||
playerList[n - 1].direction = direction
|
|
||||||
}
|
|
||||||
if (playerList[n - 1].holdTime < 5) {
|
|
||||||
lifeAdjust = 0
|
|
||||||
} else if (playerList[n - 1].holdTime > 28) {
|
|
||||||
lifeAdjust *= 5
|
|
||||||
if (playerList[n - 1].holdTime >= 60) {
|
|
||||||
lifeAdjust *= 2
|
|
||||||
}
|
|
||||||
}
|
|
||||||
playerList[n - 1].life += lifeAdjust
|
|
||||||
activePlayerBoxes[activePlayerBoxes.length] = n
|
|
||||||
drawPlayerBox(n)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (var i = 1; i <= playerList.length; i ++) {
|
|
||||||
if (!activePlayerBoxes.includes(i)) {
|
|
||||||
playerList[i - 1].firection = "none"
|
|
||||||
playerList[i - 1].holdTime = 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
loop = setTimeout(heldDown, 100)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//Updated!!! Are we there yet? Ooh! Is this it? ermagerd?
|
//Updated!!! Are we there yet? Ooh! Is this it? ermagerd?
|
||||||
|
@@ -128,9 +128,12 @@
|
|||||||
#gridShell {
|
#gridShell {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
#gridShell:fullscreen {
|
#gridShell:fullscreen {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
}
|
}
|
||||||
|
#gridShell:-webkit-full-screen {
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
#gridShell.fullscreenUnavailable {
|
#gridShell.fullscreenUnavailable {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
}
|
}
|
||||||
@@ -224,4 +227,4 @@
|
|||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<script src="data/life/life.js"></script>
|
<script src="data/life/life.js"></script>
|
||||||
<html>
|
<html>
|
||||||
|
Reference in New Issue
Block a user