the pit

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

Moderator: anthonio

the pit

Berichtdoor bluatigro » ma jul 16, 2012 12:30 pm

senario :
- je bent in een gat
- stenen vallen op je
- stuur de stenen zo dat je uit het gat klimt

error :
- human is niet zichtbaar
Code: Selecteer alles
dim p( 40 , 30 )
global hx , hy , stone , stonest , faling , wimx , winy , stonex , stoney
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
winx = WindowWidth
winy = WindowHeight
nomainwin
stone = 1
faling = not( 0 )
open "The pit" for graphics as #m
  #m "trapclose [quit]"
  #m "cls"
  #m "getbmp empty 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 lightgray"
  #m "down"
  #m "boxfilled 20 40"
  #m "up"
  #m "getbmp stone 0 0 20 40"
  for x = 0 to 40
    for y = 0 to 30
      #m "addsprite " ; p$( x , y ) ; " stone empty"
      #m "spritexy " ; p$( x , y ) _
      ; " " ; winx / 2 - 400 + x * 20 ; " " ; winy / 2 - 300 + y * 20
    next y
  next x
  #m "backcolor blue"
  #m "goto 0 20"
  #m "down"
  #m "boxfilled 20 40"
  #m "up"
  #m "getbmp human 0 0 20 40"
  #m "addsprite human human"
  #m "when characterInput [key]"
  #m "setfocus"
  call restart
  call drawpit
  timer 250 , [tmr]
wait
[key]
  lastkey$ = right$( Inkey$ , 1 )
wait
[tmr]
  if stonest = faling then
    p( stonex , stoney ) = empty
    if p( stonex , stoney + 1 ) = empty then
      stoney = stoney + 1
    else
      stonest = not( faling )
    end if
    p( stonex , stoney ) = stone
  else
    stonex = hx
    stoney = 0
    stonest = faling
  end if
  if stonex = hx and stoney + 1 = hy then
    timer 0
    notice "YOU DIED !!"
    close #m
    end
  end if
  if hx < 3 or hx > 37 then
    timer 0
    notice "YOU ESCAPED !!"
    close #m
    end
  end if
  select case lastkey$
    case chr$( _VK_LEFT )
      if p( hx - 1 , hy ) = empty then
        hx = hx - 1
      else
        if p( hx - 1 , hy - 1 ) = empty then
          hx = hx - 1
          hy = hy - 1
        end if
      end if
    case chr$( _VK_RIGHT )
      if p( hx + 1 , hy ) = empty then
        hx = hx + 1
      else
        if p( hx + 1 , hy - 1 ) = empty then
          hx = hx + 1
          hy = hy - 1
        end if
      end if
    case else
  end select
  while p( hx , hy + 1 ) = empty
    hy = hy + 1
  wend
  lastkey$ = ""
  call drawpit
wait
function p$( x , y )
  p$ = "p" ; x ; "_" ; y
end function
sub restart
  for x = 0 to 40
    for y = 0 to 30
      p( x , y ) = 0
      if x < 3 and y > 10 then
        p( x , y ) = stone
      end if
      if x > 37 and y > 10 then
        p( x , y ) = stone
      end if
      if y > 27 then
        p( x , y ) = stone
      end if
    next y
  next x
  hx = 20
  hy = 26
end sub
sub drawpit
  for x = 0 to 40
    for y = 0 to 30
      if p( x , y ) = stone then
        #m "spriteimage " ; p$( x , y ) ; " stone"
      else
        #m "spriteimage " ; p$( x , y ) ; " empty"
      end if
    next y
  next x
  #m "spritexy human " _
  ; winx / 2 - 400 + hx ; " " ; winy / 2 - 300 + hy
  #m "drawsprites"
end sub
[quit]
  close #m
end
bluatigro
 
Berichten: 306
Geregistreerd: za sep 27, 2008 6:01 pm

Re: the pit

Berichtdoor bluatigro » do jul 19, 2012 11:12 am

update :
- nu zonder error's
- andere klueren
- tijd

ik denk dat de record tijd rond 3 nimuten ligt
ik denk niet dat veel minder mogelijk is

SPEEL ZE !!

Code: Selecteer alles
dim p( 40 , 30 )
global hx , hy , stone , stonest , faling , winx , winy , stonex , stoney , sec
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
winx = WindowWidth
winy = WindowHeight
nomainwin
stone = 1
faling = not( 0 )
open "The pit" for graphics as #m
  #m "trapclose [quit]"
  #m "fill black"
  #m "getbmp bmp 0 0 1 1"
  #m "background bmp"
  notice chr$( 13 ) _
       + "Welkome in the pit :" + chr$( 13 ) _
       + "a game by BluaTigro ." + chr$( 13 ) + chr$( 13 ) _
       + "You are in a pit" + chr$( 13 ) _
       + "stones are faling on you" + chr$( 13 ) _
       + "use the cursor keys to" + chr$( 13 ) _
       + "steer the stones so" + chr$( 13 ) _
       + "that you escape the pit" + chr$( 13 ) _
       + "in a least amount of time ." + chr$( 13 ) + chr$( 13 ) _
       + "          HAVE FUN !!"
  #m "getbmp empty 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 lightgray"
  #m "down"
  #m "boxfilled 20 40"
  #m "up"
  #m "getbmp stone 0 0 20 40"
  for x = 0 to 40
    for y = 0 to 30
      #m "addsprite " ; p$( x , y ) ; " stone empty"
      #m "spritexy " ; p$( x , y ) _
      ; " " ; winx / 2 - 500 + x * 25 ; " " ; winy / 2 - 400 + y * 25
    next y
  next x
  #m "backcolor yellow"
  #m "goto 0 20"
  #m "down"
  #m "boxfilled 20 40"
  #m "up"
  #m "getbmp human 0 0 20 40"
  #m "addsprite human human"
  #m "when characterInput [key]"
  #m "setfocus"
  call restart
  call drawpit
  timer 250 , [tmr]
wait
[key]
  lastkey$ = right$( Inkey$ , 1 )
wait
[tmr]
  sec = sec + .25
  if stonest = faling then
    p( stonex , stoney ) = empty
    if p( stonex , stoney + 1 ) = empty then
      stoney = stoney + 1
    else
      stonest = not( faling )
    end if
    p( stonex , stoney ) = stone
  else
    stonex = hx
    stoney = 0
    stonest = faling
  end if
  if stonex = hx and stoney + 1 = hy then
    timer 0
    notice "YOU DIED !!" + chr$( 13 ) _
         + "time : " ; sec ; " sec."
    close #m
    end
  end if
  if hx < 3 or hx > 37 then
    timer 0
    notice "YOU ESCAPED !!" + chr$( 13 ) _
         + "time : " ; sec ; " sec."
    close #m
    end
  end if
  select case lastkey$
    case chr$( _VK_LEFT )
      if p( hx - 1 , hy ) = empty then
        hx = hx - 1
      else
        if p( hx - 1 , hy - 1 ) = empty then
          hx = hx - 1
          hy = hy - 1
        end if
      end if
    case chr$( _VK_RIGHT )
      if p( hx + 1 , hy ) = empty then
        hx = hx + 1
      else
        if p( hx + 1 , hy - 1 ) = empty then
          hx = hx + 1
          hy = hy - 1
        end if
      end if
    case else
  end select
  while p( hx , hy + 1 ) = empty
    hy = hy + 1
  wend
  lastkey$ = ""
  call drawpit
wait
function p$( x , y )
  p$ = "p" ; x ; "_" ; y
end function
sub restart
  for x = 0 to 40
    for y = 0 to 30
      p( x , y ) = 0
      if x < 3 and y > 10 then
        p( x , y ) = stone
      end if
      if x > 37 and y > 10 then
        p( x , y ) = stone
      end if
      if y > 27 then
        p( x , y ) = stone
      end if
    next y
  next x
  hx = 20
  hy = 27
  sec = 0
end sub
sub drawpit
  for x = 0 to 40
    for y = 0 to 30
      if p( x , y ) = stone then
        #m "spriteimage " ; p$( x , y ) ; " stone"
      else
        #m "spriteimage " ; p$( x , y ) ; " empty"
      end if
    next y
  next x
  #m "spritexy human " _
  ; winx / 2 - 500 + hx * 25 ; " " _
  ; winy / 2 - 400 + hy * 25
  #m "drawsprites"
end sub
[quit]
  close #m
end
bluatigro
 
Berichten: 306
Geregistreerd: za sep 27, 2008 6:01 pm

Re: the pit

Berichtdoor Gordon » do jul 19, 2012 6:27 pm

Leuke game!

Gordon
Avatar gebruiker
Gordon
Site Admin
 
Berichten: 684
Geregistreerd: zo mei 22, 2005 12:50 am


Keer terug naar Games

Wie is er online

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

cron