From 6fb7f248f79df057b6caf294aaf0d4d10df455ca Mon Sep 17 00:00:00 2001 From: Andrew Ardill Date: Thu, 4 Jul 2013 14:51:40 +1000 Subject: [PATCH] world.js: Trigger movement with clicks on the map Clicking on the map in different quadrants will move you in that direction. Clicks are measured relative to the centre of the current location centre of the map. Click above the player to move up, click below to move down etc. This should enable better gameplay on touch devices. --- script/world.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/script/world.js b/script/world.js index 16b9791..7ad8167 100644 --- a/script/world.js +++ b/script/world.js @@ -315,6 +315,26 @@ var World = { default: break; } + }, + + click: function(event) { + var map = $('#map'), + // measure clicks relative to the centre of the current location + centreX = map.offset().left + map.width() * World.curPos[0] / (World.RADIUS * 2), + centreY = map.offset().top + map.height() * World.curPos[1] / (World.RADIUS * 2), + clickX = event.pageX - centreX, + clickY = event.pageY - centreY; + if (clickX > clickY && clickX < -clickY) { + World.moveNorth(); + } + if (clickX < clickY && clickX > -clickY) { + World.moveSouth(); + } + if (clickX < clickY && clickX < -clickY) { + World.moveWest(); + } + if (clickX > clickY && clickX > -clickY) { + World.moveEast(); } }, @@ -663,6 +683,8 @@ var World = { var map = $('#map'); if(map.length == 0) { map = new $('
').attr('id', 'map').appendTo('#worldOuter'); + // register click handler + map.click(World.click); } var mapString = ""; for(var j = 0; j <= World.RADIUS * 2; j++) {