Stimulerende Simulaties : File

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

Moderator: anthonio

Stimulerende Simulaties : File

Berichtdoor bluatigro » zo jun 27, 2010 12:04 pm

dit is een simulatie van een file
error's :
- de auto's botsen nog
- de auto's halen niet in

sprites :
main code : http://www.basic.wikispaces.com/Draw+Bool+Sprites
ander kleuren zou duidelijk moeten zijn
Code: Selecteer alles
call clear 32 , 32
call boxfil 0 , 0 , 32 , 32 , red , black
call save "p-red"

niet vergeten : pas de path's aan indien noodzakelijk
Code: Selecteer alles
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
global winx , winy
winx = WindowWidth
winy = WindowHeight
automax = 200
dim auto( automax , 3 )
global lanes , waitauto , autotel
lanes = 4
nomainwin
loadbmp "blue" , DefaultDir$ + "\BMP\p-blue.bmp"
loadbmp "red" , DefaultDir$ + "\BMP\p-red.bmp"
loadbmp "yellow" , DefaultDir$ + "\BMP\p-yellow.bmp"
loadbmp "green" , DefaultDir$ + "\BMP\p-green.bmp"

open "TRAFIC JAM" for graphics as #m
  #m "trapclose [quit]"
  #m "color black"
  #m "backcolor black"
  #m "goto 0 50"
  #m "down"
  #m "boxfilled " ; winx ; " " ; 50 + lanes * 40
  #m "up"
  #m "color white"
  for i = 0 to lanes
    #m "down"
    #m "line 0 " ; 50 + 40 * i ; " " _
    ; winx ; " " ; 50 + 40 * i
    #m "up"
  next i
  #m "getbmp bmp 0 0 " ; winx ; " " ; winy
  #m "background bmp"
  for i = o to automax
    #m "addsprite spr" ; i _
    ; " blue red green yellow"
    #m "spritexy spr" ; i ; " 0 0"
  next i
  timer 40 , [tmr]
wait
sub addauto
  if autotel >= automax then exit sub
  autotel = autotel + 1
  auto( autotel , 0 ) = 0
  auto( autotel , 1 ) = 0
  auto( autotel , 2 ) = rnd( 0 ) * 5 + 2
  d = int( rnd( 0 ) * 4 )
  select case d
    case 0
      #m "spriteimage spr" ; autotel ; " red"
    case 1
      #m "spriteimage spr" ; autotel ; " blue"
    case 2
      #m "spriteimage spr" ; autotel ; " green"
    case else
      #m "spriteimage spr" ; autotel ; " yellow"
  end select
end sub
[tmr]
  for i = 0 to autotel
    call free i , autoleft , autofront , autoright
    ''drive right as posible
    if not( autoright ) _
    and auto( i , 1 ) < lanes then
      auto( i , 1 ) = auto( i , 1 ) + 1
    end if
    ''drive fast as posible
    if autofront then
      ''overtake when needed
      if not( autoleft ) _
      and auto( i , 1 ) > 0 then
        auto( i , 1 ) = auto( i , 1 ) - 1
      else
        ''slow down if can not overtake
        auto( i , 2 ) = auto( i , 2 ) / 2
      end if
    else
      ''drive faster til maxspeed
      if auto( i , 2 ) < 10 then
        auto( i , 2 ) = auto( i , 2 ) + 0.1
      end if
    end if
    auto( i , 0 ) = ( auto( i , 0 ) _
    + auto( i , 2 ) ) mod winx
    #m "spritexy spr" ; i ; " " _
    ; auto( i , 0 ) ; " " _
    ; auto( i , 1 ) * 40 + 52
  next i
  waitauto = waitauto - 1
  if waitauto < 1 then
    call addauto
    waitauto = rnd( 0 ) * 100 + 32
  end if
  #m "drawsprites"
wait
sub free no , byref l , byref v , byref r
  l = 0
  v = 0
  r = 0
  for i = 0 to autotel
    ax = auto( no , 0 )
    ay = auto( no , 1 )
    aq = auto( no , 2 )
    bx = auto( i , 0 )
    by = auto( i , 1 )
    bq = auto( i , 2 )
    a = ax + aq + 64
    b = bx + bq + 64
    ''auto left ?
    if ( ax > b and a < bx ) _
    and by - ay = -1 then
      l = 1
    end if
    ''auto front ?
    if ( ax > b and a < bx ) then
      v = 1
    end if
    ''auto right ?
    if ( ax < b and a > bx ) _
    and by - ay = 1 then
      r = 1
    end if
  next i
end sub
[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