Can someone help with this code :(
BlitzMax Forums/BlitzMax Beginners Area/Can someone help with this code :(
| ||
[edited. Now code is properly displayed] Thanks Regular K and xlsior ;) Hi people, I have programmed a little pong clone to help me get familiar with BMax. If you run this code and leave it to run for a few moments, you'll see the problem that i've got. The cpu score seems to shoot up to quickly as the ball is hidden, then suddenly the ball comes back into play. Can anyone please help me out. here is the code: Thankyou Devil |
| ||
I can't seem to reproduce the problem enough to know for sure, but it seems that when the ball bounces out of bounds, then reverses direction, then hits teh top or bottom edge of the user's paddle before the ball actually gets out into the playfield, it reverses back out of bounds again, then sort of gets stuck there for a few hundred cycles until it dislodges itself back into the playing field. You need to make sure the ball is actually traveling toward the paddle before reversing the ball. try changingIf ball.x<(user.x+user.width) And ball.y>user.y And (ball.y+ball.radius)<(user.y+user.height) ball.vx=-ball.vx 'ball to user collision check EndIf with If ball.x<(user.x+user.width) And ball.y>user.y And (ball.y+ball.radius)<(user.y+user.height) And ball.vx < 0 ball.vx=-ball.vx 'ball to user collision check EndIf See if that helps. |
| ||
Hi Tom, I have just replaced the code exactly how you said, and you were right. It works great now!!! Thankyou ever so much, i really appriciate your help :) Thanks again Tom Devil |
| ||
also to put the code into boxes put [ code ] at the top then [ / code ] at the bottom, without spaceslike that ^^ |
| ||
Ahhh, i see :) Thankyou Regular K. I've been wondering how to do that for ages and now i know. Thankyou very much :) |
| ||
you can also put it in a scrollable box using the [ codebox ] tag, like below... Can make discussions a little easier to follow if there are large pieces of code intermixed with them. |
| ||
Thankyou xlsior. Your help is greatly appriciated :) |