Jump to content
IGNORED

How should I be using RAND?


Words Fail

Recommended Posts

DPC+ kernel so I don't need  RAND16.

 

shootmissilebottom 
 rem l=rand
 if rand<=30 then missile1height=14: missile1x=player1x+10: missile1y=player1y-14: k=1
 return thisbank

shootmissiletop
 rem m=rand
 if rand<=30 then missile0height=14: missile0x=player2x+10: missile0y=player2y+14: n=1
 return thisbank 

 

If either top or bottom missile is to fire it goes to one of those. I can see the pattern. I fly up, right, up, left, and the first two bullets usually come out at the exact same spots.. I continue to fly around level and I can usually see the bullets in the some of the same spots.

Link to comment
Share on other sites

2 hours ago, Karl G said:

I don't understand what you are trying to do well enough to know why it isn't working as you expected. It doesn't seem like your missile starting location is at all random, but based on the player's position.

Of course it's based on the player (enemy) position. It's a space ship that fires out of the ship. The randomness is to tell if the ship if it should fire or not.

Link to comment
Share on other sites

30 minutes ago, Words Fail said:

Of course it's based on the player (enemy) position. It's a space ship that fires out of the ship. The randomness is to tell if the ship if it should fire or not.

So, the enemy is moving across the screen, and you are noticing that it seems to "randomly" fire when it is in the same place? I follow now, I think.

 

To get more of a feeling of randomness, you can read from rand at times based on the player's actions, so it would presumably be different each time. Basically you are using the player. Something simple like "if joy0fire then temp1=rand" will cycle the random number generator at non-predictable times, and usually lead to a more random-seeming result for when you do use the rand value for something like this.

Link to comment
Share on other sites

30 minutes ago, Karl G said:

To get more of a feeling of randomness, you can read from rand at times based on the player's actions, so it would presumably be different each time. Basically you are using the player. Something simple like "if joy0fire then temp1=rand" will cycle the random number generator at non-predictable times, and usually lead to a more random-seeming result for when you do use the rand value for something like this.

DPC+ uses a better random number generator

Link to comment
Share on other sites

18 hours ago, Words Fail said:

DPC+ kernel so I don't need  RAND16.

 

shootmissilebottom 
 rem l=rand
 if rand<=30 then missile1height=14: missile1x=player1x+10: missile1y=player1y-14: k=1
 return thisbank

shootmissiletop
 rem m=rand
 if rand<=30 then missile0height=14: missile0x=player2x+10: missile0y=player2y+14: n=1
 return thisbank 

 

If either top or bottom missile is to fire it goes to one of those. I can see the pattern. I fly up, right, up, left, and the first two bullets usually come out at the exact same spots.. I continue to fly around level and I can usually see the bullets in the some of the same spots.

 

What happens if you have one that is if rand<31 and the other one that is if rand>224? Does that change the pattern?

Link to comment
Share on other sites

If you are trying to get an enemy firing but why less discernible pattern sometimes I may do something like have the code for the firing only activate if the enemy was within a certain range of the player. 
 

so if the enemy is moving vertically I may look to see if the enemy y coordinates are close to the player y. And if then it may fire. 

 

other times I may tie the generation of the random firing to something like a timer or a coordinate of something. I will play around with it and tweak until it just feels right. 

Link to comment
Share on other sites

I still like to reference R.T.s rand usage charts:

https://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#rand

 

A pro game maker move is to seed rand when the player first presses the FIRE button.  I do this when they exit the title screen.  Since humans are pretty random you're almost sure to get a unique set of numbers coming out of rand.


 

title

 counter = counter + 1

 if joy0fire then rand = counter : goto maingame

 goto title

 

  • Like 1
Link to comment
Share on other sites

1 hour ago, bogax said:

I don't know what DPC+ does but normally if you use rand in the predicate of an if statement it does'nt call the rand function it just references the rand seed/variable

Ahh; I didn't realize that, but that's good to know. So, in addition to my advice, I'd suggest @Words Fail try setting a temp variable to rand, and then using the temp variable in the code in question.

  • Like 1
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...