Skip to main content
gamedev.net
🔒 Locked

Collision detection in my simple 2d Tilebased game

Started by Nyocia 2 replies 950+ views
Original Post
Nyocia
Nyocia
Hello ! this is how i check if we may have a collision around in the world: // TESTING , COLLISION UNDER SPECIAL CIRCUMSTANCES ****->Johan int tx1 = DC->m_SidePlayer.m_iXpos / TILE_SIZE; int ty1 = DC->m_SidePlayer.m_iYpos / TILE_SIZE; int tx2 = DC->m_SidePlayer.m_iXpos+32 / TILE_SIZE; int ty2 = DC->m_SidePlayer.m_iYpos+32 / TILE_SIZE; for( int y = ty1; y < ty2; y++ ) for( int x = tx1; y < tx2; y++ ) { if( DC->m_Tilemap_Side.m_map[x + y * SIDEWORLDWIDTH].m_iFlags == 'a') { HDC hdc = DC->m_dDraw->getBackbufferDC(); TextOut(hdc,0,200,"HEJ",strlen("HEJ")); DC->m_dDraw->releaseBackbufferDC(hdc); } } Unfortually it doesnt work :( can anyone see anything wrong here ?
"Try not. Do, or do not. There is no try" - Yoda- Software Engineer, - Computer Game Developer
password
password
I'm not that good at windows programming, but what about these lines?

for( int y = ty1; y < ty2; y++ )
for( int x = tx1; y < tx2; y++ )
{

if( DC->m_Tilemap_Side.m_map[x + y * SIDEWORLDWIDTH].m_iFlags == 'a')
{
HDC hdc = DC->m_dDraw->getBackbufferDC();
TextOut(hdc,0,200,"HEJ",strlen("HEJ"));
DC->m_dDraw->releaseBackbufferDC(hdc);
}

}

the first loop does have more than one line of code but still no { }.
ronkfist
ronkfist
Well this might not solve it, but its prolly part of the problem...

for( int y = ty1; y < ty2; y++ )
for( int x = tx1; y < tx2; y++ ) <<<--- x++, not y++
Undeadlnsanity
Undeadlnsanity
Try using this:

for( int y = ty1; y < ty2; y++ ) {     for( int x = tx1; x < tx2; x++ ) {                    if( DC->m_Tilemap_Side.m_map[x + y * SIDEWORLDWIDTH].m_iFlags == 'a') {              HDC hdc = DC->m_dDraw->getBackbufferDC();              TextOut(hdc, 0, 200, "HEJ", strlen("HEJ"));              DC->m_dDraw->releaseBackbufferDC(hdc);          }         }}

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.