[code] version 21 jul 2010
WindowWidth = DisplayWidth WindowHeight = DisplayHeight global winx , winy winx = WindowWidth winy = WindowHeight global [[code]WindowWidth = DisplayWidthWindowHeight = DisplayHeightglobal winx , winywinx = WindowWidthwiny = WindowHeightglobal px , py , pst , lastkey$ , pi , q , d , joyYN$ , firetel global firetelglobal points , lives , state , ufohasfired , level , ufost global ufostglobal true , false global falseglobal sndPlayerFire$ , sndPlayerWasHit$ , sndRockWasHit$ global sndRockWasHit$global sndUfoWasHit$ , sndUfoFlie$ global sndUfoFlie$global notjetactif , flies , washit notjetactif = 0 flies = 1 washit = 2 global washitnotjetactif = 0flies = 1washit = 2global rockmax , ufomax dim ufomaxdim rockdx( 8 ) , rockdy( 8 ) , rockst( 8 ) false = 0 true )false = 0true = not( false ) pi )pi = atn( 1 ) * 4 level = 0 call nextlevel for 4level = 0for i = 0 to 31 loadbmp 31loadbmp "p";i , DefaultDir$ + "\BMP\player" + nr$( i ) + ".bmp" ".bmp"anim$ = anim$ = anim$ + " p";i next i loadbmp + " p";inext iloadbmp "fire" , DefaultDir$ + "\BMP\dot.bmp" loadbmp "\BMP\dot.bmp"loadbmp "rock" , DefaultDir$ + "\BMP\rock.bmp" loadbmp "\BMP\rock.bmp"loadbmp "ufo" , DefaultDir$ + "\BMP\ufo.bmp" loadbmp "\BMP\ufo.bmp"loadbmp "star" , DefaultDir$ + "\BMP\star.bmp" notice "\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 1 if ."readjoystick 1if joy1x > 2 then confirm thenconfirm chr$( 13 ) _ + _+ "Joystick detected . " + chr$( 13 ) _ + _+ "Use joystick ?" ; joyYN$ end if ''graphicbox joyYN$end if''graphicbox #m.g , 0 , 0 , winx , winy nomainwin open winynomainwinopen "asteriods" for graphics as #m #m #m#m "trapclose [quit]" #m [quit]"#m "when characterInput [key]" #m [key]"#m "fill black" #m black"#m "backcolor white" #m white"#m "color white" #m white"#m "getbmp back 0 0 " ; winx ; " " ; winy #m winy#m "background back" for back"for i = 0 to 100 #m 100#m "addsprite star" ; i ; " star" #m star"#m "spritexy star"; i ; " " _ ; _; rnd( 0 ) * winx ; " " ; rnd( 0 ) * winy #m winy#m "spritescale star"; i ; " " ; rnd( 0 ) ^ 3 * 100 #m 100#m "spritemovexy star" ; i ; " 0 1" next i for 1"next ifor i = 0 to 4 #m 4#m "addsprite live" ; i ; " p" ; 0 #m 0#m "spritexy live" ; i ; " " ; i * 50 ; " " ; winy - 50 #m 50#m "spritescale live"; i ; " 50" next i for 50"next ifor i = 0 to 20 #m 20#m "addsprite playerfire" ; i ; " fire" #m fire"#m "spritexy playerfire" ; i ; " -100 -100" next i for -100"next ifor i = 0 to 7 #m 7#m "addsprite rock" ; i ; " rock" next i #m rock"next i#m "spritescale rock0 100" #m 100"#m "spritescale rock1 70" #m 70"#m "spritescale rock2 70" #m 70"#m "spritescale rock3 50" #m 50"#m "spritescale rock4 50" #m 50"#m "spritescale rock5 50" #m 50"#m "spritescale rock6 50" #m 50"#m "addsprite ufo ufo" #m ufo"#m "addsprite ufofire fire" #m "setfocus" #m fire"#m "setfocus"#m "addsprite player " ; anim$ #m anim$#m "spritexy player " ; px ; " " ; py call drawpoints timer pycall nextlevelcall drawpointstimer 40 , [tmr] wait function [tmr]waitfunction nr$( no ) nr$ )nr$ = right$( "00" + str$( no ) , 2 ) end function [tmr] )end function[tmr]q = q = q - 1 if - 1if q < 0 then q thenq = int( rnd( 0 ) * 20 ) d )d = int( rnd( 0 ) * 3 ) end if if )end ifif joyYN$ = "yes" then if thenif joy1x < 256 * 256 / 3 then pst thenpst = ( pst + 1 ) if )if pst > 31 then pst = 0 end if if 0end ifif joy1x > 256 * 256 * 2 / 3 then pst thenpst = ( pst - 1 ) if )if pst < 0 then pst = 31 end if if 31end ifif joy1y < 256 * 256 / 3 then px thenpx = ( px - sin( strad( pst ) ) * 5 ) if )if px < -100 then px = winx if winxif px > winx then px = -100 py -100py = ( py - cos( strad( pst ) ) * 5 ) if )if py < -100 then py = winy if winyif py > winy then py = -100 end if if -100end ifif joy1y > 256 * 256 * 2 / 3 then ''here then''here i wil place a hyperjump in the furture end if else select furtureend ifelseselect case lower$( lastkey$ ) case )case chr$( _VK_LEFT ) pst )pst = ( pst + 1 ) if )if pst > 32 then pst = 0 case 0case chr$( _VK_RIGHT ) pst )pst = ( pst - 1 ) if )if pst < 0 then pst = 32 case 32case chr$( _VK_UP ) px )px = ( px - sin( strad( pst ) ) * 5 ) if )if px < -100 then px = winx if winxif px > winx then px = -100 py -100py = ( py - cos( strad( pst ) ) * 5 ) if )if py < -100 then py = winy if winyif py > winy then py = -100 case -100case chr$( _VK_DOWN ) ''hyperjump case )''hyperjumpcase chr$( 27 ) ''escape goto [quit] wait case " " #m ''escapegoto [quit]waitcase " "#m "spritexy playerfire" ; firetel ; " " _ ; _; px - 16 - sin( strad( pst ) ) * 45 ; " " _ ; _; py - 16 - cos( strad( pst ) ) * 45 #m 45#m "spritemovexy playerfire" ; firetel ; " " _ ; _; sin( strad( pst ) ) * -6 ; " " _ ; _; cos( strad( pst ) ) * -6 -6firetel = firetel = firetel + 1 if + 1if firetel > 20 then firetel = 0 end select end if lastkey$ = "" #m 0end selectend iflastkey$ = ""#m "spritexy player " ; px - 50 ; " " ; py - 50 #m 50#m "spriteimage player p" ; pst for pstfor i = 0 to 10 #m 10#m "spritexy? playerfire" ; i ; " x y" if y"if x < -100 or x > winx + 100 _ or _or y < -100 or y > winy + 100 then #m then#m "spritemovexy playerfire" ; i ; " 0 0" end if next i #m 0"end ifnext i#m "spritexy? ufo ufox ufoy" if ufoy"if ufox < -100 then ufox = winx ufohasfired = false thenufox = winxufohasfired = falsestate = rnd( 0 ) * ( winx / 2 ) + winx / 4 - 35end ifstate = state = rnd( 0 ) * ( winx / 2 ) + winx / 4 - 35 end if state = state - 1 if - 1if state < 0 and not( ufohasfired ) then ufohasfired = true dx thenufohasfired = truedx = px - ufox dy ufoxdy = py - ufoy af ufoyaf = sqr( dx ^ 2 + dy ^ 2 ) #m + 1#m "spritexy ufofire " ; ufox ; " " ; ufoy ufoy#m "spritemovexy ufofire " ; dx / af * 6 ; " " ; dy / af * 6end if#m "spritexy? ufofire x y"if x < -100 then #m "spritemovexy ufofire " ; dx / af * 6 ; " " ; dy / af * 6 end if 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? ufofire rock"; i ; " x y" if y"if x < -100 then #m "spritemovexy ufofire 0 0" if x = winxif x > winx then #m "spritemovexy ufofire 0 0" if x = -100if y < -100 then #m "spritemovexy ufofire 0 0" if y = winyif y > winy then #m "spritemovexy ufofire 0 0" #m "spritexy 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 " ; ufox ; " " ; ufoy for 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 6 #m 100#m "spritexy? rock"; star" ; i ; " x y" if x < -100 then x = winx if x > winx then x = -100 if y < -100 then y = winy if y"if y > winy then y = -100 #m "spritexy rock" ; i ; " " ; x ; " " ; y next i ''colisiondetecion and respons #m "spritecollides player playerhit$" if instr( playerhit$ , "rock" ) <> 0 _ or instr( playerhit$ , "ufo" ) <> 0 then lives = lives - 1 if lives < 0 then call gameover else call resetscene end if end if #m "spritecollides rock0 rockhit$" if instr( rockhit$ , "playerfire" ) _ and rockst( 0 ) = flies then point = point + 1 call rocksplit 0 , 1 , 2 end if for i = 1 to 2 #m "spritecollides rock" ; i ; " rockhit$" if instr( rockhit$ , "playerfire" ) _ and rockst( i ) = flies then point = point + 2 if i = 1 then call rocksplit 1 , 3 , 4 else call rocksplit 2 , 5 , 6 end if end if next i for i = 3 to 6 #m "spritecollides rock" ; i ; " rockhit$" if instr( rockhit$ , "playerfire" ) _ and rockst( 0 ) = flies then point = point + 4 rockst( i ) = washit #m "spritexy rock" ; i ; " -100 -100" #m "spritemove rock" ; i ; " 0 0" end if next i #m "spritecollides ufo ufohit$" if instr( ufohit$ , "playerfire" ) then points = points + 7 #m "spritexy ufo " ; winx ; " " _ then#m "spritexy star" ; i ; " " ; rnd( 0 ) * ( winy / 2 ) + winy / 4 - 50 state = rnd( 0 ) * ( winx / 2 ) + winx / 4 ufohasfired = false call drawpoints end if for i = 0 to 100 #m "spritexy? star" ; i ; " x y" if y > winy then #m "spritexy star" ; i ; " " ; rnd( 0 ) * winx ; " " ; -30 #m winx ; " " ; -30#m "spritescale star" ; i ; " " _ ; _; rnd( 0 ) ^ 3 * 100 end if next i allwashit = true if 100end ifnext iallwashit = trueif ufost <> washit then allwashit = false for falsefor i = 0 to 6 if 6if rock( i ) <> washit then allwashit = false next i if falsenext iif allwashit then call nextlevel #m "drawsprites" wait sub resetgame level = 0 lives = 3 points = 0 ufohasfired = false state nextlevel#m "drawsprites"waitsub resetgamelevel = 0lives = 3points = 0ufohasfired = falsestate = rnd( 0 ) * ( winx / 2 ) + winx / 4 call resetscene end sub sub resetscene timer 0 call drawpoints for 4call resetsceneend subsub resetscenetimer 0call drawpointsfor i = 1 to 4 #m 4#m "spritexy live" ; i ; " " ; i * 50 ; " " ; winy - 50 next i for 50next ifor i = 0 to 20 #m 20#m "spritexy playerfire" ; i ; " -100 -100" next i #m -100"next i#m "spritexy ufofire -100 -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 py = winy + winx / 2 #m "spritexy player " ; px ; " " ; py timer 40 , [tmr] end sub sub nextlevel for i = 0 to 7 rockst( i ) = notjetactif next i rockst( 0 ) = flies ufost = flies level = level + 1 #m - 50#m "spritexy ufo " ; winx ; " " ; rnd(0) * winy/2 + winy/4 - 35 call resetscene end sub sub gameover notice 35call resetsceneend subsub gameovernotice chr$( 13 ) _ + _+ "GAME OVER !!!" goto [quit] end sub sub !!!"goto [quit]end subsub rocksplit no , a , b dx bdx = rockdx( no ) dy )dy = rockdy( no ) rockst( )rockst( no ) = washit #m washit#m "spritexy? rock" ; no ; " x y" #m y"#m "spritexy rock" ; no ; " -100 -100" #m -100"#m "spritemovexy rock" ; no ; " 0 0" #m 0"#m "spritexy rock" ; a ; " " ; x ; " " ; y rockst( yrockst( a ) = flies call fliescall rotate dx , dy , 120 #m 120#m "spritemove rock" ; a ; " " ; dx ; " " ; dy #m dy#m "spritexy rock" ; b ; " " ; x ; " " ; y rockst( yrockst( b ) = flies call fliescall rotate dx , dy , 120 #m 120#m "spritemove rock" ; b ; " " ; dx ; " " ; dy end sub sub dyend subsub rotate byref k , byref l , deg s degs = sin( deg * pi / 180 ) c )c = cos( deg * pi / 180 ) hk )hk = k * c - l * shl = l * s hl = + l * s + l * c k ck = hk : l = lh end sub sub drawpoints #m lhend subsub drawpoints#m "fill black" #m black"#m "font Corier_New 50 bold" #m bold"#m "color green" #m green"#m "backcolor black" #m black"#m "goto 0 50" #m 50"#m "\POINTS : " ; right$( " " + str$( points ) , 8 ) #m )#m "goto 200 100" #m 100"#m "\LEVEL : " ; level #m level#m "getbmp back 0 0 " ; winx ; " " ; winy #m winy#m "background back" for back"for i = 0 to lives #m lives#m "spritexy live" ; i ; " " ; i * 50 ; " " ; 50 next i for 50next ifor i = lives to 3 #m 3#m "spritexy live" ; i ; " -100 -100" next i end sub -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]]