如果它与其他div发生碰撞,如何重置图像位置?

时间:2013-09-12 16:52:57

标签: javascript jquery html css maze

我正在尝试使用javascript / css做一个小迷宫游戏,我知道如果玩家走在地图边界上如何重置迷宫,但是如果玩家走在div(迷宫的墙壁上)我无法找到重置迷宫的简单方法)。

对于地图边框,我使用了以下代码:

  var getPos = $("#player").position();

  $("#x").text('x: ' + getPos.left);

  $("#y").text('y: ' + getPos.top);

  //map border collide
  if(getPos.left < 0 || getPos.left > 484){
  $("#player").css('left', position.left = 0 + 'px');
  $("#player").css('top', position.top = 0 + 'px');
  $("#x").text('x: ' + 0);
  $("#y").text('y: ' + 0);
  }
  else if(getPos.top < 0 || getPos.top > 473){
  $("#player").css('left', position.left = 0 + 'px');
  $("#player").css('top', position.top = 0 + 'px');
  $("#x").text('x: ' + 0);
  $("#y").text('y: ' + 0);
  }

如果玩家走上div或其他物体作为障碍物,我该如何实现?

0 个答案:

没有答案
相关问题