TGC Codebase Backup



pac man by dared

20th Nov 2004 6:23
Summary

the pacman game but faster. code origanaly by: Kevin Carthew. i added the sync to make it faster



Description



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    sync on
`pacman mess-about code

`To do list:
`1. Improve frame rate!
`2. Make ghost obey maze collision
`3. Make pacman's collision less fiddly when turning corners
`4. Power pills!
`5. Make pacman animate while holding down directional key in directions: l,u,d (image frame is always reset!)
`6. Second ghost

`sprites 1 - 16 are currently the four frames of animation in each of the four directions pacman can face
`sprites 17 - 20 are currently the four frames of the pink ghost
`sprites 21 - 24 are the four frames of the blue ghost (currently unused)
`sprites 25 and 26 are the two frames when the ghosts are scared (currently unused)
`sprite 27 is the pill, 28 is the power pill (currently unused)
`sprites 29 - 36 are the maze pieces (piece 35 is currently unused)

`load sprite bank bitmap into bank 1
LOAD BITMAP "pacman2.bmp",1
HIDE MOUSE

`cut invidual frames from bitmap, cuts 16 frames in total for pacman
`4 for pink, 4 for blue, 2 frames for the scared flashing ghost, 2 for each type of pill
FOR y=0 to 6
   FOR x=0 TO 3
      GET IMAGE 1+x+(y*4),(x*64),(y*64),(x*64)+64,(y*64)+64
   NEXT x
NEXT y
`cuts 8 individual frames for maze
FOR y=0 to 7
   GET IMAGE y+29,256,(y*64),256+64,(y*64)+64
NEXT y

`now that all the individual frames are stored in memory we can delete the bitmap
DELETE BITMAP 1

`these variables are used to set pacman's starting position and starting anim image
xpos=64
ypos=352
image=1
`this one determines pacman's direction (1=r/2=l/3=u/4=d)
pacd=1

`these variables are used to set pinky's starting position and starting anim image
p_xpos = 320
p_ypos = 176
p_image = 17
`determines pinky's direction
pinkyd = 4
`counts how many units pinky has moved before thinking about changing direction
pinkysteps = 0
`value used for when pinky actually thinks about changing direction (increase to travel in straight line longer)
pinkychange = 40

`manual sync
SYNC ON
SYNC RATE 30
`build the maze (REMEMBER - use an array to do this eventually!!), all maze sprites >2 and <41
`1
sprite 3,0,32,29 : sprite 4,64,32,34 : sprite 5,128,32,34 : sprite 6,192,32,34 : sprite 7,256,32,31
sprite 8,320,32,29 : sprite 9,384,32,34 : sprite 10,448,32,34 : sprite 11,512,32,34 : sprite 12,576,32,31
`2
sprite 13,0,96,33 : sprite 14,256,96,30 : sprite 15,320,96,32 : sprite 16,576,96,33
`3
sprite 17,0,160,32 : sprite 18,128,160,36 : sprite 19,448,160,36 : sprite 20,576,160,30
`4
sprite 21,256,224,36 : sprite 22,320,224,36
`5
sprite 23,0,288,31 : sprite 24,128,288,36 : sprite 25,448,288,36 : sprite 26,576,288,29
`6
sprite 27,0,352,33 : sprite 28,256,352,29 : sprite 29,320,352,31 : sprite 30,576,352,33
`7
sprite 31,0,416,30 : sprite 32,64,416,34 : sprite 33,128,416,34 : sprite 34,192,416,34 : sprite 35,256,416,32
sprite 36,320,416,30 : sprite 37,384,416,34 : sprite 38,448,416,34 : sprite 39,512,416,34 : sprite 40,576,416,32

`place the pills (REMEMBER - use an array to do this eventually!!), all pill sprites = >40 and <72
`1
sprite 41,64,96,27 : sprite 42,128,96,27 : sprite 43,192,96,27 : sprite 44,384,96,27 : sprite 45,448,96,27
sprite 46,512,96,27
`2
sprite 47,64,160,27 : sprite 48,192,160,27 : sprite 49,256,160,27 : sprite 50,320,160,27 : sprite 51,384,160,27
sprite 52,512,160,27
`3
sprite 53,0,224,27 : sprite 54,64,224,27 : sprite 55,128,224,27 : sprite 56,192,224,27 : sprite 57,384,224,27
sprite 58,448,224,27 : sprite 59,512,224,27 : sprite 60,576,224,27
`4
sprite 61,64,288,27 : sprite 62,192,288,27 : sprite 63,256,288,27 : sprite 64,320,288,27 : sprite 65,384,288,27
sprite 66,512,288,27
`5
sprite 67,128,352,27 : sprite 68,192,352,27 : sprite 69,384,352,27 : sprite 70,448,352,27 : sprite 71,512,352,27
` place pac
sprite 1,xpos,ypos,image

`main loop
DO
   if rightkey()=1 then pacd=1
   if leftkey()=1 then pacd=2 : image = 5
   if upkey()=1 then pacd=3 : image = 9
   if downkey()=1 then pacd=4 : image = 13

   old_xpos = xpos
   old_ypos = ypos

   if pacd = 1 then gosub moveright
   if pacd = 2 then gosub moveleft
   if pacd = 3 then gosub moveup
   if pacd = 4 then gosub movedown

   sprite 1,xpos,ypos,image
   p_collide=SPRITE COLLISION(1,0)

   if p_collide>2 AND p_collide<41
      xpos = old_xpos
      ypos = old_ypos
      sprite 1,xpos,ypos,image
   endif

   if p_collide>40
      delete sprite p_collide
   endif

   gosub update_pinky
   sprite 2,p_xpos,p_ypos,p_image

   IF SPRITE COLLISION(1,2)=1 THEN gosub resetpac

   SYNC
LOOP

update_pinky:
   if pinkyd = 1
      p_xpos = p_xpos + 6
      if p_xpos>640 then p_xpos = -64
      p_image = 18
   endif

   if pinkyd = 2
      p_xpos = p_xpos - 6
      if p_xpos<-64 then p_xpos = 640
      p_image = 17
   endif

   if pinkyd = 3
      p_ypos = p_ypos - 6
      if p_ypos<-64 then p_ypos = 480
      p_image = 19
   endif

   if pinkyd = 4
      p_ypos = p_ypos + 6
      if p_ypos>480 then p_ypos = -64
      p_image = 20
   endif

   pinkysteps = pinkysteps + 1
   if pinkysteps = pinkychange
      pinkyd = RND(4)
      if pinkyd = 0 then pinkyd = 1
      pinkysteps = 0
   endif
return

moveright:
      xpos=xpos+4
      IF xpos>640 THEN xpos=-64
      image=image+1
      IF image>4 THEN image=1
return

moveleft:
      xpos=xpos-4
      IF xpos<-64 THEN xpos=640
      image=image+1
      IF image>8 THEN image=5
return

moveup:
      ypos=ypos-4
      IF ypos<-64 THEN ypos=480
      image=image+1
      IF image>12 THEN image=9
return

movedown:
      ypos=ypos+4
      IF ypos>480 THEN ypos=-64
      image=image+1
      IF image>16 THEN image=13
return

resetpac:
   xpos=64
   ypos=352
   image=1
   pacd = 1
return

sync