LoginLogin
Nintendo shutting down 3DS + Wii U online services, see our post

mutiple ramdom sprites and collision

Root / Programming Questions / [.]

PedoSaCreated:
i need help to make multiple sprites with ramdom behaviors that are all the same some trees that get to a ramdom x,y value and some collision sprite which makes them dissapear it would look like this but just the trees

So you want to create random sprites and detect collision? Collision is as simple as using SPCOL sprite#,true/false and checking SPHITSP for each sprite.

i need help to make multiple sprites with ramdom behaviors that are all the same some trees that get to a ramdom x,y value and some collision sprite which makes them dissapear it would look like this but just the trees
Could you clarify what you mean in this message? The fact that there isn’t any punctuation is making it very hard to figure out what you’re saying.

Could you clarify what you mean in this message? The fact that there isn’t any punctuation is making it very hard to figure out what you’re saying.
Here is a grammar corrected version for your viewing pleasure: I need help to make multiple sprites with random behaviors that are all the same. some trees that get to a random x and y value and some collision sprite which makes them disappear. it would look like this, but just the trees

Could you clarify what you mean in this message? The fact that there isn’t any punctuation is making it very hard to figure out what you’re saying.
Here is a grammar corrected version for your viewing pleasure: I need help to make multiple sprites with random behaviors that are all the same. some trees that get to a random x and y value and some collision sprite which makes them disappear. it would look like this, but just the trees
In that case for the sprites doing random things I suggest an array. When a sprite is created assign random values to the array including its coordinates. You might want to use multiple 1d arrays to make removal of each tree object easier (just remove the element(s) for that tree).

ACLS

rndmX = RND(100) 'the 100 in parentheses is the maximum value the random variable can have. You should change this to your needs.
rndmY = RND(100)

FOR I=0 TO numSprites 'put the number of sprites you want to create in place of numSprites
   SPSET I , treeSprite
   SPOFS I , rndmX, rndmY
   SPCOL I
NEXT
This should work for randomly placing multiple sprites across the screen. I’m still not sure what you mean by “and some collision Sprite that makes them disappear”. Perhaps you mean the player sprite? If that’s the case, then it’s simple enough to add collision to that.

ACLS

rndmX = RND(100) 'the 100 in parentheses is the maximum value the random variable can have. You should change this to your needs.
rndmY = RND(100)

FOR I=0 TO numSprites 'put the number of sprites you want to create in place of numSprites
   SPSET I , treeSprite
   SPOFS I , rndmX, rndmY
   SPCOL I
NEXT
This should work for randomly placing multiple sprites across the screen. I’m still not sure what you mean by “and some collision Sprite that makes them disappear”. Perhaps you mean the player sprite? If that’s the case, then it’s simple enough to add collision to that.
oops i mean the random sprites

SPSET RND#

oops i mean the random sprites
You want the Randomly placed sprites to disappear when they collide with each other? I’m sorry, it’s just not making very much sense.

oops i mean the random sprites
You want the Randomly placed sprites to disappear when they collide with each other? I’m sorry, it’s just not making very much sense.
no when the Player colides they disapear

RANDOM_NUMBER=RND(128)
SPSET 0,1
SPSET 1,RANDOM_NUMBER
IF SPHITSP(0,1) THEN SPCLR 1
Use loops and the concept of reusing sprites (arrays work well for this) with this and you might get the desired effect. Sprite 0 is the player sprite.

oops i mean the random sprites
You want the Randomly placed sprites to disappear when they collide with each other? I’m sorry, it’s just not making very much sense.
no when the Player colides they disapear
OK, that’s easy to do.
ACLS

SPSET 0, 'player sprite
SPCOL 0

rndmX = RND(100) 'the 100 in parentheses is the maximum value the random variable can have. You should change this to your needs.
rndmY = RND(100)

FOR I=1 TO numSprites 'put the number of sprites you want to create in place of numSprites
   SPSET I , treeSprite
   SPOFS I , rndmX, rndmY
   SPCOL I
NEXT

FOR I=1 TO numSprites
   IF SPHITSP(0,I) THEN SPCLR I
NEXT
I haven’t tested this, but it should work. You’ll still have to add your own things like player movement and such, but this should cover random placement and collision.

oops i mean the random sprites
You want the Randomly placed sprites to disappear when they collide with each other? I’m sorry, it’s just not making very much sense.
no when the Player colides they disapear
OK, that’s easy to do.
ACLS

SPSET 0, 'player sprite
SPCOL 0

rndmX = RND(100) 'the 100 in parentheses is the maximum value the random variable can have. You should change this to your needs.
rndmY = RND(100)

FOR I=1 TO numSprites 'put the number of sprites you want to create in place of numSprites
   SPSET I , treeSprite
   SPOFS I , rndmX, rndmY
   SPCOL I
NEXT

FOR I=1 TO numSprites
   IF SPHITSP(0,I) THEN SPCLR I
NEXT
I haven’t tested this, but it should work. You’ll still have to add your own things like player movement and such, but this should cover random placement and collision.
what do you mean by "PLR sprite" the code or name?

I put “ 'player sprite” in the code so that you could choose whichever sprite you want the player to be from the Smile Tool. SPSET 0,1 would make The the orange or whatever fruit is number one in the Smile tool to be the player sprite.