BREAK OUT

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

Moderator: anthonio

BREAK OUT

Berichtdoor bluatigro » ma jul 04, 2011 11:48 am

break out :
hit alle blokjes met de bal
zonder de bal te laten vallen
Code: Selecteer alles
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
nomainwin
global winx , winy
winx = DisplayWidth
winy = DisplayHeight

dim p( 30 , 20 )

global white , red , green , hx , hy , bx , by , bdx , bdy , tel , point
red = 1
green = 2
open "BREAK OUT" for graphics as #m
  #m "trapclose [quit]"
  #m "font Courier_new 25 bold"
  #m "fill darkgray"
  #m "getbmp back 0 0 " ; winx ; " " ; winy
  #m "background back"
  #m "goto 0 0"
  #m "down"
  #m "backcolor black"
  #m "boxfilled 100 40"
  #m "up"
  #m "goto 0 20"
  #m "down"
  #m "backcolor yellow"
  #m "boxfilled 20 40"
  #m "up"
  #m "getbmp yellow 0 0 20 40"
  #m "goto 0 20"
  #m "down"
  #m "backcolor 255 0 255"
  #m "boxfilled 20 40"
  #m "up"
  #m "getbmp brown 0 0 20 40"
  #m "goto 0 20"
  #m "down"
  #m "backcolor cyan"
  #m "boxfilled 20 40"
  #m "up"
  #m "getbmp cyan 0 0 20 40"
  #m "goto 0 20"
  #m "down"
  #m "backcolor blue"
  #m "boxfilled 20 40"
  #m "up"
  #m "getbmp blue 0 0 20 40"
  #m "goto 0 20"
  #m "down"
  #m "backcolor white"
  #m "boxfilled 20 40"
  #m "up"
  #m "getbmp white 0 0 20 40"
  #m "goto 0 20"
  #m "down"
  #m "backcolor red"
  #m "boxfilled 20 40"
  #m "up"
  #m "getbmp red 0 0 20 40"
  #m "goto 0 20"
  #m "down"
  #m "backcolor green"
  #m "boxfilled 20 40"
  #m "up"
  #m "getbmp green 0 0 20 40"
  #m "goto 0 20"
  #m "down"
  #m "backcolor yellow"
  #m "boxfilled 100 40"
  #m "up"
  #m "getbmp bat 0 0 100 20"
  clr$ = "blue brown red yellow green cyan"
  for x = 0 to 30
    for y = 0 to 20
      #m "addsprite x" ; x ; "y" ; y ; " " ; word$( clr$ , (x+y)mod 6 + 1 )
      #m "spritexy x" ; x ; "y" ; y ; " " _
      ; ( x - 15 ) * 20 + winx / 2 ; " " _
      ; ( y - 20 ) * 20 + winy / 2
      p( x , y ) = white
    next y
  next x
  #m "addsprite human bat"
  hx = winx / 2 - 50
  hy = winy / 2 + 300
  #m "addsprite bal white"
  bx = winx / 2 - 5
  by = winy * .6
  bdx = 5
  bdy = 5
  #m "setfocus"
  #m "when mouseMove [move]"

  timer 40 , [tmr]
wait
[move]
  hx = MouseX
wait
[tmr]
  #m "spritexy human " ; hx ; " " ; hy
  #m "spritexy bal " ; bx ; " " ; by
  if bx < winx / 2 - 400 then bdx = abs( bdx )
  if bx > winx / 2 + 400 then bdx = 0 - abs( bdx )
  if by < 0 then bdy = abs( bdy )
  if by > winy * .9 then
    by = winy * .6
    lives = lives - 1
    timer 0
    if lives < 0 then
      notice "GAME OVER !!"
      close #m
    end if
  end if
  bx = bx + bdx
  by = by + bdy
  #m "spritecollides bal list$"
  if instr( list$ , "x" ) <> 0 then
    bdy = abs( bdy )
    for x = 0 to 30
      for y = 0 to 20
        if instr( list$ , "x";x;"y";y ) <> 0 then
          #m "spritexy x";x;"y";y;" 0 0"
          tel = tel + 1
          point = point + 1
          if point > 100 then timer 25 , [tmr]
        end if
      next y
    next x
  end if
  #m "spritecollides human list$"
  if list$ = "bal" then
    bdy = 0 - abs( bdy )
    bdx = 0 - ( hx + 50 - bx + 5 ) / 14
  end if
  #m "drawsprites"
  #m "goto 50 50"
  #m "down"
  #m "color yellow"
  #m "backcolor darkgray"
  #m "\points : " ; nr$( point )
  #m "up"
  #m "flush"
wait
function nr$( x )
  nr$ = right$( "000000" ; str$( x ) , 6 )
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