Random sprite creation help

BlitzMax Forums/BlitzMax Beginners Area/Random sprite creation help

TomShep(Posted 2011) [#1]
Im am very new to blitzmax and coding in general so forgive me for asking what is probably the most obvious question...

I am trying to get sprites(squares atm) to be drawn in a random position at a certain rate...

when I have

If Rand(10) = 1 Then
enemy:Tblue = New Tblue
DrawImage (blue, enemy.x, enemy.y)
enemy.x = rand(0,100)
enemy.y = rand(0,100)
ListAddLast bluelist, blue

For enemy:Tblue = EachIn bluelist
If enemy.x < player.x
enemy.x = enemy.x + bluespeed
EndIf
If enemy.x > player.x
enemy.x = enemy.x - bluespeed
EndIf
If enemy.y < player.y
enemy.y = enemy.y + bluespeed
EndIf
If enemy.y > player.y
enemy.y = enemy.y - bluespeed
EndIf
Next
EndIf

one version of the sprite appears in the top corner and just flashes.... Im not sure if I am approaching the random location of each generation correctly either...

Any help with this would be most appreciated

Tom

Last edited 2011

Last edited 2011

Last edited 2011


Warpy(Posted 2011) [#2]
You need to add the 'enemy' object to the list, not the 'blue' image.
Your method for picking the location randomly looks fine.


Polan(Posted 2011) [#3]
Put drawimage in eachin loop (it's not Call and Forget function) and use it after you set position variable.
And move eachin loop outside if rand(10) = 1 statement.
If Rand(10) = 1 Then 
enemy:Tblue = New Tblue
enemy.x = rand(0,100)
enemy.y = rand(0,100)
ListAddLast bluelist, enemy
endif
For enemy:Tblue = EachIn bluelist	
If enemy.x < player.x
enemy.x = enemy.x + bluespeed 
EndIf 
If enemy.x > player.x
enemy.x = enemy.x - bluespeed
EndIf 
If enemy.y < player.y
enemy.y = enemy.y + bluespeed
EndIf 
If enemy.y > player.y
enemy.y = enemy.y - bluespeed
EndIf
DrawImage (blue, enemy.x, enemy.y)
Next 


Last edited 2011


TomShep(Posted 2011) [#4]
Bloody hell, I thought it might be something simple,
- Thanks guys - really appreciate it!!

Tom