Update life.js

This commit is contained in:
Kyle
2019-08-16 15:12:46 -07:00
parent a413d46080
commit ea1d8222c1

View File

@@ -91,7 +91,7 @@ function playerBox(playerBoxID, canvasRotation, wide) {
this.canvas = document.createElement("canvas") this.canvas = document.createElement("canvas")
this.direction = "false" this.direction = "false"
this.holdTime = 0 this.holdTime = 0
this.touchIndex = -1 // this.touchId = 0.5
this.color = "#222222" this.color = "#222222"
this.textColor = "#ffffff" this.textColor = "#ffffff"
this.image = new Image() this.image = new Image()
@@ -314,10 +314,8 @@ 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() {
console.log("click started")
clicking = true clicking = true
// singleClick() singleTap(event.target)
singleTap()
} }
function updateMouseCoordinates() { function updateMouseCoordinates() {
touchX[0] = event.clientX touchX[0] = event.clientX
@@ -342,9 +340,10 @@ function switchToTouchEvents() {
window.addEventListener("touchend", endTouch, true) window.addEventListener("touchend", endTouch, true)
} }
function startTouch() { function startTouch() {
event.changedTouches[0].target.touchId = event.changedTouches[0].identifier)
moveTouch() moveTouch()
clicking = true clicking = true
singleTap() singleTap(event.changedTouches[0].target)
} }
function moveTouch() { function moveTouch() {
touchX = [], touchY = [] touchX = [], touchY = []
@@ -354,8 +353,14 @@ function moveTouch() {
} }
} }
function endTouch() { function endTouch() {
// console.log(event.changedTouches) for (var i = 1; i <= playerList.length; i++) {
console.log(event.changedTouches[0].identifier) if (playerList[i - 1].touchId == event.changedTouches[0].identifier) {
playerList[i - 1].touchId = 0.5
console.log(i + " no longer touching")
}
}
console.log(event.changedTouches)
console.log(event.changedTouches[0].target.touchId)
moveTouch() moveTouch()
if (event.touches.length == 0) { if (event.touches.length == 0) {
clicking = false clicking = false
@@ -371,9 +376,9 @@ function endTouch() {
function singleTap() { function singleTap(targetPlayerBox) {
var playerBoxBounds = event.target.getBoundingClientRect() var playerBoxBounds = targetPlayerBox.getBoundingClientRect()
var tappedPlayerBox = playerList[event.target.customVarID - 1] var tappedPlayerBox = playerList[targetPlayerBox.customVarID - 1]
var lifeAdjust = 0 var lifeAdjust = 0
if (tappedPlayerBox.rotation == 0 || tappedPlayerBox.rotation == 180) { if (tappedPlayerBox.rotation == 0 || tappedPlayerBox.rotation == 180) {
if (touchX[touchX.length - 1] > playerBoxBounds.width / 2 + playerBoxBounds.x) { if (touchX[touchX.length - 1] > playerBoxBounds.width / 2 + playerBoxBounds.x) {
@@ -394,8 +399,6 @@ function singleTap() {
direction = lifeAdjust + "" direction = lifeAdjust + ""
tappedPlayerBox.life += lifeAdjust tappedPlayerBox.life += lifeAdjust
drawPlayerBox(tappedPlayerBox.id) drawPlayerBox(tappedPlayerBox.id)
console.log(tappedPlayerBox.id)
console.log(event.changedTouches[0].identifier)
} }
@@ -550,4 +553,4 @@ function heldDown() {
loop = setTimeout(heldDown, 100) loop = setTimeout(heldDown, 100)
} }
} }
//Updated //Updated!!!