开发者

How do physics work for ball and paddle style games like Breakout and Pong?

开发者 https://www.devze.com 2023-03-31 18:33 出处:网络
I have the following game: I have the rectangle collisions ready with the ball and with the tiles. but my problem is when the ball hits the tiles and the bat, what angle should开发者_开发技巧 the b

I have the following game:

How do physics work for ball and paddle style games like Breakout and Pong?

I have the rectangle collisions ready with the ball and with the tiles. but my problem is when the ball hits the tiles and the bat, what angle should开发者_开发技巧 the ball bounce at? How do I determine that?


You should read up on physics, specifically Reflection. There are lots of tutorials on Breakout style physics.


It's not that difficult, if the ball hits a vertical obstacle simply invert its x velocity, if it hits a horizontal obstacle invert its y velocity.


There is actually a built in method in the XNA Vector2 class just for this. Check out the Vector2.Reflect method.

0

精彩评论

暂无评论...
验证码 换一张
取 消