首页 > 解决方案 > 如何在我的 JavaScript 游戏中围绕网格移动玩家?

问题描述

在我正在制作的游戏界面中,玩家将鼠标朝他们希望角色移动的方向移动。

度数值(如东方的 90)被发送回游戏服务器。

调用该函数时move,我希望玩家的 x 和 y 位置根据度数值发生变化。

所以, move(90, 0, 0)will return{x:1, y:0}并且move(45, 8, 14)could return {x:8.something, y:14.something}

代码需要是 JavaScript,看起来像这样:

function move(degree, currentX, currentY) {
  //Complicated maths things with pi and circles and stuff
  return {x:newX,y:newY};
}

标签: javascriptrotationgrid

解决方案


推荐阅读