May 4, 201016 yr Hello everyone. This my first post on this forum, I'm a bit stuck with this thing im trying to do, heres the basics. Its not necessarily code im after, just ideas, maybe if anyones done anything similar before. Ive started a javascript cluedo game, which is coming along all well. I want to use a scanned image of the original board, then declare the various rooms and adjoining squares in an image map. Eventually, users will be able to roll a dice, then move their playing piece depending on dice roll and location on the board. Essentially, I want to limit the players ability to move to the playing area of the board, but cant think of a way to do it other than declaring each square's neighbours, or setting different collision tests for different sectors of the board. I have thought through the possibility of returning the X and Y from the mouse click (would require extensive boundary declarations, and several comparisons depending on where the player is on the board) or declaring each squares neighbours (extensive neighbour declarations!). As yet, I cannot see that either approach is particularly appropriate for what I am trying to accomplish. The shape of the playing area of the board makes the whole thing difficult. If anyone has any ideas on how best to proceed, please make a suggestion, Im sure it'll be something I have not previously considered. Thanks in advance for any ideas.
May 6, 201016 yr Maybe you could create a 2-dimensional array of the board area, a sort of internal map of the board in code. For example if the board area was 8 x 8 squares: (Note the following is pseudo-code just to illustrate the idea) boardArray=new Array [8,8]; boardArray[1]="--------"; boardArray[2]="--XXXX--"; boardArray[3]="--XX----"; ...etc... ...where 'X' is a permitted square or path, and '-' is a forbidden (non-playing) square such as a room wall. If you know where the player's counter is at the moment e.g. say the player is on square 4,2 then you can quickly poll the surrounding 'squares' in the array i.e. 4,1 5,2 4,3 5,1 to determine which directions the counter can be moved in (i.e. for 4,2 valid directions are left, right, down, but not up).
May 19, 201016 yr Author Thank you for your worthy suggestion. What I have done is a more general test based on the edges of the two items to be tested. I wanted to avoid loads of board square declarations, so instead, set the xmax, xmin, ymax and ymin boundaries, in which the playing token moves, then used 2D array to declare locations of each room (or item to be collision tested). For example, if the token is moving left, I first check that the Y coords are in range of any of the test items, if its not in any of the items range, I allow the move. If in items range, I simply test that the tokens edge that is about to intersect is not within an increment of the items edge, if it is not within the increment, allow the move, and vice versa. Its probably a bit more computation, but is probably the general test I was after. Its based on calculating the two approaching vectors, and is summarised in the attached jpeg. I will try the suggested approach for another example, possibly the old 'Stratego' game. Thank you for your suggestion.
Create an account or sign in to comment