midnight8 Posted April 18, 2008 Share Posted April 18, 2008 (edited) in batari basic make a ball appear in a random place in the playfield like in indy 500 Edited April 18, 2008 by midnight8 Quote Link to comment Share on other sites More sharing options...
+batari Posted April 18, 2008 Share Posted April 18, 2008 This is how I would do it: ballx=(rand&127)+16 bally=(rand&63)+8 This gives a decent range while being roughly centered. You can adjust it a little to suit your needs (change the 8 or 16, not the 127 or 63.) If the range isn't quite right, there is a function available that can do this. It's slower and takes up more space, however. Quote Link to comment Share on other sites More sharing options...
midnight8 Posted April 18, 2008 Author Share Posted April 18, 2008 This is how I would do it: ballx=(rand&127)+16 bally=(rand&63)+8 This gives a decent range while being roughly centered. You can adjust it a little to suit your needs (change the 8 or 16, not the 127 or 63.) If the range isn't quite right, there is a function available that can do this. It's slower and takes up more space, however. I'll give that a try. thanks a lot Quote Link to comment Share on other sites More sharing options...
midnight8 Posted April 18, 2008 Author Share Posted April 18, 2008 This is how I would do it: ballx=(rand&127)+16 bally=(rand&63)+8 This gives a decent range while being roughly centered. You can adjust it a little to suit your needs (change the 8 or 16, not the 127 or 63.) If the range isn't quite right, there is a function available that can do this. It's slower and takes up more space, however. that worked like I wanted. thanks. One more question. I am probably asking a lot but how can I make sure it does not appear on top of something else in the playfield? any help appreciated. Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted April 18, 2008 Share Posted April 18, 2008 that worked like I wanted. thanks. One more question. I am probably asking a lot but how can I make sure it does not appear on top of something else in the playfield? any help appreciated. I wonder if pfread might be helpful: http://www.randomterrain.com/atari-2600-me...nds.html#pfread Quote Link to comment Share on other sites More sharing options...
+batari Posted April 18, 2008 Share Posted April 18, 2008 This is how I would do it: ballx=(rand&127)+16 bally=(rand&63)+8 This gives a decent range while being roughly centered. You can adjust it a little to suit your needs (change the 8 or 16, not the 127 or 63.) If the range isn't quite right, there is a function available that can do this. It's slower and takes up more space, however. that worked like I wanted. thanks. One more question. I am probably asking a lot but how can I make sure it does not appear on top of something else in the playfield? any help appreciated. Probably the easiest way would be to check for a playfield/ball collision during the next frame, and if so, get a different random number. This method isn't preemptive, so you may see the ball appear in a few different places for a few frames before it finds a valid place. In practice it will probably work just fine, however. A preemptive method using pfread might work as well, but it will require some additional calculations. Quote Link to comment Share on other sites More sharing options...
midnight8 Posted April 18, 2008 Author Share Posted April 18, 2008 This is how I would do it: ballx=(rand&127)+16 bally=(rand&63)+8 This gives a decent range while being roughly centered. You can adjust it a little to suit your needs (change the 8 or 16, not the 127 or 63.) If the range isn't quite right, there is a function available that can do this. It's slower and takes up more space, however. that worked like I wanted. thanks. One more question. I am probably asking a lot but how can I make sure it does not appear on top of something else in the playfield? any help appreciated. Probably the easiest way would be to check for a playfield/ball collision during the next frame, and if so, get a different random number. This method isn't preemptive, so you may see the ball appear in a few different places for a few frames before it finds a valid place. In practice it will probably work just fine, however. funny you came back and said that. I do not really understand the pfread. I feel really stupid trying to do this stuff hopefully I will get better. I did use the collision detection and so far it seems to be working well for me. I'm kinda proud tho cause I figured it out before you posted it. thanks for you guys help. I appreciate it. A preemptive method using pfread might work as well, but it will require some additional calculations. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.