2012-10-24 2 views
0

미로를 통해 움직이는 캐릭터가있는 게임을 제작 중입니다. 움직임은 한 타일의 중심에서 각 움직임에 대해 선택한 방향 (북쪽, 남쪽, 동쪽 또는 서쪽)으로 다음 타일의 중심으로 이동하지만 벽에 몇 가지 문제가 있습니다.인접한 타일이 경로 상에 있는지 찾기

코딩 방법은 현재 정상적으로 작동하지만 오래 동안 문제가 발생할 수 있습니다. 기본적으로 나는 플레이어가 무대에서 가능할 수있는 각 타일을 검색 한 다음 플레이어가 이동 방향과 관련하여 어떤 옵션을 갖고 있는지를 결정합니다. 예를 들어 :

if (player.center.x = tile_001.x && player.center.y = tile_001.y){ 
    player has option to move in east and west directions 
} 

if (player.center.x = tile_002.x && player.center.y = tile_002.y){ 
    player has option to move in east, north and south directions 
} 

이 나는 ​​캐릭터가 이동할 수있는 결정하는 경우 100 개 이상의 문을 가지고 있음을 의미하며, 나는 더 쉬운 방법이 알고 . 대신 네 개의 인접한 타일을 플레이어의 현재 위치 (미로에있을 수있는 모든 위치)로 검색하여 경로에 있는지 또는 벽의 일부인지 결정합니다.

스택 오버플로에 관해 많은 질문이 있지만 일반적으로 더 많은 코드가 이미 작성되어 있지만 현재로서는이를 수행하는 방법이 없습니다. 어떤 도움이라도 대단히 감사하겠습니다.

하자 '타일'할 수있는 구조/객체 : 나는 언어를 모르는 나는 어떤 대중적인 언어로 구현 가능한있을 정도로 일반 desciption을 떠 났어요 있도록 :

답변

0

이 이론은 특정 엑스 코드되지 않는다 정의합니다 :

  • 그래픽
  • 의 종류 타일 블록의 움직임

는 '보드'다차원 배열 또는 배열의 배열하자합니다. goNorth() goEast() goWest() 및 goWest() :

방향/화살표 키를 할당 처리기가있는 가정

goNorth(player){ 
    int newX = player.x + 1; 
    if(isPassable(newX ,y) == true) 
    player.x = newX; 
    else 
    //set error condition to be used when updating board to make beep noise 
    //redraw the board 
}; 

goEast(player){ 
    int newY = player.y + 1; 
    if(isPassable(x,newY) == true) 
    player.y = newY; 
    else 
    //set error condition to be used when updating board to make beep noise 
    //redraw the board 
} 

goSouth(player){ 
    int newX = player.x - 1; 
    if(isPassable(newX,y) == true) 
    player.x = newX ; 
    else 
    //set error condition to be used when updating board to make beep noise 
    //redraw the board 
} 

goWest(player){ 
    int newY = player.y - 1; 
    if(isPassable(x,newY) == true) 
    player.y = newY; 
    else 
    //set error condition to be used when updating board to make beep noise 
    //redraw the board 
} 

bool isPassable(x,y){ 
bool passable = false; 
//check bounds, if it is outside of range we will return false to prevent the movement 
if((x > -1 && x <= maxWidthIndex) && (y > -1 && y <= maxHeightIndex)) 
    passable = (board[x][y].passable == true); 
return passable; 
}