Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
C-/C++-Quelltext |
|
1 2 3 4 |
if(/*Kollisionsbedingungen*/) { //bisheriger Code, der zur Lokalisierung dient } |
Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von »Checkmateing« (24.08.2013, 20:25)
C-/C++-Quelltext |
|
1 2 |
/* Keep the compiler happy */ return(0); |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
void CStartGame::m_bCheckCollision (CSprite Sprite) { double dLeftA, dLeftB; double dRightA, dRightB; double dTopA, dTopB; double dBottomA, dBottomB; dLeftA = Sprite.fXPos; dRightA = Sprite.fXPos + Sprite.GetWith(); dTopA = Sprite.fYPos; dBottomA = Sprite.fYPos + Sprite.GetHeight(); it = Fields.begin(); while ( it != Fields.end() ) { dLeftB = it->XPos; dRightB = it->XPos + it->GetWith(); dTopB = it->YPos; dBottomB = it->YPos + it->GetHeight(); if( dLeftA < dLeftB && dRightA > dLeftB && dTopA < dBottomB && dBottomA > dTopB ) cout << "Kollision!" << endl; it++; } } |
C-/C++-Quelltext |
|
1 2 |
/* Keep the compiler happy */ return(0); |
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »Swoerm« (25.08.2013, 17:14)
Quellcode |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
if(Kollision) { if(Kollision links) { // } else if(Kollision rechts) { // } else if(Kollision oben) { // } else if (Kollision unten) { // } } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
while ( it != Fields.end() ) { bCollision = false; dLeftB = it->XPos; dRightB = it->XPos + it->GetWith(); dTopB = it->YPos; dBottomB = it->YPos + it->GetHeight(); if( dLeftA < dRightB && dRightA > dLeftB && dTopA < dBottomB && dBottomA > dTopB ) bCollision = true; if(bCollision) { if(dRightB < dLeftA) { m_bCollisionLeft = true; } } |
C-/C++-Quelltext |
|
1 2 |
/* Keep the compiler happy */ return(0); |
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »Swoerm« (25.08.2013, 18:54)
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
void CStartGame::ProcessMoving () { m_bCollisionLeft = false; m_bCollisionRight = false; m_bCollisionTop = false; m_bCollisionBottom = false; m_bCheckCollision (Player); if( g_pFramework->KeyDown (SDLK_LEFT) && Player.fXPos > 0 && !m_bCollisionLeft ) { Player.fXPos -= PlayerSpeed; PlayerState = Left; } if( g_pFramework->KeyDown (SDLK_RIGHT) && Player.fXPos + Player.Sprite->w < g_pFramework->m_pScreen->w && !m_bCollisionRight ) { Player.fXPos += PlayerSpeed; PlayerState = Right; } if( g_pFramework->KeyDown (SDLK_UP) && Player.fYPos > 0 && !m_bCollisionTop ) { Player.fYPos -= PlayerSpeed; PlayerState = Up; } if( g_pFramework->KeyDown (SDLK_DOWN) && Player.fYPos + Player.Sprite->h < g_pFramework->m_pScreen->h && !m_bCollisionBottom ) { Player.fYPos += PlayerSpeed; PlayerState = Down; } } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
void CStartGame::m_bCheckCollision (CSprite Sprite) { double dLeftA, dLeftB; double dRightA, dRightB; double dTopA, dTopB; double dBottomA, dBottomB; bool bCollision = false; dLeftA = Sprite.fXPos; dRightA = Sprite.fXPos + Sprite.GetWith(); dTopA = Sprite.fYPos; dBottomA = Sprite.fYPos + Sprite.GetHeight(); it = Fields.begin(); while ( it != Fields.end() ) { bCollision = false; dLeftB = it->XPos; dRightB = it->XPos + it->GetWith(); dTopB = it->YPos; dBottomB = it->YPos + it->GetHeight(); if( dLeftA < dRightB && dRightA > dLeftB && dTopA < dBottomB && dBottomA > dTopB ) bCollision = true; if(bCollision) { if(dLeftA < dRightB) m_bCollisionLeft = true; if( dRightA > dLeftB ) m_bCollisionRight = true; if( dTopA < dBottomB ) m_bCollisionTop = true; if( dBottomA > dTopB ) m_bCollisionBottom = true; } it++; } } |
C-/C++-Quelltext |
|
1 2 |
/* Keep the compiler happy */ return(0); |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
if(bCollision) { if(dLeftA < dRightB) m_bCollisionLeft = true; if( dRightA > dLeftB ) m_bCollisionRight = true; if( dTopA < dBottomB ) m_bCollisionTop = true; if( dBottomA > dTopB ) m_bCollisionBottom = true; } |
C-/C++-Quelltext |
|
1 2 |
/* Keep the compiler happy */ return(0); |
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »Swoerm« (25.08.2013, 23:14)
Werbeanzeige