help plz.., breakout/arkanoid clone, bouncing ball, giving it angles etc.,

Started by
24 comments, last by mickey 21 years, 7 months ago
Let''s say the ball is heading for the paddle (vector +9.4, +3.4), that atan will tell us is about 0.35 * PI (20 degrees). Even if we are modifying the angle, we''ll want the ball out with at -0.35 * PI or 1.9 * PI (20 or 340 degrees) (vector +9.4, -3.4), if the ball hit the middle. This is excatly like we hit the top of a normal brick. I then want this angle to change based on how far (in per cent) I hit off the middle.
I do this by calculating the fAngleIn = atan2f(-X,Y), which gives us -70 degrees, that is, I rotate it 90 degrees. In the middle case, all that is done is to negate this angle (ie. +70 degrees), which is then turned back into a vector.
In my formula, if we are hitting the absolute right of the paddle with fAngleIn = -70 degrees, the fAngle out will be 1 * 0.9 * 90 = 81 degrees, if we hit at 75% of the paddle it will be interpolated between 70 (middle) and 81 (absolute right).

Lets look at the formula again (it''s bad and messy, I know):

fAngleOut = fPaddleHit * ((float)(PI / 2) + fAngleIn * (fPaddleHit < 0 ? -1 : 1)) - fAngleIn;

fPaddleHit * ((float)(PI / 2) will 0 when hitting the middle, 0 -> -45 when left on the paddle, and 0 -> +45 when hitting on the right. I then add the fAngleIn, which is negated if hit on the left, and I then the the in angle off that again. No idea how this formula works, but it does the trick somehow. If it is coming from the right (-90 << fAngleIn << 0), the possible out angle is between the reverse in-angle and 90 degrees (-70 through 90 in our case). If it comes from the left (0 >> fAngleIn >> 90) it can come out between -90 and the reverse in angle (-90 through 70 in our case). Hope you understand anything here, I bet I wouldn''t.

For you problem with the collission detection, I''m afraid I really don''t know where to look. Almost all people making a Arkanoid/Breakout or Pong clone seem to have problem with the ball getting stuck. I did not have that problem at all, so I lack the experience to fix it. Perhaps you need to redo the algorithm from scratch, sometimes that can help. There is another thread here just now (or some hours ago) discussing this problem, see if they have anything good. Also try to search the archives, might give you some hints.

Advertisement
Hiya CWizard, thanks very much, i think you have explained enough, it''s upto me now to understand what you just explained when i go back to my code, thanks again for having some time to help me out,
http://www.dualforcesolutions.comProfessional website designs and development, customized business systems, etc.,
Ok. Hope I''ve been of some help, although I know I tend to complicate matters to the worse when trying to explain them... Good luck
hello,

hope you''re still there to see this, anyway, i''ve got a different question now,

do you have animation on your breakout game like when a ball hits a block and thus your block will show a breaking apart animation.. i was wondering if you associated a ''timer'' for each of the blocks. If not, then plz share how your architect your animations in your breakout clone.

many thanks,
http://www.dualforcesolutions.comProfessional website designs and development, customized business systems, etc.,
Sorry, I didn''t come to that point; they simply disappear

But if you want to animate them, you''ll need some sort of timer for every block. I had this in mind when I designed my game, so I had several parallell arrays, which held different kind of info for every block. The only one I used, though, was my BrickType, which simply said of which type the brick was, if any. Another one I planned on using was BrickStatus, which could hold a counter for bricks that needed more than one. For animation another one would be needed. You''ll be better off, if you somehow store that the brick shall animate, and store the time when it begins, rather then keep a "live" counter on each brick. When rendering, and come across such a brick, you just calculate how much time has passed since it started and pick the correct frame in the animation.

I have a common timing technique when I make "game objects", in that I have initialization, control, run, and render methods. The run methods increments the objects internal timer, which cause the "game object" to pause if I do not call a run method. Which makes pausing the game rather easy, and you can also run it faster and slower, without modifying anything of the object. To have an internal timer for your "game object" is highly suggested to use as reference for the animations, rather than, for example, the system timer.

Just some thoughts, good luck
yes! thank you. timer for each block. Coz i thought i''m using too much data.

now i''m off to ask outside why my ball always gets stuck!

cya around,

http://www.dualforcesolutions.comProfessional website designs and development, customized business systems, etc.,

This topic is closed to new replies.

Advertisement