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 |
const unsigned char ball[]={ 0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0, 0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0, 0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0, 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0, 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0, 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0, 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0, 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0, 0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0, 0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0, 0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,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 36 37 |
void moveBall(){ double winkel=atan2(static_cast<double>(ballVektor[1]),static_cast<double>(ballVektor[0])); double dCos = cos(winkel), dSin = sin(winkel); double x,y; x=0; y=0; //nicht über die seltsamen Zahlen wundern, der Sprite wird von eben links abgeprüft statt von der Mitte if (ballX+17 > SCREEN_WIDTH || ballX-17<0 || ballY+21 >SCREEN_HEIGHT || ballY-1 < 0){ x = ballVektor[0] * dCos - ballVektor[1] * dSin; y = ballVektor[0] * dSin + ballVektor[1] * dCos; ballVektor[0]=x; ballVektor[1]=y; } int i, j, c, yofs; ballX=ballX+ballVektor[0]; ballY=ballY+ballVektor[1]; //Ball wird gezeichnet yofs = ballY * (screen->pitch / 4) + ballX; for (i = 0, c = 0; i < 16; i++) { for (j = 0; j < 16; j++, c++) { if (ball[c]) { ((unsigned int*)screen->pixels)[yofs + j] = 0xFFFFFF; } } yofs += (screen->pitch / 4); } } |
C-/C++-Quelltext |
|
1 |
Wenn du nur auf die Wände reagieren willst, schaust eu hald einfach, ob der Ball.x kleiner 0 ist (natürlich noch Breite einberechnen) oder Ball.y grösser die Breite sein soll. (Dasselbe natürlich auch noch für y-Richtung). |
Zitat
Ich sehe jetzt keinen Vorteil mit einer Bitmap, außerdem wollte ich ein klassiches "Pixel"spiel machen, da sollte man natürlich mit Pixeln arbeiten
C-/C++-Quelltext |
|
1 |
screen->pixels)[yofs + j] |
Zitat
Wenn du nämlich mit Bitmaps arbeitest, hast du deine anderen Probleme auch nicht mehr. Ich verstehe auch nicht, warum etwas abstürzen sollte, nur weil es nicht mehr in DEINEM Spielfeld ist. Wenn ich etwas rendere, dann kann das sein, wo es will, das gibt mir nie irgend einen Fehler. Das schlimmste, was passiert ist, dass du einfach nichts siehst, weil es zu weit Weg (oder seitlich) ist.
Zitat
Aber da du da anscheinend in einen anderen Buffer schreibst, würde ich mal davon ausgehen, dass du auf Speicher zugreifst, wo du nicht darfst.
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 |
//for constant velocity if (xVel>0) xVel=static_cast<int>(xVel/xVel) *10; if (yVel>0) yVel=static_cast<int>(yVel/yVel) *10; //If the dot went too far to the left or right if( ( x < 0 ) || ( x + DOT_WIDTH > SCREEN_WIDTH ) ){ double winkel=atan2(static_cast<double>(ballVektor[1]),static_cast<double>(ballVektor[0]))+90; double dCos = cos(winkel), dSin = sin(winkel); double x1,y1; x1=0; y1=0; x1 = xVel * dCos - yVel * dSin; y1 = xVel * dSin + yVel * dCos; xVel=x1; yVel=y1; } if( ( y < 0 ) || ( y + DOT_HEIGHT > SCREEN_HEIGHT )){ double winkel=atan2(static_cast<double>(ballVektor[1]),static_cast<double>(ballVektor[0]))+90; double dCos = cos(winkel), dSin = sin(winkel); double x1,y1; x1=0; y1=0; x1 = xVel * dCos - yVel * dSin; y1 = xVel * dSin + yVel * dCos; xVel=x1; yVel=y1; } //Move the dot left or right x += xVel; //Move the dot up or down y += yVel; |
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 |
void Dot::move() { //If the dot went too far to the left or right if( ( x + DOT_WIDTH > SCREEN_WIDTH ) ){ if (Flugwinkel>=40){ xDirection*=1; yDirection*=-1; }else{ xDirection*=-1; yDirection*=+1; } } if (( x < 0 )){ if (Flugwinkel<=40){ xDirection*=1; yDirection*=-1; }else{ xDirection*=-1; yDirection*=+1; } } //if the dot went too far up or down if( ( y + DOT_HEIGHT > SCREEN_HEIGHT )){ if (Flugwinkel>=40){ xDirection*=1; yDirection*=-1; }else{ xDirection*=-1; yDirection*=+1; } } if (( y< 0 ) ){ if (Flugwinkel<=40){ xDirection*=1; yDirection*=-1; }else{ xDirection*=-1; yDirection*=+1; } } //Move the dot left or right x += xVel*xDirection; //Move the dot up or down y += yVel*yDirection; Flugwinkel=atan2(static_cast<double>(y),static_cast<double>(x))*180/PI ; |
Werbeanzeige