drop zone

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

Moderator: anthonio

drop zone

Berichtdoor bluatigro » di jul 24, 2012 1:01 pm

senario :
- stenen vallen
- stuur de stenen zo dat kloppende kleuren verdwijnen

error :
- de klopende kleuren block verdwijnen niet .

Code: Selecteer alles
dim p( 40 , 30 )
global hx , hy , stonest , winx , winy , stonex , stoney , sec
global black , red , green , yellow , blue , pink , cyan , white
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
winx = WindowWidth
winy = WindowHeight
black = 0
red = 1
green = 2
yellow = 3
blue = 4
pink = 5
cyan = 6
white = 7
nomainwin
faling = not( 0 )
open "drop zone" for graphics as #m
  #m "trapclose [quit]"
  #m "fill black"
  #m "getbmp bmp 0 0 1 1"
  #m "background bmp"
  #m "getbmp black 0 0 20 40"
  #m "goto 0 0"
  #m "backcolor black"
  #m "down"
  #m "boxfilled 20 20"
  #m "up"
  #m "goto 0 20"
  #m "backcolor red"
  #m "down"
  #m "boxfilled 20 40"
  #m "up"
  #m "getbmp red 0 0 20 40"
  #m "backcolor green"
  #m "goto 0 20"
  #m "down"
  #m "boxfilled 20 40"
  #m "up"
  #m "getbmp green 0 0 20 40"
  #m "backcolor yellow"
  #m "goto 0 20"
  #m "down"
  #m "boxfilled 20 40"
  #m "up"
  #m "getbmp yellow 0 0 20 40"
  #m "backcolor blue"
  #m "goto 0 20"
  #m "down"
  #m "boxfilled 20 40"
  #m "up"
  #m "getbmp blue 0 0 20 40"
  #m "backcolor pink"
  #m "goto 0 20"
  #m "down"
  #m "boxfilled 20 40"
  #m "up"
  #m "getbmp pink 0 0 20 40"
  #m "backcolor cyan"
  #m "goto 0 20"
  #m "down"
  #m "boxfilled 20 40"
  #m "up"
  #m "getbmp cyan 0 0 20 40"
  #m "backcolor white"
  #m "goto 0 20"
  #m "down"
  #m "boxfilled 20 40"
  #m "up"
  #m "getbmp white 0 0 20 40"
  #m "backcolor lightgray"
  #m "goto 0 20"
  #m "down"
  #m "boxfilled 20 40"
  #m "up"
  #m "getbmp gray 0 0 20 40"
  for x = 0 to 40
    for y = 0 to 30
      #m "addsprite " ; p$( x , y ) _
      ; " black red green blue yellow pink cyan white"
      #m "spritexy " ; p$( x , y ) _
      ; " " ; winx / 2 - 400 + x * 20 _
      ; " " ; winy / 2 - 300 + y * 20
    next y
  next x
  #m "addsprite human gray"
  #m "when characterInput [key]"
  #m "setfocus"
  notice chr$( 13 ) + "Welkome by drop zone ." + chr$( 13 ) _
       + "a bluatigro game ." + chr$( 13 ) + chr$( 13 ) _
       + "Stones are faling" + chr$( 13 ) _
       + "use the cursor keys and spacebar to" + chr$( 13 ) _
       + "steer the stones so" + chr$( 13 ) _
       + "that colors match and disapeer ." + chr$( 13 ) + chr$( 13 ) _
       + "         HAVE FUN !!"
  call restart
  call drawpit
  timer 250 , [tmr]
wait
[key]
  lastkey$ = right$( Inkey$ , 1 )
wait
[tmr]
''  sec = sec + .25
  if stonest then
    for i = 0 to 2
      a( i ) = p( stonex , stoney + i )
      p( stonex , stoney + i ) = black
    next i
    if not( p( stonex , stoney + 3 ) ) then
      stoney = stoney + 1
      fl = 0
    else
      stonest = 0
      fl = 1
    end if
    if fl then
      for i = 0 to 2
        if p( stonex , stoney + i ) = p( stonex - 1 , stoney + i ) then
          p( stonex , stoney + i ) = black
          p( stonex - 1 , stoney + i ) = black
          sec = sec + 1
        end if
        if p( stonex , stoney + i ) = p( stonex + 1 , stoney + i ) then
          p( stonex , stoney + i ) = black
          p( stonex + 1 , stoney + i ) = black
         sec = sec + 1
        end if
      next i
      for i = 0 to 2
        if not( p( stonex , stoney + i ) ) then
          if not( p( stonex - 1 , stoney + i ) ) then
            h = 0
            while p( stonex - 1 , stoney + i - h )
              p( stonex - 1 , stoney + i + h ) _
              = p( stonex - 1 , stoney + i + h - 1 )
              h = h + 1
            wend
          end if
          if not( p( stonex + 1 , stoney + i ) ) then
            h = 0
            while p( stonex + 1 , stoney + i - h )
              p( stonex + 1 , stoney + i + h ) _
              = p( stonex + 1 , stoney + i + h - 1 )
              h = h + 1
            wend
          end if
        end if
      next i
      if stoney < 2 then
        timer 0
        notice chr$( 13 ) + "You have " ; sec ; " points ."
        close #m
        end
      end if
    end if
    for i = 0 to 2
        p( stonex , stoney + i ) = a( i )
    next i
  else
    stonest = 1
    stonex = 20
    stoney = 0
    for i = 0 to 2
      p( stonex , i ) = int( rnd( 0 ) * 6 + 1 )
    next i
  end if
  select case lastkey$
    case chr$( _VK_LEFT )
      fl = 0
      for i = 0 to 2
        if p( stonex - 1 , stoney + i ) then
          fl = 1
        end if
      next i
      if not( fl ) then
        for i = 0 to 2
          p( stonex - 1 , stoney + i ) = p( stonex , stoney + i )
          p( stonex , stoney + i ) = black
        next i
      end if
      stonex = stonex - 1
    case chr$( _VK_RIGHT )
      fl = 0
      for i = 0 to 2
        if p( stonex + 1 , stoney + i ) then
          fl = 1
        end if
      next i
      if not( fl ) then
        for i = 0 to 2
          p( stonex + 1 , stoney + i ) = p( stonex , stoney + i )
          p( stonex , stoney + i ) = black
        next i
      end if
      stonex = stonex + 1
    case chr$( _VK_SPACE )
      h = p( stonex , stoney + 2)
      p( stonex , stoney + 2 ) = p( stonex , stoney + 1 )
      p( stonex , stoney + 1 ) = p( stonex , stoney )
      p( stonex , stoney ) = h
    case chr$( _VK_ESCAPE )
      close #m
      end
    case else
  end select

  lastkey$ = ""
  call drawpit
wait
function p$( x , y )
  p$ = "p" ; x ; "_" ; y
end function
sub restart

''TODO : create grid and player and enemy's start postions

''this is a example grid
''feel free to change
  for x = 0 to 40
    for y = 0 to 30
      p( x , y ) = 0
      if y > 29 then p( x , y ) = white
      if x < 1 then p( x , y ) = white
      if x > 39 then p( x , y ) = white
    next y
  next x
  hx = 20
  hy = 15
  sec = 0
end sub
sub drawpit
  for x = 0 to 40
    for y = 0 to 30
      select case p( x , y )
        case black
          #m "spriteimage " ; p$( x , y ) ; " black"
        case red
          #m "spriteimage " ; p$( x , y ) ; " red"
        case green
          #m "spriteimage " ; p$( x , y ) ; " green"
        case yellow
          #m "spriteimage " ; p$( x , y ) ; " yellow"
        case blue
          #m "spriteimage " ; p$( x , y ) ; " blue"
        case pink
          #m "spriteimage " ; p$( x , y ) ; " pink"
        case cyan
          #m "spriteimage " ; p$( x , y ) ; " cyan"
        case else
          #m "spriteimage " ; p$( x , y ) ; " white"
      end select
    next y
  next x
''  #m "spritexy human " _
''  ; winx / 2 - 400 + hx * 20 ; " " _
''  ; winy / 2 - 300 + hy * 20
  #m "drawsprites"
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