Yeah, I've been sitting around the past bit here working with DBP. It is amazing and I got something working, somewhat.
It seems to be operating, I had it at one point displaying to me all of the images in the map_tiles.bmp file that I have. What is happening, is when it is drawing the map, everything seems to go down the drain. My FPS is killed and it seems like it is frozen. When you comment out the "draw_map()" from the main loop, the program works as it should.
Any ideas as to why it all freezes on me?
I have been using the Pac-Man tutorial found
here. Graphics are thanks to David Gervais in the 2D Graphics Buffet post. The player character is something that has been sitting on my HDD.
Rem Project: CodeTester
Rem Created: Monday, December 13, 2010
Rem Creator: Sharlenwar a.k.a. Martin Holubec
Rem ***** Main Source File *****
Rem Purpose: This program is simply for any code pieces that I need tested. This is a purely learning project.
`Setup Display Settings
sync on
sync rate 60
`Setup any Types
`The terrain type will handle any information on that square.
type terrain
id as dword
dispimg as dword
impass as byte
endtype
`For our coordinates in the game world.
type coordinate
x as integer
y as integer
endtype
`Setup any global variables.
`Sreen Size
global screenx as word
global screeny as word
`Mid point value
global midx as word
global midy as word
`Mouse values
global msex as word
global msey as word
global msez as word
`Click Position Values
global clkx as word
global clky as word
`Player Information
global spr_pc as word
global img_pc as word
global pc_x as integer
global lpc_x as integer `Last players x position
global pc_y as integer
global lpc_y as integer `Last players y positon
global mpc_key as boolean `Is a player moving key pressed?
`Map Information
global map_tile_size as word
global map_columns as word
global map_rows as word
global map_pc_spawn as coordinate
`Box Values
global drawbox as boolean
`Initialize any media.
init_media()
`Main Game Loop
do
cls
capture_data()
keycontrol()
debug_info()
draw_map()
collision_pc()
draw_pc()
draw_box()
sync
loop
`Handles any data loading for the game.
function init_media()
`Map Setup.
map_columns = 20 `This makes the map 21 units
map_rows = 20
map_tile_size = 32
`Starting map coordinates.
map_pc_spawn.x = 10
map_pc_spawn.y = 10
`Set the text for the outputs
set text font "Courier New"
set text size 15
`Setup the player sprite
img_pc = free_img()
spr_pc = free_spr()
create animated sprite spr_pc, "male.bmp", 12, 1, img_pc
`setup the player's position to the spawn point.
pc_x = map_pc_spawn.x
pc_y = map_pc_spawn.y
load_map()
endfunction
`Setup the map
function load_map()
dim imgs_map(99) as word `Setup the map images array, for easy retrieval
dim sprs_map(map_columns, map_rows) as terrain `Here is the map array.
local img_map as word
local xpix as word
local ypix as word
local img_ptr as dword
`Here we are loading up the map images, and inserting them into the imgs_map array for drawing of the map.
img_map = free_img()
load image "map_tiles.bmp", img_map, 1
paste image img_map, 0, 0
`
for ypix = 0 to 319 step 32
for xpix = 0 to 319 step 32
imgs_map(img_ptr) = get_img(xpix, ypix, xpix + map_tile_size, ypix + map_tile_size, 1)
`move the image pointer
inc img_ptr
next xpix
next ypix
delete image img_map `Clean up the image file once we are done with it.
endfunction
`Draws the Map. -- this code is messed I think
function draw_map()
local column as dword
local row as dword
local img_ptr as dword
`Map drawing code here
for row = 0 to map_rows
for column = 0 to map_columns
`Select the correct image
img_ptr = sprs_map(column, row).dispimg
`make a sprite for this image
sprs_map(column, row).id = make_spr(column * map_tile_size, row * map_tile_size, imgs_map(img_ptr))
next column
next row
endfunction
`Handles any data retrieval.
function capture_data()
`Capture data and insert into variables
screenx = screen width()
screeny = screen height()
midx = screenx / 2
midy = screeny / 2
msex = mousex()
msey = mousey()
msez = mousez() `Scroll Wheel Value
endfunction
`Handles the input collection.
function keycontrol()
`Basic Input Collection
if keystate(1) = 1 `ESC key
text midx, midy, "ESC Key"
endif
if keystate(17) = 1 `W key
text midx, midy, "W Key"
endif
if keystate(30) = 1 `A key
text midx, midy, "A Key"
endif
if keystate(31) = 1 `S key
text midx, midy, "S Key"
endif
if keystate(32) = 1 `D key
text midx, midy, "D Key"
endif
if upkey() = 1
lpc_y = pc_y
dec pc_y
endif
if downkey() = 1
lpc_y = pc_y
inc pc_y
endif
if leftkey() = 1
lpc_x = pc_x
dec pc_x
endif
if rightkey() = 1
lpc_x = pc_x
inc pc_x
endif
`Mouse Input
select mouseclick()
case 0
`Here we are turning off the box drawing.
drawbox = 0
endcase
case 1
`Capture any relevant data if the user left clicks.
text midx, midy, "Left Click"
endcase
case 2
`If the user right clicks, then set the flag to draw the box. Must keep button held down.
text midx, midy, "Right Click -- Capturing Data"
clkx = msex
clky = msey
drawbox = 1
endcase
case 3
`User clicks both left and right mouse button together
text midx, midy, "Both Buttons Clicked"
endcase
case 4
text midx, midy, "Scroll Wheel Click"
endcase
endselect
endfunction
`Checks to see if there are collision checks for the player.
` This is to simply smooth out the constraint on the map.
function collision_pc()
`This makes sure that the player coordinates are within the map area.
if pc_x < 0 then pc_x = 0
if pc_x > map_columns then pc_x = map_columns
if pc_y < 0 then pc_y = 0
if pc_y > map_rows then pc_y = map_rows
if sprs_map(pc_x, pc_y).impass = 1
pc_x = lpc_x
pc_y = lpc_y
endif
endfunction
`Draws the player
function draw_pc()
sprite spr_pc, pc_x * map_tile_size, pc_y * map_tile_size, img_pc
endfunction
`This draws a box near the mouse, useful for something.
function draw_box()
`If we have the right button clicked, then draw the box
if drawbox = 1
local left as word
local top as word
local right as word
local bottom as word
`Sets up the box boundary.
left = clkx + 10
top = clky + 20
right = left + 200
bottom = top + 35
`Draw the box with information inside.
ink rgb(125,125,125), rgb(0,0,0)
box left, top, right, bottom
ink rgb(185,185,185), rgb(0,0,0)
line left, top, left, bottom
line left, top, right, top
line right, top, right, bottom
line right, bottom, left, bottom
ink rgb(205,180,25), rgb(125,125,125)
set text size 12
text left + 5, top + 5, "This is a mouse box!"
`Change back to any defaults.
ink rgb(255,255,255), rgb(0,0,0)
set text size 15
endif
endfunction
`Handles our debug info that spits to the screen.
function debug_info()
text 0, 600, "FPS: " + str$(screen fps())
text 0, 625, "Mouse X: " + str$(msex)
text 0, 640, "Mouse Y: " + str$(msey)
text 0, 655, "Mouse Z: " + str$(msez)
text 0, 670, "Mouse Click: " + str$(mouseclick())
text 0, 690, "Click X: " + str$(clkx)
text 0, 705, "Click Y: " + str$(clky)
text 0, 725, "Map Dimensions - X: " + str$(map_columns + 1) + " Y: " + str$(map_rows + 1)
text 0, 740, "Player X: " + str$(pc_x) + " Y: " + str$(pc_y)
endfunction