thanks,

// Are we in the middle of a brick? No idea what to do...if(this->pcBrickType[nBrickHit = nBrick]) nTypeOfHit = 0x80 | 0x02 | 0x04 | 0x10; // Hitting a brick X - 1?else if(this->pcBrickType[nBrickHit = nBrick - 1] && fLocalX < pBall->fRadius && pBall->fSrcSpeedX < 0) nTypeOfHit = 0x80 | 0x01 | 0x02 | 0x10; // Hitting a brick X + 1?else if(this->pcBrickType[nBrickHit = nBrick + 1] && fLocalX > 1 - pBall->fRadius && pBall->fSrcSpeedX > 0) nTypeOfHit = 0x80 | 0x01 | 0x02 | 0x10; // Hitting a brick Y - 1?else if(this->pcBrickType[nBrickHit = nBrick - this->nBoardWidth] && fLocalY < pBall->fRadius && pBall->fSrcSpeedY < 0) nTypeOfHit = 0x80 | 0x00 | 0x04 | 0x10; // Hitting a brick Y + 1?else if(this->pcBrickType[nBrickHit = nBrick + this->nBoardWidth] && fLocalY > 0.5 - pBall->fRadius && pBall->fSrcSpeedY > 0) nTypeOfHit = 0x80 | 0x00 | 0x04 | 0x10; // Are we hitting paddle?else if(pBall->fCurrentY > (float)this->nBoardHeight / 2 - 0.5 - pBall->fRadius && pBall->fSrcSpeedY > 0 && pBall->fCurrentX > this->fPaddleHPosX - this->fPaddleHSize && pBall->fCurrentX < this->fPaddleHPosX + this->fPaddleHSize) { nTypeOfHit = 0x80; // -1 for absolute left of paddle, 0 for middle, +1 for absolute right fPaddleHit = (pBall->fCurrentX - this->fPaddleHPosX) / this->fPaddleHSize * (float)0.9; // Our angle of attack fAngleIn = atan2f(-pBall->fSrcSpeedX, pBall->fSrcSpeedY); // Calculate our defence angle fAngleOut = fPaddleHit * ((float)(PI / 2) + fAngleIn * (fPaddleHit < 0 ? -1 : 1)) - fAngleIn; // Calculate speed vector based on our outgoing angle pBall->fSrcSpeedX = -pBall->fSrcSpeed * sinf(fAngleOut + (float)(PI)); pBall->fSrcSpeedY = -pBall->fSrcSpeed * cosf(fAngleOut);} // If no hit, we'll leave it hereif(!nTypeOfHit) return false; // Adjust angles etc.pBall->fDestX = pBall->fCurrentX;pBall->fDestY = pBall->fCurrentY;pBall->fDestSpeed = pBall->fSrcSpeed;pBall->fDestSpeedX = (nTypeOfHit & 0x02) ? -pBall->fSrcSpeedX : pBall->fSrcSpeedX;pBall->fDestSpeedY = (nTypeOfHit & 0x04) ? -pBall->fSrcSpeedY : pBall->fSrcSpeedY;pBall->fDestAngle = atan2f(pBall->fDestSpeedX, pBall->fDestSpeedY); // If we hit a brick, take care of itif(nTypeOfHit & 0x10) this->HitBrick(nBrickHit);
quote:This was the ball''s vector. What I mean is this: If the ball is "in" or "at" the left border, you should only detect a hit when the ball''s vector has a negative X-part (ie. travelling left), and not if it is positive (ie. travelling right). Make sense? This is to avoid race conditions, when the ball gets a bit stuck in the wall or brick, and continue bouncing back and forth. Just think about it; If your ball is "inside" the left border, and is travelling right, you don''t want it to change direction to the left.
Original post by mickey
ehm, what do you mean by this "but also its vector when detecting a hit", what kind of vector am i going to watch out for this?
quote:Eh, in my current case: no. Well, usually it do, as I have a hybrid system for collission detection. When the hit is predicted (and it didn''t hit anything else before that) it will be moved to exactly the radius from the brick wall (and on it''s path towards it), while on a "real time" hit (the stuff I''ve shown here) it won''t be adjusted, only the speed vector changes.
also, do you set the position too of the ball after it hits or you just bounce it back with the appropriate angle?
quote:Sorry to say, I don''t quite understand why you need a three dimensional array or how you use it, but that''s up to you, and I guess it''s working. No, I didn''t use Direct3D, just DirectDraw 7. The stuff I made was mostly to try a kind of game state machine with independent objects that I plan to employ in the future, so it was never really meant to be a "real" game.
i used a 3 array of int for my game, ie, map[width][height][type of block] then seperate meshes for each type of block i have but all the block''s texture is only contained in one file. This way, i don''t need to call SetTexture everytime i render a block but instead, use the right mesh(the only thing that is different are the texture coordinates), how about you? are you using d3d8 too?
quote:Well, I wouldn''t suggest it. I think it works really great in my game (at least for the borders
hmm.., "where each time the ball starts going somewhere it calculates when (in time) it would hit anything", do you think i need to do this too so that my ball doens''t stuck in the blocks or goes out of bounds? yeah, sometimes my ball just go out of bounds, it doesn''t bounce properly when it hits the sides of the wall,