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 |
// Ball: Konstruktor Ball::Ball(SDL_Surface* img, vector<Paddle>* vec, int s, Mix_Chunk* snd) { // ... reset(); // ... } // Ball: reset void Ball::reset() { // ... const int X_MIN = 200; const int X_MAX = SDL_GetVideoSurface()->clip_rect.w - X_MIN - rect.w; const int Y_MIN = 200; const int Y_MAX = SDL_GetVideoSurface()->clip_rect.h - Y_MIN - rect.h; rect.x = X_MIN + rand() % (X_MAX - X_MIN + 1); rect.y = Y_MIN + rand() % (Y_MAX - Y_MIN + 1); } |
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »Koschi« (17.08.2013, 08:16)
C-/C++-Quelltext |
|
1 |
const int X_MAX = SDL_GetVideoSurface()->clip_rect.w - X_MIN - rect.w; |
C-/C++-Quelltext |
|
1 |
rect.x = X_MIN + rand() % (X_MAX - X_MIN + 1); |
Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von »Koschi« (17.08.2013, 10:28)
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
void Ball::update() { rect.x += xVel; rect.y += yVel; if(rect.x >= SDL_GetVideoSurface()->clip_rect.w - rect.w || rect.x <= 0) xVel = -xVel; if(rect.y >= SDL_GetVideoSurface()->clip_rect.h - rect.h || rect.y <= 0) yVel = -yVel; for(vector<Paddle>::iterator i = paddles->begin(); i != paddles->end(); ++i) { if(rectVsRect(rect, i->getRect())) { xVel = -xVel; Mix_PlayChannel(-1, sound, 0); } } } |
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »wluc-16« (17.08.2013, 10:47)
Ich benutze den Algorithmus schon länger und bis jetzt immer erfolgreich :-)
Daher glaube ich nicht, dass der Algorithmus falsch ist.
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »wluc-16« (17.08.2013, 11:43)
Werbeanzeige