Hi there!
Am new to DB Pro and am just trying to learn it the old fashioned way by writing a game and learning by my mistakes!
I have written some code to display a sprite on the screen and move it around.
This originally worked but I have since tried to "upgrade" my code to make it more structured (types, functions, etc).
Since I changed to this method though, I do not see my sprite or any text on the screen!
The check keys code works as I can hear a sound when i click the mouse.
I have attached my code below... any ideas out there!??!?
Many thanks in advance
Mike
'Initialize the program
HIDE MOUSE
SYNC ON
' User types
type PlayerType
score as integer
alive as integer
lives as integer
x as integer
y as integer
firing as integer
spritenum as integer
endtype
' Global
global SCREENHEIGHT = 768
global SCREENWIDTH = 1024
global SHIPSPRITE = 1
global SHIPIMAGE = 1
global NUM_PLAYERS = 1
global player_num = 0
global player as PlayerType
global CheckFireButton as integer = 0
' Initialise
SetDisplay()
LoadSounds()
LoadImages()
' Create new player
CreateNewPlayer(player_num)
' MK - need to do this so that the sprite is here before I start the main loop
sprite player.spritenum, 200, 200, SHIPIMAGE
'This is the game loop
REPEAT
'for player_num = 0 to NUM_PLAYERS
CheckFireButton = CheckKeys(player_num)
if CheckFireButton = 1
play sound 1
endif
'draw the ship
SPRITE player.spritenum, player.x, player.y, SHIPIMAGE
'next i
text 900, 0, str$(player.x)
'text 900, 20, str$(player.y)
'text 900, 40, str$(CheckFireButton)
'update the screen
SYNC
'Check for mouse click to exit
UNTIL ESCAPEKEY()=1
SHOW MOUSE
END
function CheckKeys(playerNum)
sprite_width as integer = SPRITE WIDTH(player.spritenum)
sprite_height as integer = SPRITE HEIGHT(player.spritenum)
FireButton as integer = 0
IF LEFTKEY() = 1
player.x = player.x - 1
if player.x < (0 + sprite_width) then player.x = 0 + SCREENWIDTH
endif
if RIGHTKEY() = 1
player.x = player.x +1
if player.x > (SCREENWIDTH - sprite_width) then player.x = SCREENWIDTH - sprite_width
endif
IF UPKEY() = 1
player.y = player.y - 1
if player.y < (0 + sprite_height) then player.y = 0 + sprite_height
endif
if DOWNKEY() = 1
player.y = player.y + 1
if player.y > (SCREENHEIGHT - sprite_height) then player.y = SCREENHEIGHT - sprite_height
endif
if MOUSECLICK() = 1
FireButton = 1
endif
endfunction FireButton
function CreateNewPlayer(playerNum as integer)
player.score = 0
player.alive = 1
player.lives = 3
player.x = 50
player.y = 50
player.firing = 0
player.spritenum = SHIPSPRITE
endfunction
function CreateMissile(x as integer, y as integer, max as integer)
for i = 0 to max
if missiles(i).alive = 0
missiles(i).alive = 1
missiles(i).x = x
missiles(i).y = y
missiles(i).spritenum = 3
endif
next
endfunction
function SetDisplay()
set display mode SCREENWIDTH, SCREENHEIGHT,16
set image colorkey 255, 255, 255
RgbForeValue=RGB(rnd(255),rnd(255),rnd(255))
RgbBackValue=RGB(rnd(0),rnd(0),rnd(0))
ink RgbForeValue, RgbBackValue
endfunction
function LoadImages()
'Load the sprite
load image "c:\src\images\test\ship1.bmp", SHIPIMAGE
endfunction
function LoadSounds()
LOAD SOUND "C:\src\sounds\shoot.wav", 1
endfunction