• Advertisement

Archived

This topic is now archived and is closed to further replies.

2D Tile Collisions

This topic is 5738 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Don't laugh too hard, the following code does work for doing tile collision checks between a player structures x and y coords and tiles. But it checks for collisions every time it draws a wall tile (1's are walls, 0's are clear), awfully inefficient. So far it's the only method I've gotten to work. Looking for other articles/tutorials on the subject when time permits. //map array char map[]= { 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1, 1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1, 1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1, 1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1, 1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1, 1,0,0,0,0,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1, 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, 1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1, 1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1, 1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1, 1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1, 1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1, 1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, }; //function to draw tiles void drawTiles(void) { RECT rcRect; HRESULT ddrval; int startX,startY; int renderX,renderY; int whichCell; int xOffset,yOffset; startX=0; startY=0; rcRect.top=0; rcRect.bottom=16; whichCell=0; xOffset=240; yOffset=100; for(renderY=0;renderY<20;renderY++) { xOffset=240; for(renderX=0;renderX<20;renderX++) { if(map[whichCell]==1) { rcRect.left=0; rcRect.right=16; detHits(xOffset,yOffset); /**/ } if(map[whichCell]==0) { rcRect.left=16; rcRect.right=32; } ddrval=lpDDSBack->BltFast(xOffset,yOffset,lpDDSTextures, &rcRect,DDBLTFAST_SRCCOLORKEY); xOffset=xOffset+16; ++whichCell; } yOffset=yOffset+16; } } Better methods? "A man can't just sit around." 'Lawn Chair' Larry Walters (1982) [edited by - Tracy on June 7, 2002 5:24:49 PM]

Share this post


Link to post
Share on other sites
Advertisement
Drawing a map is not the same thing as checking for collisions. I don''t see why you''re putting them in the same part. There''s no need to - whenever you need to check for collisions, you just take the player''s location, translate that into tile coordinates, and see if the tile (or tiles) at that location is passable or not.

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files ]

Share this post


Link to post
Share on other sites
Got it!

"A man can''t just sit around." ''Lawn Chair'' Larry Walters (1982)

Share this post


Link to post
Share on other sites

  • Advertisement