ASTERIODS 2

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

Moderator: anthonio

ASTERIODS 2

Berichtdoor bluatigro » di maart 27, 2012 12:04 pm

dit is mijn 2e poging met asteriods

ofwel hoe bouw ik mijn games

sprites :
http://www.basic.wikispaces.com/how+to+ ... ur+Sprites
hoofd code :
Draw Bool Sprites
sprite code :
asteriods

NIET VERGETEN : pas path in code aan indien nodig

stap 1 :
ik begin vrijwel altijd met de mens gecontroleerde graphics
Code: Selecteer alles
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
global winx , winy , px , py , pangle , lastkey , pi
winx = WindowWidth
winy = WindowHeight
pi = atn( 1 ) * 4
nomainwin
loadbmp "fire" , DefaultDir$ + "\BMP\fire.bmp"
for i = 0 to 31
  loadbmp "player" ; i , DefaultDir$ + "\BMP\player" ; nr$( i ) ; ".bmp"
  anim$ = anim$ + " player" ; i
next i
loadbmp "rock" , DefaultDir$ + "\BMP\rock.bmp"
loadbmp "ufo" , DefaultDir$ + "\BMP\ufo.bmp"
open "ASTERIODS" for graphics as #m
  #m "trapclose [quit]"
  #m "fill black"
  #m "getbmp background 0 0 2 2"
  #m "background background"
  #m "addsprite human" ; anim$
  call resetlevel
  #m "setfocus"
  #m "when characterInput [read_key]"
  timer 40 , [timer_tick]
wait
[read_key]
  lastkey = asc( right$( Inkey$ , 1 ) )
wait
[timer_tick]
  select case lastkey
    case _VK_UP
      px = px - sin( radst( pangle ) ) * 4
      py = py - cos( radst( pangle ) ) * 4
    case _VK_RIGHT
      pangle = ( pangle - 1 ) and 31
    case _VK_DOWN
      px = px + sin( radst( pangle ) ) * 4
      py = py + cos( radst( pangle ) ) * 4
    case _VK_LEFT
      pangle = ( pangle + 1 ) and 31
    case else
  end select
  lastkey = 0
  if px < -64 then px = winx
  if px > winx then px = -64
  if py < -64 then py = winy
  if py > winy then py = -64
  #m "spritexy human " ; px ; " " ; py
  #m "spriteimage human player" ; pangle
  #m "drawsprites"
wait
function radst( stangle )
  radst = stangle * pi / 16
end function
sub resetlevel
  px = winx / 2 - 32
  py = winy / 2 - 32
  pangle = 0
end sub
function nr$( x )
  nr$ = right$( "00" ; x , 2 )
end function
[quit]
  unloadbmp "fire"
  for i = 0 to 31
    unloadbmp "player" ; nr$( i )
  next i
  unloadbmp "rock"
  unloadbmp "ufo"
  close #m
end
bluatigro
 
Berichten: 306
Geregistreerd: za sep 27, 2008 6:01 pm

Re: ASTERIODS 2

Berichtdoor bluatigro » di maart 27, 2012 1:55 pm

stap 2 :
rotsen en vuur

senario [ dat wat zou moeten gebeuren :
-je hebt 1 leven
-je vliegt rond
-je ontwijkt de rotsen
-als je schiet op een rots en je raakt hem dan splijt hij in 2

error :
rots zweeft niet door t scherm
Code: Selecteer alles
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
global winx , winy , px , py , pangle , lastkey , pi
winx = WindowWidth
winy = WindowHeight
pi = atn( 1 ) * 4
nomainwin
loadbmp "fire" , DefaultDir$ + "\BMP\dot.bmp"     '>>>>>>>>>> gewijzigd door Gordon
for i = 0 to 31
  loadbmp "player" ; nr$( i ) , DefaultDir$ + "\BMP\player" ; nr$( i ) ; ".bmp"
  anim$ = anim$ + " player" ; nr$( i )
next i
loadbmp "rock" , DefaultDir$ + "\BMP\rock.bmp"
loadbmp "ufo" , DefaultDir$ + "\BMP\ufo.bmp"
open "ASTERIODS" for graphics as #m
  #m "trapclose [quit]"
  #m "fill black"
  #m "getbmp background 0 0 2 2"
  #m "background background"
  #m "addsprite human" ; anim$
  #m "addsprite hfire fire"
  for i = 0 to 7
    #m "addsprite rock"; i ;" rock"
  next i
  call resetlevel
  #m "setfocus"
  #m "when characterInput [read_key]"
  timer 40 , [timer_tick]
wait
sub rockwashit no , a , b
  rx( a ) = rx( no )
  ry( a ) = ry( no )
  rdx( a ) = rnd( 0 ) * 4 - 2
  rdy( a ) = rnd( 0 ) * 4 - 2
  rx( b ) = rx( no )
  ry( b ) = ry( no )
  rdx( b ) = rnd( 0 ) * 4 - 2
  rdy( b ) = rnd( 0 ) * 4 - 2
  rx( no ) = -200
  ry( no ) = -200
  rdx( no ) = 0
  rdy( no ) = 0
end sub
[read_key]
  lastkey = asc( right$( Inkey$ , 1 ) )
wait
[timer_tick]
''  #m "goto 0 50"
''  #m "color cyan"
''  #m "backcolor black"
''  #m "font Courier_new 50 bold"
''  #m "down"
''  #m "\POINTS " ; right$( "000000" ; points , 6 )
  select case lastkey
    case _VK_UP
      px = px - sin( radst( pangle ) ) * 4
      py = py - cos( radst( pangle ) ) * 4
    case _VK_RIGHT
      pangle = ( pangle - 1 ) and 31
    case _VK_DOWN
      px = px + sin( radst( pangle ) ) * 4
      py = py + cos( radst( pangle ) ) * 4
    case _VK_LEFT
      pangle = ( pangle + 1 ) and 31
    case _VK_SPACE
      hfx = px
      hfy = py
      #m "spritexy hfire " ; hfx ; " " ; hfy
      hfdx = 0-sin( radst( pangle ) ) * 8
      hfdy = 0-cos( radst( pangle ) ) * 8
    case _VK_ESCAPE
      goto [quit]
    case else
  end select
  lastkey = 0
  if px < -64 then px = winx
  if px > winx then px = -64
  if py < -64 then py = winy
  if py > winy then py = -64
  #m "spritexy human " ; px ; " " ; py
  #m "spriteimage human player" ; nr$( pangle )
  hfx = hfx + hfdx
  hfy = hfy + hfdy
  if hfx < -64 _
  or hfx > winx _
  or hfy < -64 _
  or hfy > winy then
    hfx = -200
    hfy = -200
    hfdx = 0
    hfdy = 0
  end if
  for i = 0 to 7
    rx( i ) = rx( i ) + rdx( i )
    ry( i ) = ry( i ) + rdy( i )
    if rx(i) < -200 then rx(i) = winx
    if rx(i) > winx then rx(i) = -64
    if ry(i) < -200 then ry(i) = winy
    if ry(i) > winy then ry(i) = -64
    #m "spritecollides rock" ; i ; " list$"
    if instr( list$ , "player" ) then
      timer 0
      notice chr$( 13 ) ; "You ar dead !!"
      goto [quit]
    end if
    if instr( list$ , "fire" ) then
      hfx = -200
      hfy = -200
      hfdx = 0
      hfdy = 0
      select case i
        case 0
          call rockwashit 0 , 1 , 2
          points = points + 1
        case 1
          call rockwashit 1 , 3 , 4
          points = points + 2
        case 2
          call rockwashit 2 , 5 , 6
          points = points + 2
        case else
          points = points + 4
          rx( i ) = -200
          ry( i ) = -200
          rdx( i ) = 0
          rdy( i ) = 0
      end select
    end if
    #m "spritexy rock" ; i ; " " ; rx( i ) ; " " ; ry( i )
  next i
  #m "spritexy hfire " ; hfx ; " " ; hfy

  #m "drawsprites"
wait
function radst( stangle )
  radst = stangle * pi / 16
end function
sub resetlevel
  hfx = -200
  hfy = -200
  hfdx = 0
  hfdy = 0
  px = winx / 2 - 32
  py = winy / 2 - 32
  pangle = 0
  for i = 0 to 7
    rx( i ) = -200
    ry( i ) = -200
    rdx( i ) = 0
    rdy( i ) = 0
  next i
  rx( 0 ) = 0
  ry( 0 ) = 0
  rdx( 0 ) = rnd( 0 ) * 8 - 4
  rdy( 0 ) = rnd( 0 ) * 8 - 4
end sub
function nr$( x )
  nr$ = right$( "00" ; x , 2 )
end function
[quit]
  unloadbmp "fire"
  for i = 0 to 31
    unloadbmp "player" ; nr$( i )
  next i
  unloadbmp "rock"
  unloadbmp "ufo"
  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