You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
1.3 KiB
JavaScript
64 lines
1.3 KiB
JavaScript
// Clickable checks, event listeners, etc.
|
|
|
|
function clickableCheck(cursorX,cursorY,entity){
|
|
|
|
// Collision detection between clicked offset and clickableItems
|
|
// https://stackoverflow.com/a/9880302
|
|
if(
|
|
cursorY > gameData.position[entity][1] && cursorY < gameData.position[entity][1] + gameData.size[entity][1]
|
|
&& cursorX > gameData.position[entity][0] && cursorX < gameData.position[entity][0] + gameData.size[entity][0]
|
|
)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Left click
|
|
canvas.addEventListener('click', function(event) {
|
|
|
|
var x = event.pageX - canvasLeft,
|
|
y = event.pageY - canvasTop;
|
|
|
|
|
|
console.log('LEFT CLICK X: '+x+' Y: '+y);
|
|
|
|
for (const [key, value] of Object.entries(gameData.size)) {
|
|
// Key is item here
|
|
|
|
// If there's no position data skip, can't interact
|
|
if(gameData.position === undefined){
|
|
continue;
|
|
}
|
|
|
|
// If the X/Y of cursor isn't within the shape's bounds can't interact
|
|
if(!clickableCheck(x,y,key)){
|
|
continue;
|
|
}
|
|
|
|
// If it's deck atm
|
|
if(gameData.deck[key] !== undefined){
|
|
// If deck belongs to player
|
|
if(gameData.player[key] == gameData.playerId){
|
|
requestDrawACard();
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
// Right click
|
|
canvas.addEventListener('contextmenu', function(event) {
|
|
event.preventDefault();
|
|
|
|
var x = event.pageX - canvasLeft,
|
|
y = event.pageY - canvasTop;
|
|
|
|
console.log('RIGHT CLICK X: '+x+' Y: '+y);
|
|
|
|
});
|
|
|