LB Booster
« ATILERY DUEL »

Welcome Guest. Please Login or Register.
Apr 1st, 2018, 04:39am



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
We apologize Conforums does not have any export functions to migrate data.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

Thank you Conforums members.
Speed up Liberty BASIC programs by up to ten times!
Compile Liberty BASIC programs to compact, standalone executables!
Overcome many of Liberty BASIC's bugs and limitations!
LB Booster Resources
LB Booster documentation
LB Booster Home Page
LB Booster technical Wiki
Just BASIC forum
BBC BASIC Home Page
Liberty BASIC forum (the original)

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: ATILERY DUEL  (Read 345 times)
bluatigro
Full Member
ImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 111
xx ATILERY DUEL
« Thread started on: May 16th, 2015, 1:12pm »

this is a try at a atilery duel game

senario :
- you fire
- if you mis
- the computer fires
- if it mises you are again

error :
- there is somthuing wrong whit my game logic

Code:
''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


 
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: ATILERY DUEL
« Reply #1 on: May 16th, 2015, 3:16pm »

on May 16th, 2015, 1:12pm, bluatigro wrote:
this is a try at a atilery duel game

Liberty BASIC 4.04 comes with MAYHEM.BAS which is very similar. You could perhaps use that as a starting point, or at least it may give you some ideas to help fix your logic.

Richard.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls