Just got DBC recently and this is my first post - "Hello all!". I'm am trying to do pacman based on the DBP tutorial on this forum. Except for using the images and the movement routine, I am trying to do the program myself but I am running into a problem with the framerate. I am at the point where the maze is created using sprites and the pacman is placed. My pacman is moving in sloooow motion.
The FPS is 4! even without trying to move the pacman sprite.
My code is below. Any thought on why the ungodly slow FPS?
Thanks!
[rem Pacman game
rem Started 12/17/08
Dim CreateMaze(18,21)
Dim sprs_maze(18,21)
Global pac_try
Global pac_dir
Global spr_pac
Global pac_spnx
Global pac_spny
`Sprite number for pacman
spr_pac = 419
Gosub Setup
Gosub Initilize
Gosub LoadImages
Gosub CreateMaze
Gosub MazeArray
New_Round
`Main Loop
Repeat
`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 750, 250, "Frames Per Second: " + str$(screen fps())
get_pac_move
move_pac
Sync
Cls
Until EscapeKey() = 1
`PASTED CODE
`get player input
Function get_pac_move()
select pac_try
case 0
if upkey() then pac_try = 1
if rightkey() then pac_try = 2
if downkey() then pac_try = 3
if leftkey() then pac_try = 4
endcase
case 1
if upkey() = 0 then pac_try = 0
endcase
case 2
if rightkey() = 0 then pac_try = 0
endcase
case 3
if downkey() = 0 then pac_try = 0
endcase
case 4
if leftkey() = 0 then pac_try = 0
endcase
endselect
Endfunction
`move pac-man
Function move_pac()
`local xpos as word
`local ypos as word
`local row as dword
`local column as dword
`cache Pac-Man position
xpos = sprite x(spr_pac)
ypos = sprite y(spr_pac)
`find current tile Pac-Man is in
column = xpos/32
row = ypos/32
`Set Cursor 800,50 : Print "Column = ";column
`Set Cursor 800,80 : Print "Row = ";row
`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
case 1
if sprs_maze(column, row-1) = 0 then pac_dir = 1
endcase
case 2
if sprs_maze(column+1, row) = 0 then pac_dir = 2
endcase
case 3
if sprs_maze(column, row+1) = 0 then pac_dir = 3
endcase
case 4
if sprs_maze(column-1, row) = 0 then pac_dir = 4
endcase
endselect
`stop Pac-Man from moving if he's about to walk into a wall
select pac_dir
case 1
if sprs_maze(column, row-1) => 1 then pac_dir = 0
endcase
case 2
if sprs_maze(column+1, row) => 1 then pac_dir = 0
endcase
case 3
if sprs_maze(column, row+1) => 1 then pac_dir = 0
endcase
case 4
if sprs_maze(column-1, row) => 1 then pac_dir = 0
endcase
endselect
endif
select pac_dir
case 1
dec ypos
endcase
case 2
inc xpos
endcase
case 3
inc ypos
endcase
case 4
dec xpos
endcase
endselect
sprite spr_pac, xpos, ypos, 52
Endfunction
Function New_Round
`Place dots on map
`Place Pacman at spawn point
Sprite spr_pac,pac_spnx,pac_spny,52
Show Sprite spr_pac
Endfunction
`END OF PASTED CODE
Setup:
set display mode 1024,768,16
`Set Window on
`Set Window Title "Pacman"
sync on : sync rate 0
`Hide Mouse
Initilize:
FoodCounter = 0
FruitCounter = 1
Level = 1
Player1Score = 0
Player2Score = 0
pac_spnx = 288
pac_spny = 512
GhostHomex = 50
GhostHomey = 50
pac_try = 0
LoadImages:
Remstart
*****TAKE OUT WHEN MAZE IS DONE TESTIN ONLY
`Load full map and draw line to segment tiles
Load Bitmap "Fullmaze.bmp"
Get Image 200,0,0,605,702
Create Bitmap 1,605,702
Paste Image 200,0,0
BW = Bitmap Width()
BH = Bitmap Height()
Ink rgb(255,255,255),rgb(0,0,0)
SegmentsX = BW/19
SegmentsY = BH/22
For X = 0 to 19
Line X*32,0,X*32,BH
Next X
For Y = 0 to 22
Line 0,Y*32,702,Y*32
Next Y
Save Bitmap "Mazedivided.bmp",1
Sleep 500
Repeat
Sync
Until EscapeKey() =1
remend
`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
Delete Bitmap 1
Return
CreateMaze:
t=1
`***Must make dot image on 32x32 tiles so dots will be centered
`Create Maze using sprites 1 - 418
Set Current Bitmap 0
For Y = 0 to 21
For X = 0 to 18
Read MP
CreateMaze(X,Y) = MP
Sprite t,X*32,Y*32,MP
Set Sprite t,1,1
Inc t
Next X
Next Y
Sync
`Maze Data
Data 26,17,17,17,17,17,17,17,17,4,17,17,17,17,17,17,17,17,6
Data 10,99,99,99,99,99,99,99,99,10,99,99,99,99,99,99,99,99,10
Data 10,100,20,2,99,20,7,2,99,10,99,20,7,2,99,20,2,100,10
Data 10,99,14,8,99,14,19,8,99,24,99,14,19,8,99,14,8,99,10
Data 10,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,10
Data 10,99,3,23,99,9,99,3,17,4,17,23,99,9,99,3,23,99,10
Data 10,99,99,99,99,10,99,99,99,10,99,99,99,10,99,99,99,99,10
Data 21,17,17,6,99,15,17,23,12,24,12,3,17,18,99,26,17,17,25
Data 12,12,12,10,99,10,12,12,12,12,12,12,12,10,99,10,12,12,12
Data 17,17,17,25,99,24,12,26,27,28,29,6,12,24,99,21,17,17,17
Data 12,12,12,12,99,12,12,10,12,12,12,10,12,12,99,12,12,12,12
Data 17,17,17,6,99,9,12,21,17,17,17,25,12,9,99,26,17,17,17
Data 12,12,12,10,99,10,12,12,12,12,12,12,12,10,99,10,12,12,12
Data 26,17,17,25,99,24,12,3,17,4,17,23,12,24,99,21,17,17,6
Data 10,99,99,99,99,99,99,99,99,10,99,99,99,99,99,99,99,99,10
Data 10,99,3,6,99,3,17,23,99,24,99,3,17,23,99,26,23,99,10
Data 10,100,99,10,99,99,99,99,99,99,99,99,99,99,99,10,99,100,10
Data 15,23,99,24,99,9,99,3,17,4,17,23,99,9,99,24,99,3,18
Data 10,99,99,99,99,10,99,99,99,10,99,99,99,10,99,99,99,99,10
Data 10,99,3,17,17,22,17,23,99,24,99,3,17,22,17,17,23,99,10
Data 10,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,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 = Wall
`2 = Ghost Pen Wall
Cls
For Y = 0 to 21
For X = 0 to 18
Tiletype = CreateMaze(X,Y)
If Tiletype = 28
M = 2
Else
M = 1
Endif
If Tiletype = 12 or Tiletype = 99 then M = 0
sprs_maze(X,Y) = M
Next X
Next Y
remstart
For Y = 1 to 22
Set Cursor 800,Y*10+10
For X = 1 to 19
Print sprs_maze(X,Y);" ";
Next X
Next Y
Repeat
Until EscapeKey() =1
remend
Return