Jump to content



0

how do I?


6 replies to this topic

#1 midnight8 OFFLINE  

midnight8

    Dragonstomper

  • 849 posts
  • Location:orange, texas

Posted Thu Apr 17, 2008 7:30 PM

in batari basic make a ball appear in a random place in the playfield like in indy 500

Edited by midnight8, Thu Apr 17, 2008 7:31 PM.


#2 batari OFFLINE  

batari

    )66]U('=I;B$*

  • 6,236 posts
  • begin 644 contest

Posted Thu Apr 17, 2008 7:44 PM

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.

#3 midnight8 OFFLINE  

midnight8

    Dragonstomper

  • 849 posts
  • Location:orange, texas

Posted Thu Apr 17, 2008 7:52 PM

View Postbatari, on Thu Apr 17, 2008 8:44 PM, said:

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

#4 midnight8 OFFLINE  

midnight8

    Dragonstomper

  • 849 posts
  • Location:orange, texas

Posted Thu Apr 17, 2008 7:56 PM

View Postbatari, on Thu Apr 17, 2008 8:44 PM, said:

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.

#5 Random Terrain ONLINE  

Random Terrain

    Visual batari Basic User

  • 20,910 posts
  • Controlled Randomness
    Replay Value
    Nonlinear
  • Location:North Carolina (USA)

Posted Thu Apr 17, 2008 8:00 PM

View Postmidnight8, on Thu Apr 17, 2008 9:56 PM, said:

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.randomter...nds.html#pfread

#6 batari OFFLINE  

batari

    )66]U('=I;B$*

  • 6,236 posts
  • begin 644 contest

Posted Thu Apr 17, 2008 8:24 PM

View Postmidnight8, on Thu Apr 17, 2008 8:56 PM, said:

View Postbatari, on Thu Apr 17, 2008 8:44 PM, said:

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.

#7 midnight8 OFFLINE  

midnight8

    Dragonstomper

  • 849 posts
  • Location:orange, texas

Posted Thu Apr 17, 2008 8:52 PM

View Postbatari, on Thu Apr 17, 2008 9:24 PM, said:

View Postmidnight8, on Thu Apr 17, 2008 8:56 PM, said:

View Postbatari, on Thu Apr 17, 2008 8:44 PM, said:

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.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users