Collision Detection.
- Posted by "Lucius L. Hilley III" <lhilley at CDC.NET> Apr 23, 2000
- 375 views
Warning: Fixed width font required to see the 2d MAP. I am working with Cells and SubCells. Take for example the following tiny 2D map. <PRE>--Vain attempt to force fixed width. :) 1234567 ####### # # # ## # ## # # # # ### # # # ####### </PRE> Every # is a wall and every space is open floor. Each # and space is a cell. Each cell is represented as taking up 4x4 SubCells. Thus, CellSize = 4. In other words. The above map is internally represented as this next map. <PRE>--Vain attempt to force fixed width. :) ############################ ############################ ############################ ############################ #### #### #### #### #### #### #### p #### #### #### #### #### ######## #### ######## ######## #### ######## ######## #### ######## ######## #### ######## #### #### #### #### #### #### #### #### #### #### #### #### #### ############ #### #### ############ #### #### ############ #### #### ############ #### #### #### #### #### #### #### #### #### ############################ ############################ ############################ ############################ </PRE> Within each cell a player can in any one of 16 places. I use {x,y} to represent the position of a player. player positions are zero based. There is a 'p' in the above map. It's {x, y} value is {6, 7}.. this means that x = 6 -- and y = 7 I calculate positions as follow: --Actually, I use an optimized set of equivalent calculations XCell = floor(x/CellSize) YCell = floor(y/CellSize) XSubCell = x - (XCell * CellSize) YSubCell = y - (YCell * CellSize) Keep in mind that the player can make diagonal moves. My goal is to have the player navigate the maze a bound by the walls. My current collision detection works quite well but is apparently flawed. Lucius L. Hilley III lhilley at cdc.net +----------+--------------+--------------+ | Hollow | ICQ: 9638898 | AIM: LLHIII | | Horse +--------------+--------------+ | Software | http://www.cdc.net/~lhilley | +----------+-----------------------------+