SNAKE

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

Moderator: anthonio

SNAKE

Berichtdoor bluatigro » wo jan 07, 2015 11:46 am

dit is een poging om tot snake te maken

senario :
- je bent en slang
- je eet muizen
- elke keer als je een muis eet wordt je langer

error :
- de code stopt zonder te vertellen waarom

Code: Selecteer alles
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
global winx , winy
winx = WindowWidth
winy = WindowHeight
global true , false , length , key$ , points
true = not( false )
nomainwin
open "SNAKE 1.0" for graphics as #m
  #m "trapclose [quit]"
  #m "goto 0 0"
  #m "backcolor black"
  #m "down"
  #m "boxfilled 32 64"
  #m "up"
  #m "getbmp bmp 0 0 32 64"
  for i = 0 to 100
    #m "addsprite spr";i;" bmp"
    #m "spritexy spr";i;" -50 -50"
  next i
  #m "addsprite pil bmp"
  #m "spritexy pil ";int(range(0,(winx-32)/32))*32 _
                ;" ";int(range(0,(winy-32)/32))*32
  #m "when characterInput [key]"
  #m "setfocus"
  length = 1
  timer 250 , [tmr]
end
function range( l , h )
  range = rnd(0) * ( h - l ) + l
end function
[key]
  key$ = right$( Inkey$ , 1 )
wait
[tmr]
  #m "spritexy? spr0 x0 y0"
  select case key$
    case chr$( _VK_UP )
      y0 = y0 - 32
    case chr$( _VK_DOWN )
      y0 = y0 + 32
    case chr$( _VK_LEFT )
      x0 = x0 - 32
    case chr$( _VK_RIGHT )
      x0 = x0 + 32
    case else
  end select
  for i = 1 to 100
    #m "spritexy? spr";i-1;" x y"
    if i <= length then
      #m "spritexy spr";i;" ";x;" ";y
    else
      #m "spritexy spr";i;" -50 -50"
    end if
  next
  #m "spritexy spr0 ";x0;" ";y0
  #m "spritecollides spr0 hit$"
  if instr( hit$ , "pil" ) then
    #m "spritexy pil ";int(range(0,(winx-32)/32))*32 _
                ;" ";int(range(0,(winy-32)/32))*32
    points = points + length
    if lenght < 100 then
      length = length + 1
    end if
  end if
  if instr( hit$ , "spr" ) then
    timer 0
    notice "GAME OVER !!" + chr$(13) _
    ; points ; " points ."
    close #m
    end
  end if
  #m "drawsprites"
wait
[quit]
  close #m
end
bluatigro
 
Berichten: 306
Geregistreerd: za sep 27, 2008 6:01 pm

Re: SNAKE

Berichtdoor bluatigro » do jan 08, 2015 11:59 am

update :
- r beweegt nu iets

error :
- waar is mijn muis
- wat is fout by de geREMde code
Code: Selecteer alles
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
global winx , winy
winx = WindowWidth
winy = WindowHeight
global true , false , length , key$ , points
true = not( false )
nomainwin
open "SNAKE 2.0" for graphics as #m
  #m "trapclose [quit]"
  #m "goto 0 0"
  #m "backcolor black"
  #m "down"
  #m "boxfilled 32 64"
  #m "up"
  #m "getbmp bmp 0 0 32 64"
  for i = 0 to 100
    #m "addsprite spr";i;" bmp"
    #m "spritexy spr";i;" -50 -50"
  next i
  #m "spritexy spr0 128 128"
  #m "addsprite pil bmp"
  #m "spritexy pil ";int(range(128,(winx-128)/32))*32 _
                ;" ";int(range(128,(winy-128)/32))*32
  #m "when characterInput [key]"
  #m "setfocus"
  length = 1
  timer 250 , [tmr]
wait
function range( l , h )
  range = rnd(0) * ( h - l ) + l
end function
[key]
  key$ = right$( Inkey$ , 1 )
wait
[tmr]
  #m "spritexy? spr0 x0 y0"
  select case key$
    case chr$( _VK_UP )
      y0 = y0 - 32
    case chr$( _VK_DOWN )
      y0 = y0 + 32
    case chr$( _VK_LEFT )
      x0 = x0 - 32
    case chr$( _VK_RIGHT )
      x0 = x0 + 32
    case chr$( _VK_ESCAPE )
      timer 0
      notice "GAME INTERUPTED !!"
      close #m
      end
    case else
  end select
''  if x0 < 0 _
''  or x0 > winx / 32 _
''  or y0 < 0 _
''  or y0 > winy / 32 then
''    timer 0
''    notice "GAME OVER !!" + chr$( 13 ) _
''    ; points ; " points ."
''    close #m
''    end
''  end if
  for i = 100 to 1 step -1
    #m "spritexy? spr";i-1;" x y"
    if i <= length then
      #m "spritexy spr";i;" ";x;" ";y
    else
      #m "spritexy spr";i;" -50 -50"
    end if
  next
  #m "spritexy spr0 ";x0;" ";y0
  #m "spritecollides spr0 hit$"
  if instr( hit$ , "pil" ) then
    #m "spritexy pil ";int(range(128,(winx-128)/32))*32 _
                ;" ";int(range(128,(winy-128)/32))*32
    points = points + length
    if lenght < 100 then
      length = length + 1
    end if
  end if
''  if instr( hit$ , "spr" ) then
''    timer 0
''    notice "GAME OVER !!" + chr$(13) _
''    ; points ; " points ."
''    close #m
''    end
''  end if
  #m "drawsprites"
wait
[quit]
  close #m
end
bluatigro
 
Berichten: 306
Geregistreerd: za sep 27, 2008 6:01 pm

Re: SNAKE

Berichtdoor bluatigro » ma jan 12, 2015 2:07 pm

update :
- meer kleur
- proof of consept
- je gaat sneller als je groeit

error :
- sneller gaan lukt niet

Code: Selecteer alles
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
global winx , winy
winx = WindowWidth
winy = WindowHeight
global true , false , length , key$ , points , ms
true = not( false )
ms = 250
nomainwin
menu #m , "game" _
        , "info" , [info] _
        , "exit game" , [quit]
open "SNAKE 3.0" for graphics as #m
  #m "trapclose [quit]"
  for i = 0 to 15
    #m "goto 0 0"
    #m "backcolor black"
    #m "down"
    #m "boxfilled 32 64"
    #m "up"
    #m "backcolor 0 ";int(rnd(0)*255);" 0"
    #m "goto 0 32"
    #m "down"
    #m "boxfilled 32 64"
    #m "getbmp bmp";i;" 0 0 32 64"
  next i
  for i = 0 to 100
    #m "addsprite spr";i;" bmp";i mod 15 + 1
    #m "spritexy spr";i;" -50 -50"
  next i
  #m "spritexy spr0 128 128"
  #m "addsprite pil bmp0"
  #m "spritexy pil ";int(range(128/32,(winx-128)/32))*32 _
                ;" ";int(range(128/32,(winy-128)/32))*32
  #m "when characterInput [key]"
  #m "setfocus"
  length = 1
  timer ms , [tmr]
wait
function range( l , h )
  range = rnd(0) * ( h - l ) + l
end function
[info]
  r$ = chr$( 13 )
  timer 0
  text$ = "Welkome by snake ." + r$ _
  + "A game by bluatigro ." + r$ + r$ _
  + "Target of the game :" + r$ _
  + "You are a snake who eats mice ." + r$ _
  + "You wil grow and go faster ." + r$ _
  + "Dont go of the screen or byte yourself ."
  notice text$
  timer ms , [tmr]
wait
[key]
  key$ = right$( Inkey$ , 1 )
wait
[tmr]
  #m "spritexy? spr0 x0 y0"
  select case key$
    case chr$( _VK_UP )
      y0 = y0 - 32
    case chr$( _VK_DOWN )
      y0 = y0 + 32
    case chr$( _VK_LEFT )
      x0 = x0 - 32
    case chr$( _VK_RIGHT )
      x0 = x0 + 32
    case chr$( _VK_ESCAPE )
      timer 0
      notice "GAME INTERUPTED !!"
      close #m
      end
    case else
  end select
  if x0 < 0 _
  or x0 > winx _
  or y0 < 0 _
  or y0 > winy then
    timer 0
    notice "GAME OVER !!" + chr$( 13 ) _
    ; points ; " points ."
    close #m
    end
  end if
  for i = 100 to 1 step -1
    #m "spritexy? spr";i-1;" x y"
    if i <= length then
      #m "spritexy spr";i;" ";x;" ";y
    else
      #m "spritexy spr";i;" -50 -50"
    end if
  next
  #m "spritexy spr0 ";x0;" ";y0
  #m "spritecollides spr0 hit$"
  if instr( hit$ , "pil" ) then
    #m "spritexy pil ";int(range(128/32,(winx-128)/32))*32 _
                ;" ";int(range(128/32,(winy-128)/32))*32
    points = points + length
    if length < 100 then
      length = length + 1
    end if
    if length > 20 then
      if ms > 100 then
        ms = ms - 5
      end if
    end if
  end if
  if instr( hit$ , "spr" ) <> 0 _
  and instr( hit$ , "spr1" ) = 0 then
    timer 0
    notice "GAME OVER !!" + chr$(13) _
    ; points ; " points ."
    close #m
    end
  end if
  #m "drawsprites"
wait
[quit]
  close #m
end
bluatigro
 
Berichten: 306
Geregistreerd: za sep 27, 2008 6:01 pm

Re: SNAKE

Berichtdoor bluatigro » wo jan 14, 2015 11:28 am

update :
- de game gaat later sneller
- joystick toegevoegt

de max snelheid is nu 100ms
dus gamers laat me weten of de game is
- te snel , genoeg , te langzaam

Code: Selecteer alles
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
global winx , winy
winx = WindowWidth
winy = WindowHeight
global true , false , length , key$ , points , ms
true = not( false )
ms = 250
nomainwin
menu #m , "game" _
        , "info" , [info] _
        , "exit game" , [quit]
open "SNAKE 3.0" for graphics as #m
  #m "trapclose [quit]"
  for i = 0 to 15
    #m "goto 0 0"
    #m "backcolor black"
    #m "down"
    #m "boxfilled 32 64"
    #m "up"
    #m "backcolor 0 ";int(rnd(0)*255);" 0"
    #m "goto 0 32"
    #m "down"
    #m "boxfilled 32 64"
    #m "getbmp bmp";i;" 0 0 32 64"
  next i
  for i = 0 to 100
    #m "addsprite spr";i;" bmp";i mod 15 + 1
    #m "spritexy spr";i;" -50 -50"
  next i
  #m "spritexy spr0 128 128"
  #m "addsprite pil bmp0"
  #m "spritexy pil ";int(range(128/32,(winx-128)/32))*32 _
                ;" ";int(range(128/32,(winy-128)/32))*32
  #m "when characterInput [key]"
  #m "setfocus"
  length = 1
  timer ms , [tmr]
wait
function range( l , h )
  range = rnd(0) * ( h - l ) + l
end function
[info]
  r$ = chr$( 13 )
  timer 0
  text$ = "Welkome by snake ." + r$ _
  + "A game by bluatigro ." + r$ + r$ _
  + "Target of the game :" + r$ _
  + "You are a snake who eats mice ." + r$ _
  + "You wil grow and go faster ." + r$ _
  + "Dont go of the screen or byte yourself ."
  notice text$
  timer ms , [tmr]
wait
[key]
  key$ = right$( Inkey$ , 1 )
wait
[tmr]
  #m "spritexy? spr0 x0 y0"
  readjoystick 1
  if Joy1x < 256 * 256 / 3 then key$ = chr$( _VK_LEFT )
  if Joy1x > 256 * 256 * 2 / 3 then key$ = chr$( _VK_RIGHT )
  if Joy1y < 256 * 256 / 3 then key$ = chr$( _VK_UP )
  if Joy1y > 256 * 256 * 2 / 3 then key$ = chr$( _VK_DOWN )
  select case key$
    case chr$( _VK_UP )
      y0 = y0 - 32
    case chr$( _VK_DOWN )
      y0 = y0 + 32
    case chr$( _VK_LEFT )
      x0 = x0 - 32
    case chr$( _VK_RIGHT )
      x0 = x0 + 32
    case chr$( _VK_ESCAPE )
      timer 0
      notice "GAME INTERUPTED !!"
      close #m
      end
    case else
  end select
  if x0 < 0 _
  or x0 > winx _
  or y0 < 0 _
  or y0 > winy then
    timer 0
    notice "GAME OVER !!" + chr$( 13 ) _
    ; points ; " points ."
    close #m
    end
  end if
  for i = 100 to 1 step -1
    #m "spritexy? spr";i-1;" x y"
    if i <= length then
      #m "spritexy spr";i;" ";x;" ";y
    else
      #m "spritexy spr";i;" -50 -50"
    end if
  next
  #m "spritexy spr0 ";x0;" ";y0
  #m "spritecollides spr0 hit$"
  if instr( hit$ , "pil" ) then
    #m "spritexy pil ";int(range(128/32,(winx-128)/32))*32 _
                ;" ";int(range(128/32,(winy-128)/32))*32
    points = points + length
    if length < 100 then
      length = length + 1
    end if
    if length > 20 then
      if ms > 100 then
        ms = ms - 5
        timer ms , [tmr]
      end if
    end if
  end if
  if instr( hit$ , "spr" ) <> 0 _
  and instr( hit$ , "spr1" ) = 0 then
    timer 0
    notice "GAME OVER !!" + chr$(13) _
    ; points ; " points ."
    close #m
    end
  end if
  #m "drawsprites"
wait
[quit]
  close #m
end
bluatigro
 
Berichten: 306
Geregistreerd: za sep 27, 2008 6:01 pm

Re: SNAKE

Berichtdoor bluatigro » do jan 15, 2015 10:06 am

update :
- nu is versnelling een keuze
- auto start uitgezet

Code: Selecteer alles
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
global winx , winy
winx = WindowWidth
winy = WindowHeight
global true , false , length , key$ , points , ms , speeding
true = not( false )
ms = 250
confirm "Whit speeding up ?" ; yn$
if yn$ = "yes" then speeding = 1
nomainwin
menu #m , "game" _
        , "info" , [info] _
        , "exit game" , [quit]
open "SNAKE 3.0" for graphics as #m
  #m "trapclose [quit]"
  for i = 0 to 15
    #m "goto 0 0"
    #m "backcolor black"
    #m "down"
    #m "boxfilled 32 64"
    #m "up"
    #m "backcolor 0 ";int(rnd(0)*255);" 0"
    #m "goto 0 32"
    #m "down"
    #m "boxfilled 32 64"
    #m "getbmp bmp";i;" 0 0 32 64"
  next i
  for i = 0 to 100
    #m "addsprite spr";i;" bmp";i mod 15 + 1
    #m "spritexy spr";i;" -50 -50"
  next i
  #m "spritexy spr0 128 128"
  #m "addsprite pil bmp0"
  #m "spritexy pil ";int(range(128/32,(winx-128)/32))*32 _
                ;" ";int(range(128/32,(winy-128)/32))*32
  #m "when characterInput [key]"
  #m "setfocus"
  length = 1
  timer ms , [tmr]
wait
function range( l , h )
  range = rnd(0) * ( h - l ) + l
end function
[info]
  r$ = chr$( 13 )
  timer 0
  text$ = "Welkome by snake ." + r$ _
  + "A game by bluatigro ." + r$ + r$ _
  + "Target of the game :" + r$ _
  + "  You are a snake who eats mice ." + r$ _
  + "  You will grow and go faster ." + r$ _
  + "Don't go off the screen or bite yourself ."
  notice text$
  timer ms , [tmr]
wait
[key]
  key$ = right$( Inkey$ , 1 )
wait
[tmr]
  #m "spritexy? spr0 x0 y0"
  readjoystick 1
  if Joy1x <> 0 and Joy1y <> 0 then
    if Joy1x < 256 * 256 / 3 then key$ = chr$( _VK_LEFT )
    if Joy1x > 256 * 256 * 2 / 3 then key$ = chr$( _VK_RIGHT )
    if Joy1y < 256 * 256 / 3 then key$ = chr$( _VK_UP )
    if Joy1y > 256 * 256 * 2 / 3 then key$ = chr$( _VK_DOWN )
  end if
  select case key$
    case chr$( _VK_UP )
      y0 = y0 - 32
    case chr$( _VK_DOWN )
      y0 = y0 + 32
    case chr$( _VK_LEFT )
      x0 = x0 - 32
    case chr$( _VK_RIGHT )
      x0 = x0 + 32
    case chr$( _VK_ESCAPE )
      timer 0
      notice "GAME INTERUPTED !!"
      close #m
      end
    case else
  end select
  if x0 < 0 _
  or x0 > winx _
  or y0 < 0 _
  or y0 > winy then
    timer 0
    notice "GAME OVER !!" + chr$( 13 ) _
    ; points ; " points ."
    close #m
    end
  end if
  for i = 100 to 1 step -1
    #m "spritexy? spr";i-1;" x y"
    if i <= length then
      #m "spritexy spr";i;" ";x;" ";y
    else
      #m "spritexy spr";i;" -50 -50"
    end if
  next
  #m "spritexy spr0 ";x0;" ";y0
  #m "spritecollides spr0 hit$"
  if instr( hit$ , "pil" ) then
    #m "spritexy pil ";int(range(128/32,(winx-128)/32))*32 _
                ;" ";int(range(128/32,(winy-128)/32))*32
    points = points + length
    if length < 100 then
      length = length + 1
    end if
    if speeding then
      if length > 20 then
        if ms > 100 then
          ms = ms - 5
          timer ms , [tmr]
        end if
      end if
    end if
  end if
  if instr( hit$ , "spr" ) <> 0 _
  and instr( hit$ , "spr1" ) = 0 then
    timer 0
    notice "GAME OVER !!" + chr$(13) _
    ; points ; " points ."
    close #m
    end
  end if
  #m "drawsprites"
wait
[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