I'm working on this Pacman program and I have it at the point where the Ghost come out of the pen and move around the maze. I don't have any ghost/pacman collision yet so they should just move around indefinitely. Instead, whether it's 30 seconds or 2 minutes into the program, it exits back to DBEdit with the message "Compilation Successful". No error message or explanation on why it exited. Any thoughts on why that would be?
rem Pacman game
rem Started 12/17/08
LOCK CLI
Dim CreateMaze(18,21)
Dim sprs_maze(18,21)
dim pac_try(1): rem DarkEDIT global replacement
dim pac_dir(1): rem DarkEDIT global replacement
dim spr_pac(1): rem DarkEDIT global replacement
dim pac_spnx(1): rem DarkEDIT global replacement
dim pac_spny(1): rem DarkEDIT global replacement
dim pac_img(1): rem DarkEDIT global replacement. Hold imgage #s for pacman animation
dim Player(2,2): rem Hold player lives and score
dim Life(1): rem Hold sprite numbers for sprites showing number of live remaining
dim ghost_spr(4): rem sprite numbers for ghost
dim ghost_img(4,4,2) :rem Image numbers for each sprite animation
dim ghost_pen(4,1) :rem (4,0) = If Ghost in pen = 0 if in maze = 1. (4,1) = waiting for turn = 0 getting out = 1
dim ghost_dir(4,1) : rem Direction Ghost is currently moving
dim ghost_options(4,4) : rem movement options for particular ghost. 1-right 2-down 3-left 4-up if these array values
Dim HoldChoices(4) : rem holds choices for AI
`equal 0, movment in that direction is NOT possible if equal 1 then movment in that direction IS possible
dim Rdtime(1) : rem Timer starts at begining of new round. Used to time ghost getting out of pen
`****************Sprite numbers *****************************************
spr_pac(1) = 2
Ready = 3 : `Ready
Life(0) = 4 : Life(1) = 5:`Pacman representing the number of lives left
ghost_spr(1) = 6 : `red ghost
ghost_spr(2) = 7 : `yellow ghost
ghost_spr(3) = 8 : `pink ghost
ghost_spr(4) = 9 : `blue ghost
`************************************************************************
Gosub Setup
`Gosub StartScreen : `Need to add startup screen to choose # player, show point values, etc
Gosub Initilize
Gosub LoadImages
Gosub LoadAudio
Gosub CreateMaze
Gosub MazeArray
Gosub GhostAnimationArray
`Gosub Placedots : ` Took out for now to speed up game
Gosub New_Round
`*********************************Main Loop***************************************
`*********************************************************************************
Repeat
Cls
`*******The follwing are for testing*******************************
`Set Cursor 800,20 : Print "pac_try = ";pac_try
`Set Cursor 800,110 : Print "Pac_dir"; pac_dir
`Set Cursor 800,150 : Print "sprs_maze (c,r) ="; sprs_maze(column, row)
`Set Cursor 800,190 : Print "MouseX = "; MouseX()
`Set Cursor 800,210 : Print "MouseY = "; MouseY()
text 700,300, "Small dots left = " + str$(Sdot_ctr - 200)
text 700,275, "Big dots left = " + str$(Bdot_ctr -100)
text 700,250, "Frames Per Second: " + str$(screen fps())
`*************END OF STUFF FOR TESTING****************************
text 700,10, "PLAYER 1 " + str$(player(1,1))
If Num_players = 2 then text 700,50, "PLAYER 2 " + str$(player(2,1))
get_pac_move
move_pac
`Check for end of game for either player
`Check for dot collision
Hit_dot = Sprite Hit(spr_pac(1),0)
If Hit_dot => 100 and Hit_dot < Sdot_ctr then Gosub Eat_Dot
`Check for Pacman collision with Ghost
`Move Ghost
move_ghost
`Check for ghost collision with Pacman
Sync
Until EscapeKey() = 1
End
`******************************END OF MAIN LOOP***********************************
`**************************Get player input***************************************
Function get_pac_move()
select pac_try(1)
case 0
if upkey() then pac_try(1) = 1
if rightkey() then pac_try(1) = 2
if downkey() then pac_try(1) = 3
if leftkey() then pac_try(1) = 4
endcase
case 1
if upkey() = 0 then pac_try(1) = 0
endcase
case 2
if rightkey() = 0 then pac_try(1) = 0
endcase
case 3
if downkey() = 0 then pac_try(1) = 0
endcase
case 4
if leftkey() = 0 then pac_try(1) = 0
endcase
endselect
Endfunction
`***************************Move pac-man***************************************
`******************************************************************************
Function move_pac()
`cache Pac-Man position
xpos = sprite x(spr_pac(1))
ypos = sprite y(spr_pac(1))
`find current tile Pac-Man is in
column = xpos/32
row = ypos/32
`check if Pac-Man is completely in a tile
if xpos/32.0 = column and ypos/32.0 = row
`Pac-Man is completely in a square, now give player chance to change direction
`if there's an open tile
select pac_try(1)
case 1
`If moving up
if sprs_maze(column, row-1) < 3 then pac_dir(1) = 1
endcase
case 2
`If moving right
If sprs_maze(column+1, row) < 3 then pac_dir(1) = 2
endcase
case 3
`If moving down
if sprs_maze(column, row+1) < 3 then pac_dir(1) = 3
endcase
case 4
`If moving left
if sprs_maze(column-1, row) < 3 then pac_dir(1) = 4
endcase
endselect
`stop Pac-Man from moving if he's about to walk into a wall
select pac_dir(1)
case 1
if sprs_maze(column, row-1) => 3 then pac_dir(1) = 0
endcase
case 2
if sprs_maze(column+1, row) => 3 then pac_dir(1) = 0
endcase
case 3
if sprs_maze(column, row+1) => 3 then pac_dir(1) = 0
endcase
case 4
if sprs_maze(column-1, row) => 3 then pac_dir(1) = 0
endcase
endselect
endif
select pac_dir(1)
case 1
dec ypos
If pac_img(1) = 94 and ypos/2 = ypos/2.0
pac_img(1) = 95
Else
pac_img(1) = 94
EndiF
If Sprite Flipped(spr_pac(1)) = 1 then Flip Sprite spr_pac(1)
endcase
case 2
inc xpos
If pac_img(1) = 52 and xpos/2 = xpos/2.0
pac_img(1) = 53
Else
pac_img(1) = 52
Endif
If Sprite Mirrored(spr_pac(1)) = 1 then Mirror Sprite spr_pac(1)
If Sprite Flipped(spr_pac(1)) = 1 then Flip Sprite spr_pac(1)
endcase
case 3
inc ypos
If pac_img(1) = 94 and ypos/2 = ypos/2.0
pac_img(1) = 95
Else
pac_img(1) = 94
EndiF
If Sprite Flipped(spr_pac(1)) = 0 then Flip Sprite spr_pac(1)
If Sprite Mirrored(spr_pac(1)) = 1 then Mirror Sprite spr_pac(1)
endcase
case 4
dec xpos
If pac_img(1) = 52 and xpos/2 = xpos/2.0
pac_img(1) = 53
Else
pac_img(1) = 52
Endif
If Sprite Mirrored(spr_pac(1)) = 0 then Mirror Sprite spr_pac(1)
If Sprite Flipped(spr_pac(1)) = 1 then Flip Sprite spr_pac(1)
endcase
endselect
`If pacman at one wrap point place at other wrap point
If xpos = 0 and ypos = 320 then xpos = 575
IF xpos = 576 and ypos = 320 then xpos = 0
`Move pacman sprite
Sprite spr_pac(1), xpos, ypos, pac_img(1)
Endfunction
rem ********************MOVE GHOST FUNCTION**************************************
Function move_ghost()
`If Ghost in pen, move out into maze
Elapsed=(Timer()-Rdtime(1))/1000
For x = 1 to 4
If ghost_pen(x,0) = 0 and Elapsed < 40 then fisrttimeoutofpen(x,Elapsed)
Next x
`If ghost is out of the pen cache ghost position
For G = 1 to 4
If ghost_pen(G,0) = 1
gxpos = sprite x(ghost_spr(G))
gypos = sprite y(ghost_spr(G))
`find current tile Ghost is in
gcolumn = gxpos/32
grow = gypos/32
`check if Pac-Man is completely in a tile
if gxpos/32.0 = gcolumn and gypos/32.0 = grow
`Load ghost movement options into array
`Check up
If sprs_maze(gcolumn, grow-1) = 3
ghost_options(G,4) = 0
Else
ghost_options(G,4) = 1
Endif
`Check right
If sprs_maze(gcolumn+1, grow) = 3
ghost_options(G,1) = 0
Else
ghost_options(G,1) = 1
Endif
`Check Down
If sprs_maze(gcolumn, grow+1) = 3
ghost_options(G,2) = 0
Else
ghost_options(G,2) = 1
Endif
`Check left
If sprs_maze(gcolumn-1, grow) = 3
ghost_options(G,3) = 0
Else
ghost_options(G,3) = 1
Endif
endif
`If the direction ghost is currently moving is not an option (wall) then pick a new direction from options
If ghost_options(G,ghost_dir(G,1)) = 0 then ghostAI(G) : `AI Logic function
`Change x and y pos to move ghost. Need to change animation
Select ghost_dir(G,1)
Case 1
inc gxpos : endcase
Case 2
inc gypos : endcase
Case 3
dec gxpos : endcase
Case 4
dec gypos : endcase
Endselect
`Move Ghost
Sprite ghost_spr(G),gxpos,gypos,ghost_img(G,1,1)
Endif
Next G
EndFunction
Function ghostAI(G)
ctr=1
`See how many choices there are and pick a direction at random
For A = 1 to 4
If ghost_options(G,A) = 1
Holdchoices(ctr) = A
inc ctr
Endif
Next A
ghost_dir(G,1) = Holdchoices(Rnd(ctr)+1)
For AA = 1 to 4
Holdchoices(AA) = 0
Next A
Endfunction
Function fisrttimeoutofpen(x,Elapsed)
`Get ghost out of pen
text 700,150, "Elapsed Time: " + str$(Elapsed)
If x = 1 and Elapsed>5 and Elapsed<10
Sprite ghost_spr(x),288,256,ghost_img(x,1,1): `Bring out first ghost
ghost_pen(x,0) = 1
Endif
If x = 2 and Elapsed>10 and Elapsed<15
Sprite ghost_spr(x),288,256,ghost_img(x,1,1): `Bring out next ghost
ghost_pen(x,0) = 1
Endif
If x = 3 and Elapsed>15 and Elapsed<20
Sprite ghost_spr(x),288,256,ghost_img(x,1,1)
ghost_pen(x,0) = 1
Endif
If x = 4 and Elapsed>20 and Elapsed<25
Sprite ghost_spr(x),288,256,ghost_img(x,1,1)
ghost_pen(x,0) = 1
Endif
`If ghost just got out of pen pick an initial direction and move
If ghost_pen(x,0) = 1
Idir = Rnd(1)
Select Idir
Case 0 : ghost_dir(x,1) = 3 : Endcase : `Start left
Case 1 : ghost_dir(x,1) = 1 : Endcase : `Start right
Case default: text 750,150, "Case number is: " + str$(Idir) : Endcase
EndSelect
Endif
EndFunction
rem **************************END OF MOVE PACMAN*********************************
`If a dot has been collided with
Eat_dot:
`Small dot
If Hit_dot => 200
Delete Sprite Hit_dot
Sdot_ctr = Sdot_ctr -1
Play Sound 2 : `Eat dot sound
Player(Player_up,1) = Player(Player_up,1) + 10
Endif
If Bdot_ctr = 100 and Sdot_ctr = 200 then End : `All dots have been eaten
Return
`************************NEW ROUND**************************************
New_Round:
Randomize Timer()
`Place Pacman at spawn point
Sprite spr_pac(1),pac_spnx(1),pac_spny(1),52
`Place READY sprite
Sprite Ready,256,400,101
`Place sprites representing number of lives
If Player(Player_up,2) > 0
For S = 0 to Player(Player_up,2) - 2
Sprite Life(S),64+S*32,704,80
Next S
Endif
`play start round music then hide READY sprite
Play Sound 1
I = 1 : Sync Rate 8
While Sound Playing(1) = 1
`Place Ghost in their pen and animate
Sprite ghost_spr(1),ghost_penx,ghost_peny,ghost_img(1,1,I)
Sprite ghost_spr(2),ghost_penx,ghost_peny,ghost_img(2,1,I)
Sprite ghost_spr(3),ghost_penx-32,ghost_peny,ghost_img(3,1,I)
Sprite ghost_spr(4),ghost_penx+32,ghost_peny,ghost_img(4,1,I)
I = I + 1
If I = 3 then I = 1
Sync
EndWhile
Delete Sprite Ready
Sync Rate 60
Rem Start timer for ghost to leave pen
Rdtime(1)=Timer()
Return
`************************GRAPHICS SETUP****************************************
Setup:
set display mode 1024,768,16
Set Text Font "prstart",1
Set text to bold
Set Text Size 24
`Set Window on
`Set Window Title "Pacman"
sync on : sync rate 60
Hide Mouse
Return
`***********************INITILIZE VARIABLES*********************************
Initilize:
Num_players = 1 : `Allow selection of number of players from startup screen
Player_up = 1 : `Which player is up 1 or 2
FoodCounter = 0
FruitCounter = 1
Level = 1
Player(1,1) = 0 : Player(2,1) = 0 : `Player Scores
Player(1,2) = 3 : Player(2,2) = 3 : `Player Lives
pac_spnx(1) = 288 : `Starting xpos
pac_spny(1) = 512 : `Starting ypos
pac_img(1) = 52 : `Starting Image
ghost_penx = 288 : `Starting xpos in center of pen
ghost_peny = 320 : `Starting ypos in pen
pac_try(1) = 0
Return
rem ***************************LOAD IMAGES***********************************
LoadImages:
`Load Maze and convert to images 1-30
Create Bitmap 1,1280,720
Set Current Bitmap 1
Load Bitmap "Maze.bmp",1
t=1
For Y = 0 to 4
For X = 0 to 5
Get Image t,X*32,Y*32,32+X*32,32+Y*32
Inc t
Next X
Next Y
Cls
remstart just to put image numbers on the tiles
*****TAKE OUT WHEN MAZE IS DONE TESTIN ONLY
Create Bitmap 1,640,480
Set Current Bitmap 1
t=1
Set text Size 14
For Y = 0 to 4
For X = 0 to 5
Paste Image t,X*100,Y*100
Piece$ = Str$(t)
Text X*100+5,Y*100+5,Piece$
Inc t
Next X
Next Y
Save Bitmap "mappieces.bmp",1
Sleep 3000
Cls
Set Current Bitmap 0
remend
`Load Fruit bitmap and convert to images 31 - 42
Load Bitmap "Fruits.bmp",1
t=31
For Y = 0 to 2
For X = 0 to 3
Get Image t,X*32,Y*32,32+X*32,32+Y*32
Inc t
Next X
Next Y
Cls
`Load Ghoast and Pacman and convert to images 42 - 98
Load Bitmap "GhostSprites.bmp",1
t=42
For Y = 0 to 3
For X = 0 to 13
Get Image t,X*32,Y*32,32+X*32,32+Y*32
Inc t
Next X
Next Y
Cls
`Load Dots as images 99-100
Load Image "Sdot.bmp",99
Load Image "Bdot.bmp",100
`Load Ready image
Load Image "Ready.bmp",101
Delete Bitmap 1
Return
`*******************************Load Music and sounds************************
LoadAudio:
Load Sound "Ready.wav",1 : `Plays at start of each life
Load Sound "Eat Dot.wav",2 : `For eating small dot
Return
CreateMaze:
`Create Maze by pasting images for tiles on Bitmap 2 to form maze
Create Bitmap 2,650,720
Set Current Bitmap 2
For Y = 0 to 21
For X = 0 to 18
Read MP
CreateMaze(X,Y) = MP
Paste Image MP,X*32,Y*32
Next X
Next Y
`Get the whole maze as an image and create Sprite 999 which is the whole map
`Paste this sprite on Screen (Bitmap 0)
Get Image 999,0,0,608,704
Sprite 1,0,0,999
Set Sprite 1,0,0
Set Current bitmap 0
Delete Bitmap 2
Paste Sprite 1,0,0
`Maze Data
Data 26,17,17,17,17,17,17,17,17,4,17,17,17,17,17,17,17,17,6
Data 10,30,30,30,30,30,30,30,30,10,30,30,30,30,30,30,30,30,10
Data 10,5,20,2,30,20,7,2,30,10,30,20,7,2,30,20,2,5,10
Data 10,30,14,8,30,14,19,8,30,24,30,14,19,8,30,14,8,30,10
Data 10,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,10
Data 10,30,3,23,30,9,30,3,17,4,17,23,30,9,30,3,23,30,10
Data 10,30,30,30,30,10,30,30,30,10,30,30,30,10,30,30,30,30,10
Data 21,17,17,6,30,15,17,23,12,24,12,3,17,18,30,26,17,17,25
Data 12,12,12,10,30,10,12,12,12,12,12,12,12,10,30,10,12,12,12
Data 17,17,17,25,30,24,12,26,27,28,29,6,12,24,30,21,17,17,17
Data 12,12,12,12,30,12,12,10,12,12,12,10,12,12,30,12,12,12,12
Data 17,17,17,6,30,9,12,21,17,17,17,25,12,9,30,26,17,17,17
Data 12,12,12,10,30,10,12,12,12,12,12,12,12,10,30,10,12,12,12
Data 26,17,17,25,30,24,12,3,17,4,17,23,12,24,30,21,17,17,6
Data 10,30,30,30,30,30,30,30,30,10,30,30,30,30,30,30,30,30,10
Data 10,30,3,6,30,3,17,23,30,24,30,3,17,23,30,26,23,30,10
Data 10,5,30,10,30,30,30,30,30,12,30,30,30,30,30,10,30,5,10
Data 15,23,30,24,30,9,30,3,17,4,17,23,30,9,30,24,30,3,18
Data 10,30,30,30,30,10,30,30,30,10,30,30,30,10,30,30,30,30,10
Data 10,30,3,17,17,22,17,23,30,24,30,3,17,22,17,17,23,30,10
Data 10,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,10
Data 21,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,25
Return
MazeArray:
`Convert CreateMaze() to Maze which will hold the states for each tile
`0 = Pathway
`1 = Small Dots
`2 = Big dots
`3 = Wall
`4 = Ghost Pen Wall
Cls
For Y = 0 to 21
For X = 0 to 18
Tiletype = CreateMaze(X,Y)
Select Tiletype
Case 12 : M = 0 : endcase
Case 30 : M = 1 : endcase
Case 5 : M = 2 : endcase
Case 28 : M = 4 : endcase
Case default : M = 3 : endcase
sprs_maze(X,Y) = M
EndSelect
Next X
Next Y
Return
remstart
`To show what values are in the sprs_maze array
For Y = 0 to 21
Set Cursor 800,Y*10+20
For X = 0 to 18
Print sprs_maze(X,Y);" ";
Next X
Next Y
Repeat
Until EscapeKey() =1
remend
Placedots:
`Place main small dots and 4 big dots
Sdot_ctr = 200
Bdot_ctr = 100
For Y = 0 to 21
For X = 0 to 18
Dottype = sprs_maze(X,Y)
Select Dottype
Case 1 : `Small dots
Sprite Sdot_ctr,X*32,Y*32,99 : Sdot_ctr = Sdot_ctr + 1
remstart - Remove extra dots because it brings fps to low. Need new video card
If sprs_maze(X+1,Y) = 1 then Sprite SDot_ctr,X*32+16,Y*32,99 : SDot_ctr = SDot_ctr + 1
If sprs_maze(X+1,Y) = 2 then Sprite SDot_ctr,X*32+16,Y*32,99 : SDot_ctr = SDot_ctr + 1
If sprs_maze(X,Y+1) = 1 then Sprite SDot_ctr,X*32,Y*32+16,99 : SDot_ctr = SDot_ctr + 1
If sprs_maze(X,Y+1) = 2 then Sprite SDot_ctr,X*32,Y*32+16,99 : SDot_ctr = SDot_ctr + 1
remend
endcase
Case 2 : ` Big dots
Sprite Bdot_ctr,X*32,Y*32,100 : Bdot_ctr = Bdot_ctr + 1
`If sprs_maze(X+1,Y) = 1 then Sprite SDot_ctr,X*32+16,Y*32,99 : SDot_ctr = SDot_ctr + 1
`If sprs_maze(X,Y+1) = 1 then Sprite SDot_ctr,X*32,Y*32+16,99 : SDot_ctr = SDot_ctr + 1
endcase
Case default : endcase
EndSelect
Next X
Next Y
`Set all dots backsave and transparency to 0,0
For x = 100 to Sdot_ctr
Set Sprite x,0,0
Next x
Return
GhostAnimationArray:
`Load ghost_img array with images
Image = 42
For Direction = 1 to 4
For Ghost = 1 to 4
For Frame = 1 to 2
ghost_img(Ghost,Direction,Frame) = Image
Image = Image + 1
Next Frame
Next Ghost
Image = Image + 7
Next Direction
Return