Skip to main content
guest
Join
|
Help
|
Sign In
Liberty BASIC Community Wiki
Home
guest
|
Join
|
Help
|
Sign In
Wiki Home
Recent Changes
Pages and Files
Members
Home
Liberty BASIC FAQ
Contests
Tutorials
Science
Shared Code
Tips
DLLs
PublicDomainSprites
Member Pages
Links
Sandbox
asteriods 2
Edit
0
7
…
0
Tags
No tags
Notify
RSS
Backlinks
Source
Print
Export (PDF)
Older Version
Newer Version
bluatigro
Jul 21, 2010
Highlight Changes
(
Deleted
,
Inserted
)
View WikiText
version 21 jul 2010
[[code]WindowWidth = DisplayWidthWindowHeight = DisplayHeightglobal winx , winywinx = WindowWidthwiny = WindowHeightglobal px , py , pst , lastkey$ , pi , q , d , joyYN$ , firetelglobal points , lives , state , ufohasfired , level , ufostglobal true , falseglobal sndPlayerFire$ , sndPlayerWasHit$ , sndRockWasHit$global sndUfoWasHit$ , sndUfoFlie$global notjetactif , flies , washitnotjetactif = 0flies = 1washit = 2global rockmax , ufomaxdim rockdx( 8 ) , rockdy( 8 ) , rockst( 8 )false = 0true = not( false )pi = atn( 1 ) * 4level = 0for i = 0 to 31loadbmp "p";i , DefaultDir$ + "\BMP\player" + nr$( i ) + ".bmp"anim$ = anim$ + " p";inext iloadbmp "fire" , DefaultDir$ + "\BMP\dot.bmp"loadbmp "rock" , DefaultDir$ + "\BMP\rock.bmp"loadbmp "ufo" , DefaultDir$ + "\BMP\ufo.bmp"loadbmp "star" , DefaultDir$ + "\BMP\star.bmp"notice chr$( 13 ) _+ "Blua tigro presents :" + chr$( 13 ) _+ "ASTERIODS ." + chr$( 13 ) _+ "use cursor keys" + chr$( 13 ) _+ "to move your ship" + chr$( 13 ) _+ "spacebar : fire ." + chr$( 13 ) _+ "[esc] : quit game ." + chr$( 13 ) _+ "rock : 2 points ." + chr$( 13 ) _+ "ufo : 7 points ."readjoystick 1if joy1x > 2 thenconfirm chr$( 13 ) _+ "Joystick detected . " + chr$( 13 ) _+ "Use joystick ?" ; joyYN$end if''graphicbox #m.g , 0 , 0 , winx , winynomainwinopen "asteriods" for graphics as #m#m "trapclose [quit]"#m "when characterInput [key]"#m "fill black"#m "backcolor white"#m "color white"#m "getbmp back 0 0 " ; winx ; " " ; winy#m "background back"for i = 0 to 100#m "addsprite star" ; i ; " star"#m "spritexy star"; i ; " " _; rnd( 0 ) * winx ; " " ; rnd( 0 ) * winy#m "spritescale star"; i ; " " ; rnd( 0 ) ^ 3 * 100#m "spritemovexy star" ; i ; " 0 1"next ifor i = 0 to 4#m "addsprite live" ; i ; " p" ; 0#m "spritexy live" ; i ; " " ; i * 50 ; " " ; winy - 50#m "spritescale live"; i ; " 50"next ifor i = 0 to 20#m "addsprite playerfire" ; i ; " fire"#m "spritexy playerfire" ; i ; " -100 -100"next ifor i = 0 to 7#m "addsprite rock" ; i ; " rock"next i#m "spritescale rock0 100"#m "spritescale rock1 70"#m "spritescale rock2 70"#m "spritescale rock3 50"#m "spritescale rock4 50"#m "spritescale rock5 50"#m "spritescale rock6 50"#m "addsprite ufo ufo"#m "addsprite ufofire fire"#m "setfocus"#m "addsprite player " ; anim$#m "spritexy player " ; px ; " " ; pycall nextlevelcall drawpointstimer 40 , [tmr]waitfunction nr$( no )nr$ = right$( "00" + str$( no ) , 2 )end function[tmr]q = q - 1if q < 0 thenq = int( rnd( 0 ) * 20 )d = int( rnd( 0 ) * 3 )end ifif joyYN$ = "yes" thenif joy1x < 256 * 256 / 3 thenpst = ( pst + 1 )if pst > 31 then pst = 0end ifif joy1x > 256 * 256 * 2 / 3 thenpst = ( pst - 1 )if pst < 0 then pst = 31end ifif joy1y < 256 * 256 / 3 thenpx = ( px - sin( strad( pst ) ) * 5 )if px < -100 then px = winxif px > winx then px = -100py = ( py - cos( strad( pst ) ) * 5 )if py < -100 then py = winyif py > winy then py = -100end ifif joy1y > 256 * 256 * 2 / 3 then''here i wil place a hyperjump in the furtureend ifelseselect case lower$( lastkey$ )case chr$( _VK_LEFT )pst = ( pst + 1 )if pst > 32 then pst = 0case chr$( _VK_RIGHT )pst = ( pst - 1 )if pst < 0 then pst = 32case chr$( _VK_UP )px = ( px - sin( strad( pst ) ) * 5 )if px < -100 then px = winxif px > winx then px = -100py = ( py - cos( strad( pst ) ) * 5 )if py < -100 then py = winyif py > winy then py = -100case chr$( _VK_DOWN )''hyperjumpcase chr$( 27 ) ''escapegoto [quit]waitcase " "#m "spritexy playerfire" ; firetel ; " " _; px - 16 - sin( strad( pst ) ) * 45 ; " " _; py - 16 - cos( strad( pst ) ) * 45#m "spritemovexy playerfire" ; firetel ; " " _; sin( strad( pst ) ) * -6 ; " " _; cos( strad( pst ) ) * -6firetel = firetel + 1if firetel > 20 then firetel = 0end selectend iflastkey$ = ""#m "spritexy player " ; px - 50 ; " " ; py - 50#m "spriteimage player p" ; pstfor i = 0 to 10#m "spritexy? playerfire" ; i ; " x y"if x < -100 or x > winx + 100 _or y < -100 or y > winy + 100 then#m "spritemovexy playerfire" ; i ; " 0 0"end ifnext i#m "spritexy? ufo ufox ufoy"if ufox < -100 thenufox = winxufohasfired = falsestate = rnd( 0 ) * ( winx / 2 ) + winx / 4 - 35end ifstate = state - 1if state < 0 and not( ufohasfired ) thenufohasfired = truedx = px - ufoxdy = py - ufoyaf = sqr( dx ^ 2 + dy ^ 2 ) + 1#m "spritexy ufofire " ; ufox ; " " ; ufoy#m "spritemovexy ufofire " ; dx / af * 6 ; " " ; dy / af * 6end if#m "spritexy? ufofire x y"if x < -100 then #m "spritemovexy ufofire 0 0"if x > winx then #m "spritemovexy ufofire 0 0"if y < -100 then #m "spritemovexy ufofire 0 0"if y > winy then #m "spritemovexy ufofire 0 0"#m "spritexy ufo " ; ufox ; " " ; ufoyfor i = 0 to 6#m "spritexy? rock"; i ; " x y"if x < -100 then x = winxif x > winx then x = -100if y < -100 then y = winyif y > winy then y = -100#m "spritexy rock" ; i ; " " ; x ; " " ; ynext i''colisiondetecion and respons#m "spritecollides player playerhit$"if instr( playerhit$ , "rock" ) <> 0 _or instr( playerhit$ , "ufo" ) <> 0 thenlives = lives - 1if lives < 0 thencall gameoverelsecall resetsceneend ifend if#m "spritecollides rock0 rockhit$"if instr( rockhit$ , "playerfire" ) _and rockst( 0 ) = flies thenpoint = point + 1call rocksplit 0 , 1 , 2end iffor i = 1 to 2#m "spritecollides rock" ; i ; " rockhit$"if instr( rockhit$ , "playerfire" ) _and rockst( i ) = flies thenpoint = point + 2if i = 1 thencall rocksplit 1 , 3 , 4elsecall rocksplit 2 , 5 , 6end ifend ifnext ifor i = 3 to 6#m "spritecollides rock" ; i ; " rockhit$"if instr( rockhit$ , "playerfire" ) _and rockst( 0 ) = flies thenpoint = point + 4rockst( i ) = washit#m "spritexy rock" ; i ; " -100 -100"#m "spritemove rock" ; i ; " 0 0"end ifnext i#m "spritecollides ufo ufohit$"if instr( ufohit$ , "playerfire" ) thenpoints = points + 7#m "spritexy ufo " ; winx ; " " _; rnd( 0 ) * ( winy / 2 ) + winy / 4 - 50state = rnd( 0 ) * ( winx / 2 ) + winx / 4ufohasfired = falsecall drawpointsend iffor i = 0 to 100#m "spritexy? star" ; i ; " x y"if y > winy then#m "spritexy star" ; i ; " " ; rnd( 0 ) * winx ; " " ; -30#m "spritescale star" ; i ; " " _; rnd( 0 ) ^ 3 * 100end ifnext iallwashit = trueif ufost <> washit then allwashit = falsefor i = 0 to 6if rock( i ) <> washit then allwashit = falsenext iif allwashit then call nextlevel#m "drawsprites"waitsub resetgamelevel = 0lives = 3points = 0ufohasfired = falsestate = rnd( 0 ) * ( winx / 2 ) + winx / 4call resetsceneend subsub resetscenetimer 0call drawpointsfor i = 1 to 4#m "spritexy live" ; i ; " " ; i * 50 ; " " ; winy - 50next ifor i = 0 to 20#m "spritexy playerfire" ; i ; " -100 -100"next i#m "spritexy ufofire -100 -100"px = winx / 2py = winy / 2#m "spritexy player " ; px ; " " ; pytimer 40 , [tmr]end subsub nextlevelfor i = 0 to 7rockst( i ) = notjetactifnext irockst( 0 ) = flies#m "spritexy rock0 -100 " ; rnd( 0 ) * winy - 50#m "spritemovexy rock0 " ; x ; " " ; yufost = flieslevel = level + 1state = rnd( 0 ) * winx / 2 + winx / 2 - 50#m "spritexy ufo " ; winx ; " " ; rnd(0) * winy/2 + winy/4 - 35call resetsceneend subsub gameovernotice chr$( 13 ) _+ "GAME OVER !!!"goto [quit]end subsub rocksplit no , a , bdx = rockdx( no )dy = rockdy( no )rockst( no ) = washit#m "spritexy? rock" ; no ; " x y"#m "spritexy rock" ; no ; " -100 -100"#m "spritemovexy rock" ; no ; " 0 0"#m "spritexy rock" ; a ; " " ; x ; " " ; yrockst( a ) = fliescall rotate dx , dy , 120#m "spritemove rock" ; a ; " " ; dx ; " " ; dy#m "spritexy rock" ; b ; " " ; x ; " " ; yrockst( b ) = fliescall rotate dx , dy , 120#m "spritemove rock" ; b ; " " ; dx ; " " ; dyend subsub rotate byref k , byref l , degs = sin( deg * pi / 180 )c = cos( deg * pi / 180 )hk = k * c - l * shl = l * s + l * ck = hk : l = lhend subsub drawpoints#m "fill black"#m "font Corier_New 50 bold"#m "color green"#m "backcolor black"#m "goto 0 50"#m "\POINTS : " ; right$( " " + str$( points ) , 8 )#m "goto 200 100"#m "\LEVEL : " ; level#m "getbmp back 0 0 " ; winx ; " " ; winy#m "background back"for i = 0 to lives#m "spritexy live" ; i ; " " ; i * 50 ; " " ; 50next ifor i = lives to 3#m "spritexy live" ; i ; " -100 -100"next iend subfunction strad( st )strad = st * pi / 16end function[key]lastkey$ = right$( Inkey$ , 1 )wait[quit]unloadbmp "fire"unloadbmp "ufo"unloadbmp "star"for i = 0 to 31unloadbmp "p" ; inext iclose #mend[code]]
Turn off "Getting Started"
Home
...
Loading...
[[code]WindowWidth = DisplayWidthWindowHeight = DisplayHeightglobal winx , winywinx = WindowWidthwiny = WindowHeightglobal px , py , pst , lastkey$ , pi , q , d , joyYN$ , firetelglobal points , lives , state , ufohasfired , level , ufostglobal true , falseglobal sndPlayerFire$ , sndPlayerWasHit$ , sndRockWasHit$global sndUfoWasHit$ , sndUfoFlie$global notjetactif , flies , washitnotjetactif = 0flies = 1washit = 2global rockmax , ufomaxdim rockdx( 8 ) , rockdy( 8 ) , rockst( 8 )false = 0true = not( false )pi = atn( 1 ) * 4level = 0for i = 0 to 31loadbmp "p";i , DefaultDir$ + "\BMP\player" + nr$( i ) + ".bmp"anim$ = anim$ + " p";inext iloadbmp "fire" , DefaultDir$ + "\BMP\dot.bmp"loadbmp "rock" , DefaultDir$ + "\BMP\rock.bmp"loadbmp "ufo" , DefaultDir$ + "\BMP\ufo.bmp"loadbmp "star" , DefaultDir$ + "\BMP\star.bmp"notice chr$( 13 ) _+ "Blua tigro presents :" + chr$( 13 ) _+ "ASTERIODS ." + chr$( 13 ) _+ "use cursor keys" + chr$( 13 ) _+ "to move your ship" + chr$( 13 ) _+ "spacebar : fire ." + chr$( 13 ) _+ "[esc] : quit game ." + chr$( 13 ) _+ "rock : 2 points ." + chr$( 13 ) _+ "ufo : 7 points ."readjoystick 1if joy1x > 2 thenconfirm chr$( 13 ) _+ "Joystick detected . " + chr$( 13 ) _+ "Use joystick ?" ; joyYN$end if''graphicbox #m.g , 0 , 0 , winx , winynomainwinopen "asteriods" for graphics as #m#m "trapclose [quit]"#m "when characterInput [key]"#m "fill black"#m "backcolor white"#m "color white"#m "getbmp back 0 0 " ; winx ; " " ; winy#m "background back"for i = 0 to 100#m "addsprite star" ; i ; " star"#m "spritexy star"; i ; " " _; rnd( 0 ) * winx ; " " ; rnd( 0 ) * winy#m "spritescale star"; i ; " " ; rnd( 0 ) ^ 3 * 100#m "spritemovexy star" ; i ; " 0 1"next ifor i = 0 to 4#m "addsprite live" ; i ; " p" ; 0#m "spritexy live" ; i ; " " ; i * 50 ; " " ; winy - 50#m "spritescale live"; i ; " 50"next ifor i = 0 to 20#m "addsprite playerfire" ; i ; " fire"#m "spritexy playerfire" ; i ; " -100 -100"next ifor i = 0 to 7#m "addsprite rock" ; i ; " rock"next i#m "spritescale rock0 100"#m "spritescale rock1 70"#m "spritescale rock2 70"#m "spritescale rock3 50"#m "spritescale rock4 50"#m "spritescale rock5 50"#m "spritescale rock6 50"#m "addsprite ufo ufo"#m "addsprite ufofire fire"#m "setfocus"#m "addsprite player " ; anim$#m "spritexy player " ; px ; " " ; pycall nextlevelcall drawpointstimer 40 , [tmr]waitfunction nr$( no )nr$ = right$( "00" + str$( no ) , 2 )end function[tmr]q = q - 1if q < 0 thenq = int( rnd( 0 ) * 20 )d = int( rnd( 0 ) * 3 )end ifif joyYN$ = "yes" thenif joy1x < 256 * 256 / 3 thenpst = ( pst + 1 )if pst > 31 then pst = 0end ifif joy1x > 256 * 256 * 2 / 3 thenpst = ( pst - 1 )if pst < 0 then pst = 31end ifif joy1y < 256 * 256 / 3 thenpx = ( px - sin( strad( pst ) ) * 5 )if px < -100 then px = winxif px > winx then px = -100py = ( py - cos( strad( pst ) ) * 5 )if py < -100 then py = winyif py > winy then py = -100end ifif joy1y > 256 * 256 * 2 / 3 then''here i wil place a hyperjump in the furtureend ifelseselect case lower$( lastkey$ )case chr$( _VK_LEFT )pst = ( pst + 1 )if pst > 32 then pst = 0case chr$( _VK_RIGHT )pst = ( pst - 1 )if pst < 0 then pst = 32case chr$( _VK_UP )px = ( px - sin( strad( pst ) ) * 5 )if px < -100 then px = winxif px > winx then px = -100py = ( py - cos( strad( pst ) ) * 5 )if py < -100 then py = winyif py > winy then py = -100case chr$( _VK_DOWN )''hyperjumpcase chr$( 27 ) ''escapegoto [quit]waitcase " "#m "spritexy playerfire" ; firetel ; " " _; px - 16 - sin( strad( pst ) ) * 45 ; " " _; py - 16 - cos( strad( pst ) ) * 45#m "spritemovexy playerfire" ; firetel ; " " _; sin( strad( pst ) ) * -6 ; " " _; cos( strad( pst ) ) * -6firetel = firetel + 1if firetel > 20 then firetel = 0end selectend iflastkey$ = ""#m "spritexy player " ; px - 50 ; " " ; py - 50#m "spriteimage player p" ; pstfor i = 0 to 10#m "spritexy? playerfire" ; i ; " x y"if x < -100 or x > winx + 100 _or y < -100 or y > winy + 100 then#m "spritemovexy playerfire" ; i ; " 0 0"end ifnext i#m "spritexy? ufo ufox ufoy"if ufox < -100 thenufox = winxufohasfired = falsestate = rnd( 0 ) * ( winx / 2 ) + winx / 4 - 35end ifstate = state - 1if state < 0 and not( ufohasfired ) thenufohasfired = truedx = px - ufoxdy = py - ufoyaf = sqr( dx ^ 2 + dy ^ 2 ) + 1#m "spritexy ufofire " ; ufox ; " " ; ufoy#m "spritemovexy ufofire " ; dx / af * 6 ; " " ; dy / af * 6end if#m "spritexy? ufofire x y"if x < -100 then #m "spritemovexy ufofire 0 0"if x > winx then #m "spritemovexy ufofire 0 0"if y < -100 then #m "spritemovexy ufofire 0 0"if y > winy then #m "spritemovexy ufofire 0 0"#m "spritexy ufo " ; ufox ; " " ; ufoyfor i = 0 to 6#m "spritexy? rock"; i ; " x y"if x < -100 then x = winxif x > winx then x = -100if y < -100 then y = winyif y > winy then y = -100#m "spritexy rock" ; i ; " " ; x ; " " ; ynext i''colisiondetecion and respons#m "spritecollides player playerhit$"if instr( playerhit$ , "rock" ) <> 0 _or instr( playerhit$ , "ufo" ) <> 0 thenlives = lives - 1if lives < 0 thencall gameoverelsecall resetsceneend ifend if#m "spritecollides rock0 rockhit$"if instr( rockhit$ , "playerfire" ) _and rockst( 0 ) = flies thenpoint = point + 1call rocksplit 0 , 1 , 2end iffor i = 1 to 2#m "spritecollides rock" ; i ; " rockhit$"if instr( rockhit$ , "playerfire" ) _and rockst( i ) = flies thenpoint = point + 2if i = 1 thencall rocksplit 1 , 3 , 4elsecall rocksplit 2 , 5 , 6end ifend ifnext ifor i = 3 to 6#m "spritecollides rock" ; i ; " rockhit$"if instr( rockhit$ , "playerfire" ) _and rockst( 0 ) = flies thenpoint = point + 4rockst( i ) = washit#m "spritexy rock" ; i ; " -100 -100"#m "spritemove rock" ; i ; " 0 0"end ifnext i#m "spritecollides ufo ufohit$"if instr( ufohit$ , "playerfire" ) thenpoints = points + 7#m "spritexy ufo " ; winx ; " " _; rnd( 0 ) * ( winy / 2 ) + winy / 4 - 50state = rnd( 0 ) * ( winx / 2 ) + winx / 4ufohasfired = falsecall drawpointsend iffor i = 0 to 100#m "spritexy? star" ; i ; " x y"if y > winy then#m "spritexy star" ; i ; " " ; rnd( 0 ) * winx ; " " ; -30#m "spritescale star" ; i ; " " _; rnd( 0 ) ^ 3 * 100end ifnext iallwashit = trueif ufost <> washit then allwashit = falsefor i = 0 to 6if rock( i ) <> washit then allwashit = falsenext iif allwashit then call nextlevel#m "drawsprites"waitsub resetgamelevel = 0lives = 3points = 0ufohasfired = falsestate = rnd( 0 ) * ( winx / 2 ) + winx / 4call resetsceneend subsub resetscenetimer 0call drawpointsfor i = 1 to 4#m "spritexy live" ; i ; " " ; i * 50 ; " " ; winy - 50next ifor i = 0 to 20#m "spritexy playerfire" ; i ; " -100 -100"next i#m "spritexy ufofire -100 -100"px = winx / 2py = winy / 2#m "spritexy player " ; px ; " " ; pytimer 40 , [tmr]end subsub nextlevelfor i = 0 to 7rockst( i ) = notjetactifnext irockst( 0 ) = flies#m "spritexy rock0 -100 " ; rnd( 0 ) * winy - 50#m "spritemovexy rock0 " ; x ; " " ; yufost = flieslevel = level + 1state = rnd( 0 ) * winx / 2 + winx / 2 - 50#m "spritexy ufo " ; winx ; " " ; rnd(0) * winy/2 + winy/4 - 35call resetsceneend subsub gameovernotice chr$( 13 ) _+ "GAME OVER !!!"goto [quit]end subsub rocksplit no , a , bdx = rockdx( no )dy = rockdy( no )rockst( no ) = washit#m "spritexy? rock" ; no ; " x y"#m "spritexy rock" ; no ; " -100 -100"#m "spritemovexy rock" ; no ; " 0 0"#m "spritexy rock" ; a ; " " ; x ; " " ; yrockst( a ) = fliescall rotate dx , dy , 120#m "spritemove rock" ; a ; " " ; dx ; " " ; dy#m "spritexy rock" ; b ; " " ; x ; " " ; yrockst( b ) = fliescall rotate dx , dy , 120#m "spritemove rock" ; b ; " " ; dx ; " " ; dyend subsub rotate byref k , byref l , degs = sin( deg * pi / 180 )c = cos( deg * pi / 180 )hk = k * c - l * shl = l * s + l * ck = hk : l = lhend subsub drawpoints#m "fill black"#m "font Corier_New 50 bold"#m "color green"#m "backcolor black"#m "goto 0 50"#m "\POINTS : " ; right$( " " + str$( points ) , 8 )#m "goto 200 100"#m "\LEVEL : " ; level#m "getbmp back 0 0 " ; winx ; " " ; winy#m "background back"for i = 0 to lives#m "spritexy live" ; i ; " " ; i * 50 ; " " ; 50next ifor i = lives to 3#m "spritexy live" ; i ; " -100 -100"next iend subfunction strad( st )strad = st * pi / 16end function[key]lastkey$ = right$( Inkey$ , 1 )wait[quit]unloadbmp "fire"unloadbmp "ufo"unloadbmp "star"for i = 0 to 31unloadbmp "p" ; inext iclose #mend[code]]