PAC MAN 2

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

Moderator: anthonio

PAC MAN 2

Berichtdoor bluatigro » wo maart 21, 2012 1:38 pm

dit is mijn 2e poging met pac man

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

NIET VERGETEN : pas path in code aan waneer nodig

error :
- points zijn niet zichbaar

toekomst :
- spoken te jagen
- geluid
- joystick

Code: Selecteer alles
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
global winx , winy
winx = WindowWidth
winy = WindowHeight
global px , py , pdx , pdy , level , lastkey$ , timercount , points , pointlevel
global caught , flee , hunt , warning
caught = 1
flee = 2
hunt = 3
warning = 4
dim maze$( 20 , 20 )
loadbmp "caught"  , DefaultDir$ + "\BMP\caught.bmp"
loadbmp "empty"   , DefaultDir$ + "\BMP\empty.bmp"
loadbmp "flee"    , DefaultDir$ + "\BMP\flee.bmp"
loadbmp "human"   , DefaultDir$ + "\BMP\human.bmp"
loadbmp "hunt"    , DefaultDir$ + "\BMP\hunt.bmp"
loadbmp "pil"     , DefaultDir$ + "\BMP\pil.bmp"
loadbmp "super"   , DefaultDir$ + "\BMP\super.bmp"
loadbmp "wall"    , DefaultDir$ + "\BMP\wall.bmp"
loadbmp "warning" , DefaultDir$ + "\BMP\warning.bmp"
nomainwin
open "PAC MAN" for graphics as #m
  #m "trapclose [quit]"
  for x = 0 to 20
    for y = 0 to 20
      #m "addsprite maze" ; x ; "_" ; y ; " empty pil super wall"
    next y
  next x
  for i = 0 to 9
    #m "addsprite ghost";i;" caught flee hunt warning"
  next i
  #m "addsprite human human"
  #m "setfocus"
  #m "when characterInput [read_key]"
  call resetmaze
  timer 40 , [timer_tick]
wait
[read_key]
  lastkey$ = Inkey$
wait
[timer_tick]
  if timercount = 0 then
    #m "goto 50 50"
    #m "font Courier_new 50 bold"
    #m "\POINTS : " ; points
    #m "flush"
    px = px + pdx
    py = py + pdy
    pdx = 0
    pdy = 0
    select case right$( lastkey$ , 1 )
      case chr$( _VK_UP )
        if maze$( px , py - 1 ) <> "M" then  pdy = -1
      case chr$( _VK_RIGHT )
        if maze$( px + 1 , py ) <> "M" then  pdx = 1
      case chr$( _VK_DOWN )
        if maze$( px , py + 1 ) <> "M" then  pdy = 1
      case chr$( _VK_LEFT )
        if maze$( px - 1 , py ) <> "M" then  pdx = -1
      case else
    end select
    select case maze$( px , py )
      case "."
        maze$( px , py ) = " "
        points = points + 1
        pointlevel = pointlevel - 1
      case "@"
        maze$( px , py ) = " "
        points = points + 10
        pointlevel = pointlevel - 1
      case else
    end select
    lastey$ = "*"
  end if
  for x = 0 to 20
    for y = 0 to 20
      if timercount = 0 then
        select case maze$( x , y )
          case "M"  : m$ = "wall"
          case "."  : m$ = "pil"
          case "@"  : m$ = "super"
          case else : m$ = "empty"
        end select
        #m "spriteimage maze" ; x ; "_" ; y ; " " ; m$
      end if
      #m "spritexy maze" ; x ; "_" ; y ; " " _
      ; winx / 2 - 32 + x * 64 - px * 64 - pdx * timercount * 2 ; " " _
      ; winy / 2 - 32 + y * 64 - py * 64 - pdy * timercount * 2
    next y
  next x
  if pointlevel <= 0 then
    timer 0
    call resetmaze
    timer 40 , [tmr]
  end if
  for i = 0 to level
    if timercount = 0 then
      gx( i ) = gx( i ) + gdx( i )
      gy( i ) = gy( i ) + gdy( i )
      dicex = 0
      dicey = 0
      while abs( dicex ) = abs( dicey ) _
      or maze$( gx( i ) + dicex , gy( i ) + dicey ) = "M"
        dicex = int( rnd( 0 ) * 4 - 2 )
        dicey = int( rnd( 0 ) * 4 - 2 )
      wend
      gdx( i ) = dicex
      gdy( i ) = dicey
      #m "spriteimage ghost" ; i ; " " ; word$( "caught flee hunt warning" , gst( i ) )
      if gx( i ) = px and gy( i ) = py then
        if gst( i ) = hunt then
          timer  0
          notice "POINTS :" + chr$( 13 ) ; points
          goto [quit]
        else
          if gst( i ) = flee then
            gst( i ) = caught
            points = points + 100
          end if
        end if
      end if
    end if
    #m "spritexy ghost" ; i ; " " _
    ; winx / 2 - 32 + gx( i ) * 64 + gdx( i ) * timercount * 2 _
    - px * 64 - pdx * timercount * 2; " " _
    ; winy / 2 - 32 + gy( i ) * 64 + gdy( i ) * timercount * 2 _
    - py * 64 - pdy * timercount * 2
  next i
  #m "spritexy human " ; winx / 2 - 32 ; " " ; winy / 2 - 32
  #m "drawsprites"

  timercount = ( timercount + 1 ) mod 32
wait
sub resetmaze
  px = 6
  py = 9
  if level < 10 then level = level + 1
  for i = 0 to level
    gx( i ) = 6
    gy( i ) = 5
    gst( i ) = hunt
  next i
  restore
  pointlevel = 0
  while a$ <> "="
    read a$
    for x = 1 to len( a$ )
      maze$( x , y ) = mid$( a$ , x , 1 )
      select case mid$( a$ , x , 1 )
        case "M"
          #m "spriteimage maze" ; x ; "_" ; y ; " wall"
        case "."
          #m "spriteimage maze" ; x ; "_" ; y ; " pil"
          pointlevel = pointlevel + 1
        case "@"
          #m "spriteimage maze" ; x ; "_" ; y ; " super"
          pointlevel = pointlevel + 1
        case else
          #m "spriteimage maze" ; x ; "_" ; y ; " empty"
      end select
    next x
    y = y + 1
  wend

  data "MMMMMMMMMMMMMMMMMMM"
  data "M@.......@.......@M"
  data "M.MMM MMM.MMM MMM.M"
  data "M.M.....M.M.....M.M"
  data "M.M.M M.M.M.M.M.M.M"
  data "M. .   . . .   . .M"
  data "M.M.M M.M.M.M M.M.M"
  data "M.M.....M.M.....M.M"
  data "M.MMM MMM.MMM MMM.M"
  data "M@.......@.......@M"
  data "M.MMM MMM.MMM MMM.M"
  data "M.M.....M.M.....M.M"
  data "M.M.M M.M.M.M.M.M.M"
  data "M. .   . . .   . .M"
  data "M.M.M M.M.M.M M.M.M"
  data "M.M.....M.M.....M.M"
  data "M.MMM MMM.MMM MMM.M"
  data "M@.......@.......@M"
  data "MMMMMMMMMMMMMMMMMMM"
  data "="
end sub
[quit]
  unloadbmp "caught"
  unloadbmp "empty"
  unloadbmp "flee"
  unloadbmp "human"
  unloadbmp "hunt"
  unloadbmp "pil"
  unloadbmp "super"
  unloadbmp "wall"
  unloadbmp "warning"
  close #m
end
bluatigro
 
Berichten: 306
Geregistreerd: za sep 27, 2008 6:01 pm

Re: PAC MAN 2

Berichtdoor bluatigro » vr maart 23, 2012 12:00 pm

update :
- spoken zijn nu jaagbaar
- spoken zijn verschilend agresief / bang

toekomst :
- geluid
- joystick

senario : [ dat wat zou moeten gebeuren ]
je heb 1 leven
je eet de pillen en krijgt punten
je ontwijkt de spoken
je eet een superpil en jaagt n tijdje op de spoken
als alle pillen en superpillen gegeten zijn
komt r n nieuw level
met elk level wordt een meer agresive / angstige spook toegevoegd
tot r 9 spoken zijn
punten :
pil 1 punt
superpil 10 punten
spook 100 punten

gamers : test dit aub
Code: Selecteer alles
WindowWidth = DisplayWidth
WindowHeight = DisplayHeight
global winx , winy
winx = WindowWidth
winy = WindowHeight
global px , py , pdx , pdy , level , lastkey$ , timercount , points , pointlevel
global caught , flee , hunt , warning , move , ghostcount
caught = 1
flee = 2
hunt = 3
warning = 4
move = 4
dim maze$( 20 , 20 )
loadbmp "caught"  , DefaultDir$ + "\BMP\caught.bmp"
loadbmp "empty"   , DefaultDir$ + "\BMP\empty.bmp"
loadbmp "flee"    , DefaultDir$ + "\BMP\flee.bmp"
loadbmp "human"   , DefaultDir$ + "\BMP\human.bmp"
loadbmp "hunt"    , DefaultDir$ + "\BMP\hunt.bmp"
loadbmp "pil"     , DefaultDir$ + "\BMP\pil.bmp"
loadbmp "super"   , DefaultDir$ + "\BMP\super.bmp"
loadbmp "wall"    , DefaultDir$ + "\BMP\wall.bmp"
loadbmp "warning" , DefaultDir$ + "\BMP\warning.bmp"
nomainwin
open "PAC MAN" for graphics as #m
  #m "trapclose [quit]"
  for x = 0 to 20
    for y = 0 to 20
      #m "addsprite maze" ; x ; "_" ; y ; " empty pil super wall"
    next y
  next x
  for i = 0 to 9
    #m "addsprite ghost";i;" caught flee hunt warning"
  next i
  #m "addsprite human human"
  #m "setfocus"
  #m "when characterInput [read_key]"
  call resetmaze
  timer 200 , [timer_tick]
wait
[read_key]
  lastkey$ = Inkey$
wait
[timer_tick]
  if timercount = 0 then
''    #m "goto 50 50"
''    #m "font Courier_new 50 bold"
''    #m "\POINTS : " ; points
''    #m "flush"
    px = px + pdx
    py = py + pdy
    pdx = 0
    pdy = 0
    select case right$( lastkey$ , 1 )
      case chr$( _VK_UP )
        if maze$( px , py - 1 ) <> "M" then  pdy = -1
      case chr$( _VK_RIGHT )
        if maze$( px + 1 , py ) <> "M" then  pdx = 1
      case chr$( _VK_DOWN )
        if maze$( px , py + 1 ) <> "M" then  pdy = 1
      case chr$( _VK_LEFT )
        if maze$( px - 1 , py ) <> "M" then  pdx = -1
      case else
    end select
    select case maze$( px , py )
      case "."
        maze$( px , py ) = " "
        points = points + 1
        pointlevel = pointlevel - 1
      case "@"
        maze$( px , py ) = " "
        points = points + 10
        pointlevel = pointlevel - 1'
        ghosttimer = 20
        for i = 0 to level
          gst( i ) = flee
        next i
      case else
    end select
    lastey$ = "*"
  end if
  for x = 0 to 20
    for y = 0 to 20
      if timercount = 0 then
        select case maze$( x , y )
          case "M"  : m$ = "wall"
          case "."  : m$ = "pil"
          case "@"  : m$ = "super"
          case else : m$ = "empty"
        end select
        #m "spriteimage maze" ; x ; "_" ; y ; " " ; m$
      end if
      #m "spritexy maze" ; x ; "_" ; y ; " " _
      ; winx / 2 - 32 + x * 64 - px * 64 - pdx * timercount * move ; " " _
      ; winy / 2 - 32 + y * 64 - py * 64 - pdy * timercount * move
    next y
  next x
  if pointlevel <= 0 then
    timer 0
    call resetmaze
    timer 200 , [tmr]
  end if
  for i = 0 to level
    if timercount = 0 then
      if ghosttimer > 0 then ghosttimer = ghosttimer - 1
      if ghosttimer < 5 then gst( i ) = warning
      if ghosttimer <= 0 then gst( i ) = hunt
''      #m "spritecollides human list$"
''      if instr( list$ , "ghost" ; i ) then
''        select case gst( i )
''          case hunt
''            timer 0
''            notice "POINTS :" + chr$( 13 ) ; points
''            goto [quit]
''          case flee
''            ghosttimer = 20
''            points = points + 100
''            gst( i ) = caught
''          case else
''        end select
''      end if
      gx( i ) = gx( i ) + gdx( i )
      gy( i ) = gy( i ) + gdy( i )
      dicex = 0
      dicey = 0
      select case gst( i )
        case hunt
          if rnd( 0 ) < i / 10 then
            if gx( i ) < px and maze$( gx( i ) + 1 , gy( i ) ) <> "M" then dicex = 1
            if gx( i ) > py and maze$( gx( i ) - 1 , gy( i ) ) <> "M" then dicex = -1
            if gy( i ) < py and maze$( gx( i ) , gy( i ) + 1 ) <> "M" then dicey = 1
            if gy( i ) > py and maze$( gx( i ) , gy( i ) - 1 ) <> "M" then dicey = -1
          end if
        case flee
          if rnd( 0 ) < i / 10 then
            if gx( i ) > px and maze$( gx( i ) + 1 , gy( i ) ) <> "M" then dicex = 1
            if gx( i ) < py and maze$( gx( i ) - 1 , gy( i ) ) <> "M" then dicex = -1
            if gy( i ) > py and maze$( gx( i ) , gy( i ) + 1 ) <> "M" then dicey = 1
            if gy( i ) < py and maze$( gx( i ) , gy( i ) - 1 ) <> "M" then dicey = -1
          end if
        case else
      end select
      while abs( dicex ) = abs( dicey ) _
      or maze$( gx( i ) + dicex , gy( i ) + dicey ) = "M"
        dicex = int( rnd( 0 ) * 4 - 2 )
        dicey = int( rnd( 0 ) * 4 - 2 )
      wend
      gdx( i ) = dicex
      gdy( i ) = dicey
      #m "spriteimage ghost" ; i ; " " ; word$( "caught flee hunt warning" , gst( i ) )
      if gx( i ) = px and gy( i ) = py then
        if gst( i ) = hunt then
          timer  0
          notice "POINTS :" + chr$( 13 ) ; points
          goto [quit]
        else
          if gst( i ) = flee then
            gst( i ) = caught
            points = points + 100
            ghosttimer = 20
          end if
        end if
      end if
    end if
    #m "spritexy ghost" ; i ; " " _
    ; winx / 2 - 32 + gx( i ) * 64 + gdx( i ) * timercount * move _
    - px * 64 - pdx * timercount * move ; " " _
    ; winy / 2 - 32 + gy( i ) * 64 + gdy( i ) * timercount * move _
    - py * 64 - pdy * timercount * move
  next i
  #m "spritexy human " ; winx / 2 - 32 ; " " ; winy / 2 - 32
  #m "drawsprites"

  timercount = ( timercount + 1 ) mod ( 64 / move )
wait
sub resetmaze
  px = 6
  py = 9
  if level < 10 then level = level + 1
  for i = 0 to 9
    gx( i ) = 2
    gy( i ) = 2
    gst( i ) = hunt
  next i
  restore
  pointlevel = 0
  while a$ <> "="
    read a$
    for x = 1 to len( a$ )
      maze$( x , y ) = mid$( a$ , x , 1 )
      select case mid$( a$ , x , 1 )
        case "M"
          #m "spriteimage maze" ; x ; "_" ; y ; " wall"
        case "."
          #m "spriteimage maze" ; x ; "_" ; y ; " pil"
          pointlevel = pointlevel + 1
        case "@"
          #m "spriteimage maze" ; x ; "_" ; y ; " super"
          pointlevel = pointlevel + 1
        case else
          #m "spriteimage maze" ; x ; "_" ; y ; " empty"
      end select
    next x
    y = y + 1
  wend

  data "MMMMMMMMMMMMMMMMMMM"
  data "M@.......@.......@M"
  data "M.MMM MMM.MMM MMM.M"
  data "M.M.....M.M.....M.M"
  data "M.M.M M.M.M.M.M.M.M"
  data "M. .   . . .   . .M"
  data "M.M.M M.M.M.M M.M.M"
  data "M.M.....M.M.....M.M"
  data "M.MMM MMM.MMM MMM.M"
  data "M@.......@.......@M"
  data "M.MMM MMM.MMM MMM.M"
  data "M.M.....M.M.....M.M"
  data "M.M.M M.M.M.M.M.M.M"
  data "M. .   . . .   . .M"
  data "M.M.M M.M.M.M M.M.M"
  data "M.M.....M.M.....M.M"
  data "M.MMM MMM.MMM MMM.M"
  data "M@.......@.......@M"
  data "MMMMMMMMMMMMMMMMMMM"
  data "="
end sub
[quit]
  unloadbmp "caught"
  unloadbmp "empty"
  unloadbmp "flee"
  unloadbmp "human"
  unloadbmp "hunt"
  unloadbmp "pil"
  unloadbmp "super"
  unloadbmp "wall"
  unloadbmp "warning"
  close #m
end
bluatigro
 
Berichten: 306
Geregistreerd: za sep 27, 2008 6:01 pm

Re: PAC MAN 2

Berichtdoor bluatigro » za maart 24, 2012 1:53 pm

wat vragen voor de gamers onder jullie :

- hoeveel levens moet de speler krijgen ?

- is het doolhof de juiste grootte ?

- is 9 spoken te veel / wijnig ?

- is 90% agresie [ voor spook 9 ] te veel ?

- zal ik een loop uit rechts / boven = loop in links / beneden weg maken ?

- zijn r andere ideeen voor verbeteringen ?
bluatigro
 
Berichten: 306
Geregistreerd: za sep 27, 2008 6:01 pm

Re: PAC MAN 2

Berichtdoor Gordon » za maart 24, 2012 5:07 pm

Ik heb ghosttiemer gewijzigd in ghosttimer
en ik heb de timer van 40 naar 200 gewijzigd.

Nu kunnen ook de langzame computers de game verwerken.

De sprites zijn nog niet foutloos.
Er blijft een zwarte streep onder elke sprite staan.

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