마지막 클릭의 위치를 저장하고 플레이어가 그 방향으로 움직이게하십시오. 이동하여 업데이트 방법 저장소에서 새 대상을
int targetX;
int targetY;
및 적용 :
플레이어 클래스에 이러한 필드를 추가 구글 할 수 있습니다 만 내용
// A new target is selected
if (Mouse.isButtonDown(0)) {
targetX = Mouse.getX();
targetY = Mouse.getY();
}
// Player is not standing on the target
if (targetX != X || targetY != Y) {
// Get the vector between the player and the target
int pathX = targetX - X;
int pathY = targetY - Y;
// Calculate the unit vector of the path
double distance = Math.sqrt(pathX * pathX + pathY * pathY);
double directionX = pathX/distance;
double directionY = pathY/distance;
// Calculate the actual walk amount
double movementX = directionX * speed;
double movementY = directionY * speed;
// Move the player
X = (int)movementX;
Y = (int)movementY;
}
를 "게임 엔진 ". 요즘에는 아무도 게임을 처음부터 쓴 사람이 없습니다. – gerrytan
이것을 gamedev stackexchange로 옮길 수도 있습니다. –
@gerrytan 그것이 사실이라면, 여기에 어떻게 4,000 가지 이상의 XNA 질문 *을 설명 할 수 있습니까? 작은 게임을 처음부터 만들지는 않을 것입니다. 게임 엔진은 종종 소규모 프로젝트의 경우 지나친 과잉입니다. – Lucius