ATILERY DUEL

Vragen en suggesties over het programmeren van spelletjes, sprites en dergelijke in Liberty BASIC

Moderator: anthonio

ATILERY DUEL

Berichtdoor bluatigro » vr feb 27, 2015 12:09 pm

senario :
- je schiet door een hoek te kiezen
- als je mist schiet de computer
- als die mist ben jij weer
- etc...

error :
- de fire sprite beweegt vreemd

Code: Selecteer alles
''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 , speed
global firedx , firedy , high , low , angle
human = 1
hfire = 2
comp = 3
cfire = 4
speed = 3
nomainwin
open "atilery duel" for graphics as #m
  #m "trapclose [quit]"
  #m "backcolor black"
  #m "goto 0 0"
  #m "down"
  #m "boxfilled 20 40"
  #m "up"
  #m "getbmp bmp 0 0 20 40"
  #m "addsprite comp bmp"
  #m "addsprite human bmp"
  #m "addsprite fire bmp"
  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 > winx / 2 and fy > cy 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 HIT ME !!"
      call newgame
    end if
    if list$ = "comp" and state = hfire then
      notice "I HIT YOU !!"
      call newgame
    end if
    timer 40 , [tmr]
  end if
  #m "spritexy fire ";fx+firedx;" ";fy+firedy+1
  #m "drawsprites"
wait
function rad( deg )
  rad = deg * pi / 180
end function
sub newgame
  state = human
  #m "spritexy human " _
  ; range( 0 , winx / 3 ) ; " " _
  ; range( winy / 4 , winy * 3 / 4 )
  #m "spritexy comp " _
  ; range( winx * 2 / 3 , winx - 20 ) ; " " _
  ; range( winy / 4 , winy * 3 / 4 )
  high = 45
  angle = 45
  low = 0
  firedx = 0
  firedy = 0
end sub
function range( l , h )
  range = rnd(0) * ( h - l ) + l
end function
[quit]
  close #m
end
bluatigro
 
Berichten: 306
Geregistreerd: za sep 27, 2008 6:01 pm

Re: ATILERY DUEL

Berichtdoor bluatigro » za mei 16, 2015 2:14 pm

update :
- nu met landschap

error :
- mijn gamelogica klopt niet

Code: Selecteer alles
''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
bluatigro
 
Berichten: 306
Geregistreerd: za sep 27, 2008 6:01 pm


Keer terug naar Games

Wie is er online

Gebruikers op dit forum: Geen geregistreerde gebruikers. en 1 gast

cron