|
|
@ -84,40 +84,36 @@ $(document).keydown(function(e) {
|
|
|
|
|
|
|
|
|
|
|
|
switch (e.which) {
|
|
|
|
switch (e.which) {
|
|
|
|
case 37:
|
|
|
|
case 37:
|
|
|
|
/* $div.css('left', $div.offset().left - 20);*/
|
|
|
|
|
|
|
|
offset.left -= 20;
|
|
|
|
offset.left -= 20;
|
|
|
|
console.log("left");
|
|
|
|
console.log("left");
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 38:
|
|
|
|
case 38:
|
|
|
|
// $div.css('top', $div.offset().top - 20);
|
|
|
|
|
|
|
|
offset.top -= 20;
|
|
|
|
offset.top -= 20;
|
|
|
|
console.log("top");
|
|
|
|
console.log("top");
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 39:
|
|
|
|
case 39:
|
|
|
|
//$div.css('left', $div.offset().left + 20);
|
|
|
|
|
|
|
|
offset.left += 20;
|
|
|
|
offset.left += 20;
|
|
|
|
console.log("right");
|
|
|
|
console.log("right");
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 40:
|
|
|
|
case 40:
|
|
|
|
//$div.css('top', $div.offset().top + 20);
|
|
|
|
|
|
|
|
offset.top += 20;
|
|
|
|
offset.top += 20;
|
|
|
|
console.log("down");
|
|
|
|
console.log("down");
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//check the offset
|
|
|
|
//check the offset
|
|
|
|
if (offset.left < 0) {
|
|
|
|
if (offset.left < 100) {
|
|
|
|
offset.left = 0;
|
|
|
|
offset.left = 100;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (offset.left > $("#ground").width() - 50) {
|
|
|
|
if (offset.left > $("#ground").width() - 100) {
|
|
|
|
offset.left = $("#ground").width() - 50;
|
|
|
|
offset.left = $("#ground").width() - 100;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (offset.top < 0) {
|
|
|
|
if (offset.top < 200) {
|
|
|
|
offset.top = 0;
|
|
|
|
offset.top = 200;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (offset.top > $("#ground").height() - 100) {
|
|
|
|
if (offset.top > $("#ground").height() - 220) {
|
|
|
|
offset.top = $("#ground").height() - 100;
|
|
|
|
offset.top = $("#ground").height() - 220;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|