Post by tsh73 on Jan 1, 2023 20:59:37 GMT
To be run from JB folder (or do fix sprite paths)
Just move mouse a bit.
New sprite is added every 3 seconds if entry (0,0) is not blocked.
The idea was to use spritecollides to prevent sprites from stomping on each other.
It kind of worked (?)
Just move mouse a bit.
New sprite is added every 3 seconds if entry (0,0) is not blocked.
The idea was to use spritecollides to prevent sprites from stomping on each other.
It kind of worked (?)
'swarmOfSprites.bas
'to be run from jb/lb folder
nomainwin
loadbmp "smiley1", "sprites\smiley1.bmp"
loadbmp "smiley2", "sprites\smiley2.bmp"
loadbmp "smiley3", "sprites\smiley3.bmp"
loadbmp "smiley4", "sprites\smiley4.bmp"
loadbmp "landscape", "sprites\bg1.bmp"
WindowHeight = 300
WindowWidth = 400
'graphicbox #wg, 0, 0, 400, 300
open "Swarm of sprites" for graphics_nf_nsb as #wg
#wg "trapclose [quit]; down"
'#wg "set 1 1"
'#wg "set 1 2" ;transparent pixel
'#wg "getbmp pixel 1 1 1 2"
''bmpsave "pixel", "pixel.bmp"
'print #wg, "addsprite pixel pixel"
print #wg, "background landscape";
N=0
gosub [addNew]
'print #wg, "addsprite smiley smiley1 smiley2 smiley3 smiley4";
'cx=150:cy=100
'print #wg, "spritexy smiley " ;cx;" ";cy
'#wg, "spritescale smiley 200"
#wg,"when mouseMove [movePixel]"
timer 50, [cycle]
wait
[addNew]
N=N+1
name$="smiley";right$("";100+N,2)
randSpr$="smiley";(int(rnd(0)*4)+1)
#wg, "addsprite ";name$;" ";randSpr$
'do not add if place is occupied
#wg, "spritecollides ";name$;" list$"
if list$<>"" then 'remove
#wg, "removesprite ";name$
N=N-1
end if
return
[movePixel]
'just a place for MouseX; MouseY to be updated
wait
[cycle]
k=k+1
if k mod 30 = 0 then gosub [addNew]
for i = 1 to N
name$="smiley";right$("";100+i,2)
#wg, "spritexy? ";name$;" x y"
dx=MouseX-x-16
dy=MouseY-y-16
d=sqr(dx*dx+dy*dy)
if d = 0 then [skip]
dx = int(dx*3/d)
dy = int(dy*3/d)
'print dx, dy
#wg, "spritexy ";name$;" ";x+2*dx;" ";y+2*dy
#wg, "spritecollides ";name$;" list$"
bad = (list$<>"")
if bad then #wg, "spritexy ";name$;" ";x;" ";y 'put back
[skip]
next
#wg "drawsprites"
#wg "place 370 20"
#wg "\";N
wait
[quit]
timer 0
close #wg
end