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.
This commit is contained in:
Andrew Ardill
2013-07-04 14:51:40 +10:00
parent d0a171e95b
commit 6fb7f248f7
+22
View File
@@ -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 $('<div>').attr('id', 'map').appendTo('#worldOuter');
// register click handler
map.click(World.click);
}
var mapString = "";
for(var j = 0; j <= World.RADIUS * 2; j++) {