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