PAC MAN 3

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

Moderator: anthonio

PAC MAN 3

Berichtdoor bluatigro » di dec 23, 2014 12:52 pm

sprites :
www.basic.wikispaces.com/How+to+draw+your+Sprites

WAARSCHUWING :
- deze code stopt niet mooi
- path v sprites veranderen als dat nodig is

error :
- speler sprite reageert niet op toetsen

TODO :
- geluid
- puntentelling
- joystick [ is r al in REM ]

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 , ghosttimer , joystick
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]"
  #m "fill black"
  #m "getbmp backgr 0 0 2 2"
  #m "background backgr"
  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
''  readjoystick 1
''  if joy1x <> 0 and joy1y <> 0 then
''    confirm "Joystick detected :" + chr$( 13 ) _
''          + "Use Joystick ?" ; yn$
''    if yn$ = "yes" then joystick = not( 0 )
''  end if
  timer 25 , [timer_tick]
wait
[timer_tick]
  if timercount = 0 then
    px = px + pdx
    py = py + pdy
    pdx = 0
    pdy = 0
''    if joystick then
''      if joy1y < 256 * 256 / 3 _
''      and maze$( px , py - 1 ) <> "M" then pdy = -1
''      if joy1x > 256 * 256 * 2 / 3 _
''      and maze$( px + 1 , py ) <> "M" then pdx = 1
''      if joy1y > 256 * 256 * 2 / 3 _
''      and maze$( px , py + 1 ) <> "M" then pdy = 1
''      if joy1x < 256 * 256 / 3 _
''      and maze$( px - 1 , py ) <> "M" then pdx = -1
''    else
      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
''    end if
    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
    if ghosttimer < 5 and ghosttimer > 0 then
      for i = 0 to level
        gst( i ) = warning
      next i
    end if
    if ghosttimer >= 0 then
      ghosttimer = ghosttimer - 1
    else
      for i = 0 to level
        gst( i ) = hunt
      next i
    end if
    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 25 , [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
      select case gst( i )
        case hunt
          if rnd(0)*10 < i then
            dicex = sign( px - gx( i ) )
            dicey = sign( py - gy( i ) )
          end if
        case flee
          dicex = sign( gx( i ) - px )
          dicey = sign( gy( i ) - py )
        case else
      end select
      if abs( dicex ) = abs( dicey ) then
        if rnd(0) < 0.5 then
          dicex = 0
        else
          dicey = 0
        end if
      end if
      while abs( dicex ) = abs( dicey ) _
      or maze$( gx( i ) + dicex , gy( i ) + dicey ) = "M"
        dicex = int( rnd( 0 ) * 3 ) - 1
        dicey = int( rnd( 0 ) * 3 ) - 1
      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
[read_key]
  lastkey$ = Inkey$
  if lastkey$ <> chr$( 27 ) then wait
[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

Keer terug naar Games

Wie is er online

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

cron