var UserControl = {}; UserControl.lastX = 0; UserControl.lastY = 0; UserControl.dragging = false; UserControl.object = null; UserControl.forces = []; UserControl.dirXs = []; UserControl.dirYs = []; UserControl.beginDrag = function(x, y, object) { UserControl.forces = [0, 0, 0, 0, 0, 0]; UserControl.dirXs = [0, 0, 0, 0, 0, 0]; UserControl.dirYs = [0, 0, 0, 0, 0, 0]; /* User for dragging */ UserControl.lastX = x; UserControl.lastY = y; UserControl.dragging = true; UserControl.object = object; object.dragging = true; } UserControl.updateDrag = function(x, y, levelData) { if (UserControl.dragging) { var dx = (UserControl.lastX - x)/levelData.scale; var dy = (UserControl.lastY - y)/levelData.scale; /* Force */ var force = Math.abs(dx) + Math.abs(dy); UserControl.forces.push(force); UserControl.forces.shift(); UserControl.dirXs.push(dx); UserControl.dirXs.shift(); UserControl.dirYs.push(dy); UserControl.dirYs.shift(); /* Use for dragging */ UserControl.lastX = x; UserControl.lastY = y; if (UserControl.object.dragAllowX) { UserControl.object.x -= dx; } if (UserControl.object.dragAllowY) { UserControl.object.y -= dy; } } } UserControl.endDrag = function(x, y) { if (UserControl.object) { /* Use for force */ var force = 0; var dx = 0; var dy = 0; for (var i=0; i