''bluatigro 27 feb 2015 ''atilery duel WindowWidth = DisplayWidth WindowHeight = DisplayHeight global winx , winy , pi winx = WindowWidth winy = WindowHeight pi = atn( 1 ) * 4 global state , human , hfire , comp , cfire global speed global firedx , firedy , high , low , angle dim h( winx ) human = 1 hfire = 2 comp = 3 cfire = 4 speed = 5 nomainwin open "atilery duel" for graphics as #m #m "trapclose [quit]" #m "backcolor black" #m "goto 0 0" #m "down" #m "boxfilled 40 80" #m "up" #m "getbmp bmp1 0 0 40 80" #m "addsprite comp bmp1" #m "addsprite human bmp1" #m "addsprite fire bmp1" state = human call newgame timer 40 , [tmr] wait [tmr] scan #m "spritexy? fire fx fy" #m "spritexy? human hx hy" #m "spritexy? comp cx cy" select case state case human timer 0 prompt "angle in degrees" ; a$ firedx = cos( rad( val( a$ ) ) ) * speed firedy = 0-sin( rad( val( a$ ) ) ) * speed state = hfire #m "spritexy fire " ; hx ; " " ; hy timer 40 , [tmr] case hfire if fx > cx then state = comp case comp firedx = 0-cos( rad( angle ) ) * speed firedy = 0-sin( rad( angle ) ) * speed #m "spritexy fire " ; cx ; " " ; cy state = cfire case cfire if fx < winx / 3 then if fy > hy then if fx < hx then high = angle else low = angle end if angle = ( low + high ) / 2 state = human end if end if case else state = human end select #m "spritecollides fire list$" if list$ <> "" then timer 0 if list$ = "human" and state = cfire then notice "YOU LOST !!" call endgame end if if list$ = "comp" and state = hfire then notice "YOU WON !!" call endgame end if timer 40 , [tmr] end if fx = fx + firedx fy = fy + firedy #m "spritexy fire " ; fx ; " " ; int( fy ) firedy = firedy + 0.1 #m "drawsprites" wait function rad( deg ) rad = deg * pi / 180 end function sub endgame confirm "Play again ?" ; yn$ if yn$ = "yes" then call newgame else notice "Bey bey ." close #m end end if end sub sub newgame state = human h( 0 ) = range( winy / 4 , winy * 3 / 4 ) h( winx ) = range( winy / 4 , winy * 3 / 4 ) call hil 0 , winx , winy / 8 #m "fill blue" #m "color green" for x = 0 to winx #m "down" #m "line " ; x ; " " ; winy _ ; " " ; x ; " " ; winy - h( x ) #m "up" next x #m "getbmp bmp 0 0 " ; winx ; " " ; winy #m "background bmp" h = int( range( 30 , winx / 3 ) ) #m "spritexy human " ; h ; _ " " ; winy - h( h ) - 20 #m "spritexy fire " ; h ; _ " " ; winy - h( h ) - 20 c = int( range( winx * 2 / 3 , winx - 30 ) ) #m "spritexy comp " ; c ; _ " " ; winy - h( c ) - 20 #m "drawsprites" high = 45 angle = 45 low = 0 end sub sub hil a , b , i if b - a < 2 then exit sub m = int( ( a + b ) / 2 ) h( m ) = ( h( a ) + h( b ) ) / 2 _ + range( 0 - i , i ) call hil a , m , i / 2 call hil m , b , i / 2 end sub function range( l , h ) range = rnd(0) * ( h - l ) + l end function [quit] close #m end
|