News:

PlayBASIC2DLL V0.99 Revision I Commercial Edition released! - Convert PlayBASIC programs to super fast Machine Code. 

Main Menu

Play Basic Sprites Demo

Started by LemonWizard, August 16, 2009, 11:19:15 PM

Previous topic - Next topic

LemonWizard

This demo shows off a few things
1-it shows how a linear timer can be used, to time events. Sequentially.
2-yes I know the code is messy. it shows how to control different sprites, in a format involving them having a destination x and y coordinate.
The Squawks sprite gets a random destination of one of the 20 sprite x's or y's
it also shows how you can use timer based methods to control the scroll image command.
I haven't seen any playbasic demos yet that use these sorts of commands, or features..
So I thought it'd be interesting to show off.
*shrugs*
Be warned if you run it, it's pretty long, about five or ten minutes.

And here is a link to the low quality video of it running on my youtube: http://www.youtube.com/watch?v=EZ83lr7cK38





PlayBASIC Code: [Select]
; PROJECT : Project2
; AUTHOR : Tosharu
; CREATED : 8/16/2009
; EDITED : 8/16/2009
; ---------------------------------------------------------------------
waitkey
waitnokey


image=newfximage(32,32)
rendertoimage image
cls rgb(255,0,0) ;make a red square

rendertoscreen ;set the rendering process to the screen again

cls rgb(0,0,0)
wait 1 ;a wait command for possible cpu cool down?

sync ;sync the back buffer

dim spritesdata(20, 2) ;1=x 2=y
dim sprites(20) ;make 20 sprite array
for temp=1 to 20
sprites(temp)=newsprite( rnd(getscreenwidth() ), rnd( getscreenheight() ), image)
spritesdata(temp, 1)=rnd(getscreenwidth() )
spritesdata(temp, 2)=rnd( getscreenheight() )
next temp
yspeed=0
squawks=0
part1counter=1
ycounter=0
rl=0
dirx=0
diry=0
added=0
goto cont
squawkssetup:
squawkx=300
squawky=300
nextswitch=0
dim images(8, 2)
for temp=1 to 8
images(temp, 1)=loadnewfximage("right"+str$(temp)+".bmp")
rendertoimage images(temp, 1)
rgbcolor=point(1, 1)
imagemaskcolour images(temp, 1), rgbcolor
next temp
for temp=1 to 8
images(temp,2)=loadnewfximage("left"+str$(temp)+".bmp")
rendertoimage images(temp, 2)
rgbcolor=point(1,1)
imagemaskcolour images(temp, 2), rgbcolor
next temp
direction=2
counter=1
squawk=1
rendertoscreen
squawks=1

return


cont:

rendertoscreen
part1:
for temp=1 to 20
a=rnd(3)
b=rnd(3)
c=rnd(100)
d=rnd(100)
if c=>51 then a=neg(a)
if d=>51 then b=neg(b)
movesprite sprites(temp), a, b+yspeed
next temp


xx=rnd(5000)
if xx=>4000
rendertoimage image
cls rgb( rnd(255), rnd(255), rnd(255) )
rendertoscreen
endif

if part1counter=>1000
for temp=1 to 20
spritesdata(temp, 2)=spritesdata(temp, 2)-1
if spritesdata(temp, 2) >getscreenheight()-64 then spritesdata(temp, 2)=getscreenheight()-64
xspeed=rnd(10)
a=rnd(100)
if a=>51 then xspeed=neg(xspeed)
spritesdata(temp, 1)=spritesdata(temp, 1)
if spritesdata(temp, 1) <0 then spritesdata(temp, 1)=32
if spritesdata(temp, 1) >getscreenwidth() then spritesdata(temp)=getscreenwidth()-32
movesprite sprites(temp), xspeed, 3
spritesdata(temp, 2)=getspritey( sprites(temp) )
if spritesdata(temp, 2) >getscreenheight()-64
spritesdata(temp, 2)=getscreenheight()-128
positionsprite sprites(temp), spritesdata(temp, 1), spritesdata(temp, 2)
endif
next temp
endif

if part1counter >3000
ycounter=ycounter+1
yspeed=rnd(10)
yspeed=neg(yspeed)
if ycounter=>500
yspeed=rnd(10)
endif

if ycounter=>1000
ycounter=0
endif

endif


drawallsprites
print part1counter
sync
cls rgb(0,0,0)

part1counter=part1counter+1
if part1counter=>10000
part2counter=0
dim spritesdestination(20, 2)
for temp=1 to 20
spritesdestination(temp, 1)=rnd(getscreenwidth() )
spritesdestination(temp, 2)=rnd(getscreenheight() )
next temp
sprreset=0
goto part2
endif
goto part1


part2:
setcursor 200, 200
ink rgb(255, 255, 255)
print " "
print squawkdestinationx: print " squawks destination x"
print squawkdestinationy: print " squawks destination y"
print squawkx: print " squawks x"
print squawky: print " squawks y"
print "part 2 counter" : print part2counter
if squawks=0
squawksd=rnd(20)
if squawksd <1 then squawksd=1
Login required to view complete source code