GordonR
Jul 21, 2010
''version 21 jul 2010
' Joy1x and Joy1y changed by Gordon
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
global winx , winy
winx = WindowWidth
winy = WindowHeight
global px , py , pst , lastkey$ , pi , q , d , joyYN$ , firetel
global points , lives , state , ufohasfired , level , ufost
global true , false
global sndPlayerFire$ , sndPlayerWasHit$ , sndRockWasHit$
global sndUfoWasHit$ , sndUfoFlie$
global notjetactif , flies , washit
notjetactif = 0
flies = 1
washit = 2
global rockmax , ufomax
dim rockdx( 8 ) , rockdy( 8 ) , rockst( 8 )
false = 0
true = not( false )
pi = atn( 1 ) * 4
level = 0
for i = 0 to 31
loadbmp"p";i"p";i , DefaultDir$ +"\BMP\player""\BMP\player" + nr$( i ) +".bmp"".bmp"
anim$ = anim$ +" p";i" p";i
next i
loadbmp"fire""fire" , DefaultDir$ +"\BMP\dot.bmp""\BMP\dot.bmp"
loadbmp"rock""rock" , DefaultDir$ +"\BMP\rock.bmp""\BMP\rock.bmp"
loadbmp"ufo""ufo" , DefaultDir$ +"\BMP\ufo.bmp""\BMP\ufo.bmp"
loadbmp"star""star" , DefaultDir$ +"\BMP\star.bmp""\BMP\star.bmp"
notice chr$( 13 ) _
+"Blua"Blua tigro presents:":" + chr$( 13 ) _
+"ASTERIODS .""ASTERIODS ." + chr$( 13 ) _
+"use"use cursorkeys"keys" + chr$( 13 ) _
+"to"to move yourship"ship" + chr$( 13 ) _
+"spacebar"spacebar : fire."." + chr$( 13 ) _
+"[esc]"[esc] : quit game."." + chr$( 13 ) _
+"rock"rock : 2 points."." + chr$( 13 ) _
+"ufo"ufo : 7 points."."
readjoystick 1
if Joy1x > 2 then
confirm chr$( 13 ) _
+"Joystick"Joystick detected ."" + chr$( 13 ) _
+"Use"Use joystick?"?" ; joyYN$
end if
''graphicbox #m.g , 0 , 0 , winx , winy
nomainwin
open"asteriods""asteriods" for graphics as #m
#m"trapclose [quit]"#m "when"trapclose [quit]"
#m "when characterInput[key]"#m "fill black"#m "backcolor white"#m "color white"#m "getbmp[key]"
#m "fill black"
#m "backcolor white"
#m "color white"
#m "getbmp back 0 0" ; winx ; " "" ; winx ; " " ; winy
#m"background back""background back"
for i = 0 to 100
#m"addsprite star" ; i ; " star"#m "spritexy star"; i ; " ""addsprite star" ; i ; " star"
#m "spritexy star"; i ; " " _
; rnd( 0 ) * winx ;" "" " ; rnd( 0 ) * winy
#m"spritescale star"; i ; " ""spritescale star"; i ; " " ; rnd( 0 ) ^ 3 * 100
#m"spritemovexy star" ; i ; " 0 1""spritemovexy star" ; i ; " 0 1"
next i
for i = 0 to 4
#m"addsprite live" ; i ; " p" ; 0#m "spritexy live" ; i ; " ""addsprite live" ; i ; " p" ; 0
#m "spritexy live" ; i ; " " ; i * 50 ;" "" " ; winy - 50
#m"spritescale live"; i ; " 50""spritescale live"; i ; " 50"
next i
for i = 0 to 20
#m"addsprite playerfire" ; i ; " fire"#m "spritexy playerfire" ; i ; ""addsprite playerfire" ; i ; " fire"
#m "spritexy playerfire" ; i ; " -100-100"-100"
next i
for i = 0 to 7
#m"addsprite rock" ; i ; " rock""addsprite rock" ; i ; " rock"
next i
#m"spritescale"spritescale rock0100"#m "spritescale100"
#m "spritescale rock170"#m "spritescale70"
#m "spritescale rock270"#m "spritescale70"
#m "spritescale rock350"#m "spritescale50"
#m "spritescale rock450"#m "spritescale50"
#m "spritescale rock550"#m "spritescale50"
#m "spritescale rock650"#m "addsprite50"
#m "addsprite ufoufo"#m "addspriteufo"
#m "addsprite ufofirefire"#m "setfocus"#m "addspritefire"
#m "setfocus"
#m "addsprite player"" ; anim$
#m"spritexy"spritexy player"" ; px ;" "" " ; py
call nextlevel
call drawpoints
timer 40 , [tmr]
wait
function nr$( no )
nr$ = right$("00""00" + str$( no ) , 2 )
end function
[tmr]
q = q - 1
if q < 0 then
q = int( rnd( 0 ) * 20 )
d = int( rnd( 0 ) * 3 )
end if
if joyYN$ ="yes""yes" then
if Joy1x < 256 * 256 / 3 then
pst = ( pst + 1 )
if pst > 31 then pst = 0
end if
if Joy1x > 256 * 256 * 2 / 3 then
pst = ( pst - 1 )
if pst < 0 then pst = 31
end if
if Joy1y < 256 * 256 / 3 then
px = ( px - sin( strad( pst ) ) * 5 )
if px < -100 then px = winx
if px > winx then px = -100
py = ( py - cos( strad( pst ) ) * 5 )
if py < -100 then py = winy
if py > winy then py = -100
end if
if Joy1y > 256 * 256 * 2 / 3 then
''here i wil place a hyperjump in the furture
end if
else
select case lower$( lastkey$ )
case chr$( _VK_LEFT )
pst = ( pst + 1 )
if pst > 32 then pst = 0
case chr$( _VK_RIGHT )
pst = ( pst - 1 )
if pst < 0 then pst = 32
case chr$( _VK_UP )
px = ( px - sin( strad( pst ) ) * 5 )
if px < -100 then px = winx
if px > winx then px = -100
py = ( py - cos( strad( pst ) ) * 5 )
if py < -100 then py = winy
if py > winy then py = -100
case chr$( _VK_DOWN )
''hyperjump
case chr$( 27 ) ''escape
goto [quit]
wait
case" "#m "spritexy playerfire"" "
#m "spritexy playerfire" ; firetel ;" "" " _
; px - 16 - sin( strad( pst ) ) * 45 ;" "" " _
; py - 16 - cos( strad( pst ) ) * 45
#m"spritemovexy playerfire""spritemovexy playerfire" ; firetel ;" "" " _
; sin( strad( pst ) ) * -6 ;" "" " _
; cos( strad( pst ) ) * -6
firetel = firetel + 1
if firetel > 20 then firetel = 0
end select
end if
lastkey$ =""#m "spritexy""
#m "spritexy player"" ; px - 50 ;" "" " ; py - 50
#m"spriteimage"spriteimage playerp"p" ; pst
for i = 0 to 10
#m"spritexy? playerfire" ; i ; ""spritexy? playerfire" ; i ; " xy"y"
if x < -100 or x > winx + 100 _
or y < -100 or y > winy + 100 then
#m"spritemovexy playerfire" ; i ; " 0 0""spritemovexy playerfire" ; i ; " 0 0"
end if
next i
#m"spritexy?"spritexy? ufo ufoxufoy"ufoy"
if ufox < -100 then
ufox = winx
ufohasfired = false
state = rnd( 0 ) * ( winx / 2 ) + winx / 4 - 35
end if
state = state - 1
if state < 0 and not( ufohasfired ) then
ufohasfired = true
dx = px - ufox
dy = py - ufoy
af = sqr( dx ^ 2 + dy ^ 2 ) + 1
#m"spritexy"spritexy ufofire"" ; ufox ;" "" " ; ufoy
#m"spritemovexy"spritemovexy ufofire"" ; dx / af * 6 ;" "" " ; dy / af * 6
end if
#m"spritexy?"spritexy? ufofire xy"y"
if x < -100 then #m"spritemovexy"spritemovexy ufofire 00"0"
if x > winx then #m"spritemovexy"spritemovexy ufofire 00"0"
if y < -100 then #m"spritemovexy"spritemovexy ufofire 00"0"
if y > winy then #m"spritemovexy"spritemovexy ufofire 00"#m "spritexy0"
#m "spritexy ufo"" ; ufox ;" "" " ; ufoy
for i = 0 to 6
#m"spritexy? rock"; i ; ""spritexy? rock"; i ; " xy"y"
if x < -100 then x = winx
if x > winx then x = -100
if y < -100 then y = winy
if y > winy then y = -100
#m"spritexy rock" ; i ; " ""spritexy rock" ; i ; " " ; x ;" "" " ; y
next i
''colisiondetecion and respons
#m"spritecollides"spritecollides playerplayerhit$"playerhit$"
if instr( playerhit$ ,"rock""rock" ) <> 0 _
or instr( playerhit$ ,"ufo""ufo" ) <> 0 then
lives = lives - 1
if lives < 0 then
call gameover
else
call resetscene
end if
end if
#m"spritecollides"spritecollides rock0rockhit$"rockhit$"
if instr( rockhit$ ,"playerfire""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$""spritecollides rock" ; i ; " rockhit$"
if instr( rockhit$ ,"playerfire""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$""spritecollides rock" ; i ; " rockhit$"
if instr( rockhit$ ,"playerfire""playerfire" ) _
and rockst( 0 ) = flies then
point = point + 4
rockst( i ) = washit
#m"spritexy rock" ; i ; ""spritexy rock" ; i ; " -100-100"#m "spritemove rock" ; i ; " 0 0"-100"
#m "spritemove rock" ; i ; " 0 0"
end if
next i
#m"spritecollides"spritecollides ufoufohit$"ufohit$"
if instr( ufohit$ ,"playerfire""playerfire" ) then
points = points + 7
#m"spritexy"spritexy ufo" ; winx ; " "" ; winx ; " " _
; 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 ; ""spritexy? star" ; i ; " xy"y"
if y > winy then
#m"spritexy star" ; i ; " ""spritexy star" ; i ; " " ; rnd( 0 ) * winx ;" "" " ; -30
#m"spritescale star" ; i ; " ""spritescale star" ; i ; " " _
; rnd( 0 ) ^ 3 * 100
end if
next i
allwashit = true
if ufost <> washit then allwashit = false
for i = 0 to 6
if rock( i ) <> washit then allwashit = false
next i
if allwashit then call nextlevel
#m"drawsprites""drawsprites"
wait
sub resetgame
level = 0
lives = 3
points = 0
ufohasfired = false
state = rnd( 0 ) * ( winx / 2 ) + winx / 4
call resetscene
end sub
sub resetscene
timer 0
call drawpoints
for i = 1 to 4
#m"spritexy live" ; i ; " ""spritexy live" ; i ; " " ; i * 50 ;" "" " ; winy - 50
next i
for i = 0 to 20
#m"spritexy playerfire" ; i ; ""spritexy playerfire" ; i ; " -100-100"-100"
next i
#m"spritexy"spritexy ufofire -100-100"-100"
px = winx / 2
py = winy / 2
#m"spritexy"spritexy player"" ; px ;" "" " ; py
timer 40 , [tmr]
end sub
sub nextlevel
for i = 0 to 7
rockst( i ) = notjetactif
next i
rockst( 0 ) = flies
#m"spritexy"spritexy rock0 -100"" ; rnd( 0 ) * winy - 50
#m"spritemovexy"spritemovexy rock0"" ; x ;" "" " ; y
ufost = flies
level = level + 1
state = rnd( 0 ) * winx / 2 + winx / 2 - 50
#m"spritexy"spritexy ufo" ; winx ; " "" ; winx ; " " ; rnd(0) * winy/2 + winy/4 - 35
call resetscene
end sub
sub gameover
notice chr$( 13 ) _
+"GAME"GAME OVER!!!"!!!"
goto [quit]
end sub
sub rocksplit no , a , b
dx = rockdx( no )
dy = rockdy( no )
rockst( no ) = washit
#m"spritexy? rock""spritexy? rock" ; no ;"" xy"#m "spritexy rock"y"
#m "spritexy rock" ; no ;"" -100-100"#m "spritemovexy rock"-100"
#m "spritemovexy rock" ; no ;" 0 0"#m "spritexy rock"" 0 0"
#m "spritexy rock" ; a ;" "" " ; x ;" "" " ; y
rockst( a ) = flies
call rotate dx , dy , 120
#m"spritemove rock""spritemove rock" ; a ;" "" " ; dx ;" "" " ; dy
#m"spritexy rock""spritexy rock" ; b ;" "" " ; x ;" "" " ; y
rockst( b ) = flies
call rotate dx , dy , 120
#m"spritemove rock""spritemove rock" ; b ;" "" " ; dx ;" "" " ; dy
end sub
sub rotate byref k , byref l , deg
s = sin( deg * pi / 180 )
c = cos( deg * pi / 180 )
hk = k * c - l * s
hl = l * s + l * c
k = hk : l = lh
end sub
sub drawpoints
#m"fill black"#m "font"fill black"
#m "font Corier_New 50bold"#m "color green"#m "backcolor black"#m "goto 0 50"#m "\POINTSbold"
#m "color green"
#m "backcolor black"
#m "goto 0 50"
#m "\POINTS :"" ; right$(" "" " + str$( points ) , 8 )
#m"goto"goto 200100"#m "\LEVEL100"
#m "\LEVEL :"" ; level
#m"getbmp"getbmp back 0 0" ; winx ; " "" ; winx ; " " ; winy
#m"background back""background back"
for i = 0 to lives
#m"spritexy live" ; i ; " ""spritexy live" ; i ; " " ; i * 50 ;" "" " ; 50
next i
for i = lives to 3
#m"spritexy live" ; i ; ""spritexy live" ; i ; " -100-100"-100"
next i
end sub
function strad( st )
strad = st * pi / 16
end function
[key]
lastkey$ = right$( Inkey$ , 1 )
wait
[quit]
unloadbmp"fire""fire"
unloadbmp"ufo""ufo"
unloadbmp"star""star"
for i = 0 to 31
unloadbmp"p""p" ; i
next i
close #m
end