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