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 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
void CGame::CheckCollisions() { CShot *pShotPlayer1=NULL; CShot *pShotPlayer2=NULL; pShotPlayer1= m_pPlayer1->GetShotPlayer (); pShotPlayer2 = m_pPlayer2->GetShotPlayer (); SDL_Rect ShotPlayer1=pShotPlayer1->GetRect (); SDL_Rect ShotPlayer2=pShotPlayer2->GetRect (); SDL_Rect Player1= m_pPlayer1->GetRect (); SDL_Rect Player2= m_pPlayer2->GetRect (); //Kollision prüfen if (ShotPlayer1.y < Player2.y + Player2.h && ShotPlayer1.y + ShotPlayer1.h >Player2.y && ShotPlayer1.x < Player2.x + 64 && ShotPlayer1.x + 64> Player2.x) { m_pPlayer2->SetALive(1); pShotPlayer1->SetALive(false); } } |
Zitat von »"Errschaffer"«
Hallo,
Spieler 2 hat 5 leben. Schiest Spieler 1 nun und trifft Spieler2 verschwindet der Schuss (das ist gut also hat die Erkennung funktioniert). Nur hört er nicht mehr auf zu zählen.
Irgendwann hat Spieler 2 -1000 Leben xD
C-/C++-Quelltext
1 2 3 4 5 6 7 { m_pPlayer2->SetALive(1); pShotPlayer1->SetALive(false); } }
Wo könnte solch ein Fehler liegen?
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 |
void CPlayer::ProcessShot(bool Player1, bool Player2) { if (Player1) { if((g_pFramework->KeyDown(SDLK_l))&& (!m_bShotLockPlayer1) && (!m_pShotPlayer->GetALive ())) { m_pShotPlayer=NULL; m_pShotPlayer= new CShot; m_pShotPlayer->Init (m_pSpriteShotPlayer,m_fXPos,m_fYPos); //Sound abspielen m_pSoundShot->Play (); m_bShotLockPlayer1=true; } } if (Player2) { if((g_pFramework->KeyDown(SDLK_q))&& (!m_bShotLockPlayer2) && (!m_pShotPlayer->GetALive ())) { m_pShotPlayer = NULL; m_pShotPlayer= new CShot; m_pShotPlayer->Init (m_pSpriteShotPlayer,m_fXPos,m_fYPos); //Sound abspielen m_pSoundShot->Play (); m_bShotLockPlayer2=true; } } |
C-/C++-Quelltext |
|
1 |
pShotPlayer1->SetALive(false); |
C-/C++-Quelltext |
|
1 |
pShotPlayer1->SetALive(1); |
Zitat von »"defaultplayer"«
n0_0ne void SetALive(int Live) {m_Lives -= Live;}
Er setzt mit false die Leben nicht auf 0, sondern er zieht 0 ab.
Errschaffer Mir fällt gerade ein, dass du bei deiner Kollisionsabfrage garnicht überprüfst, ob der Schuss überhaupt "lebt".
Daran könnte es evtl. liegen?
Werbeanzeige