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 |
void Ball::move(float speed, float frameTime, Spieler &s, Block &b) { // Kollision mit den Rändern des Fensters if(sBall.GetPosition().x <= 10.5f || sBall.GetPosition().x >= 789.5f) { xAenderung = -xAenderung; } if(sBall.GetPosition().y <= 10.5f || sBall.GetPosition().y >= 589.5f) { yAenderung = -yAenderung; } // Kollision mit dem Spieler if((sBall.GetPosition().x + 10.5f >= s.getPositionX() - 100.5f) && (sBall.GetPosition().x - 10.5f <= s.getPositionX() + 100.5f) && (sBall.GetPosition().y + 10.5f >= s.getPositionY() - 15.5f)) { yAenderung = -yAenderung; } // Kollision mit dem Block // Hier ist das Problem! :( sBall.Move(xAenderung * speed * frameTime, yAenderung * speed * frameTime); setPosition(sBall.GetPosition().x, sBall.GetPosition().y); } |
Alter Hase
Beruf: Softwareentwickler (aktuell Web/Node); Freiberuflicher Google Proxy
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
int Brick::Collision(int x, int y, PMASK* mask) { if(isAlive) { if(check_pmask_collision(this->mask,mask,this->x,this->y,x,y)) { if(this->y>y+(mask->h+ballradius)||this->y<(y-ballradius)) { return 1; } if(this->x>x+mask->w-ballradius||this->x<x+ballradius) { return 2; } } } return 0; } |
Quellcode |
|
1 2 3 4 5 6 7 8 9 |
Vector2 PointLineDist(Vector2 point, Vector2 linestart, Vector2 lineend) { Vector2 a = lineend - linestart; Vector2 b = point - linestart; double t = dot(a, b)/(length(a)²); if (t < 0) t = 0; if (t > 1) t = 1; return linestart + a * t; } |
Quellcode |
|
1 2 3 4 5 6 7 |
// minvec = Kürzester Verbindungsvektor zum rechteck // speed = geschwindigkeit des balles Vector2 norm = normalize(minvec); // Normale Vector2 orth = Vector2(norm.y,-norm.x); // Orthogonale Vector2 snorm = dot(norm,speed) * norm; // Geschwindigkeitskomponente in normalen-richtung Vector2 sorth = dot(orth,speed) * orth; // Geschwindigkeitskomponente in orthogonalen-richtung speed = sorth - snorm; // neue Geschwindigkeit |
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »CBenni::O« (09.09.2012, 21:18)
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 |
// Kollision mit den Blöcken // Speichere alle Mittelpunkte der Ballränder float left_x = posX; float left_y = posY + 10.5f; float right_x = posX + 20.f; float right_y = posY + 10.5f; float top_x = posX + 10.5f; float top_y = posY; float bottom_x = posX + 10.5f; float bottom_y = posY + 20.f; bool left = false; bool right = false; bool top = false; bool bottom = false; if(checkPointInBlock(left_x, left_y, Brick.posX, Brick.posY)) left = true; if(checkPointInBlock(right_x, right_y, Brick.posX, Brick.posY)) right = true; if(checkPointInBlock(top_x, top_y, Brick.posX, Brick.posY)) top = true; if(checkPointInBlock(bottom_x, bottom_y, Brick.posX, Brick.posY)) bottom = true; if(left) { xAenderung = -xAenderung; posX += 5.f; setPosition(posX, posY); } if(right) { xAenderung = -xAenderung; posX -= 5.f; setPosition(posX, posY); } if(top) { yAenderung = -yAenderung; posY += 5.f; setPosition(posX, posY); } if(bottom) { yAenderung = -yAenderung; posY -= 5.f; setPosition(posX, posY); } |
C-/C++-Quelltext |
|
1 2 3 4 |
bool checkPointInBlock(float x, float y, float blockX, float blockY) { return ((x > blockX) && (x < blockX + 100.f) && (y > blockY) && (y < blockY + 50.f)); } |
Werbeanzeige