The cls at the start is a throw back to classic days and win2k refresh, not required for pro.
your switching the backdrop on and off within your code, once at the top and off again prior to your main loop.
your missing sync statements prior to the end of your loops
your adding clear screen elements to your loops, which is effectively another clear and sync of the screen.
dont try to add any gosubs for now, just align it all so its procedural to get it working.
try to be neater with your variables and declare them in one area to make life easier.
Here is a revised snippet to the above I made for you earlier.
Notice Ive changed the start button to enter or return.
And now Ive added a button trapping method to allow to see the result of the bullet sprite appearing without a blue backdrop issue. We are using scancodes and only capturing one keypress, not rapid fire.
The bullet does not offset, rotate or move away from the players sprite but you get the mechanics of what im trying to show you in action.
Your seeing the blue background if the backdrop has not been declared off which is lines 19 and 20 in your revised code.
Anyway hopefully this example will make it clearer for you.
REM -------------------------------------------------------------
REM GAMENAME
REM Author : Neon Knight
REM Sunday 29th April 2007
REM support : indi(mod)
REM VERSION : DBP 6.2
REM -------------------------------------------------------------
REM -------------------------------------------------------------
REM INIT ENVIRONMENT
REM -------------------------------------------------------------
sync on : sync rate 60
randomize timer()
Set display mode 1024, 768, 32 : backdrop on : color backdrop rgb(0,0,0)
set text size 12 : set text font "verdana"
REM -------------------------------------------------------------
REM DECLARE GLOBAL VARIABLES
REM -------------------------------------------------------------
rem the maximum amount of units used in the cleanup routines
Global MaxObjects : MaxObjects = 100
REM -------------------------------------------------------------
REM DECLARE PLAYER VARIABLES
REM -------------------------------------------------------------
Plr_Angle# = 0.0
Plr_MovSpd# = 0.0
Plr_X# = screen width()/2
Plr_Y# = screen height()/2
REM PLAYER KEY SWITCH / TOGGLES
dim Yourname_Switch(1) : Yourname_Switch(1) = 0
dim Yourname_Toggle(1) : Yourname_Toggle(1) = 0
REM -------------------------------------------------------------
REM LOAD 2D MEDIA
REM -------------------------------------------------------------
REM disabled for testing
`load image "Bitmap.bmp", 1
`load image "sprite.jpg", 2
`load image "tank1.bmp", 3
`load image "tank2.bmp", 4
`load image "bullet.bmp", 6
`set image colorkey 0,0,0
REM make some temp shapes and colours
for i = 1 to 6
ink rgb(rnd(255),rnd(25),rnd(255)),1
box 0,0,32,32
ink rgb(0,0,0),1
text 4,4,STR$(i)
get image i,0,0,32,32,1
next i
REM -------------------------------------------------------------
REM LOAD MUSIC
REM -------------------------------------------------------------
REM disabled for testing
`load music "menu.mid", 1 : play music 1
REM -------------------------------------------------------------
REM START MENU FUNCTION
REM -------------------------------------------------------------
cls
StartMenu()
cls
REM -------------------------------------------------------------
REM PRE MAIN LOOP
REM -------------------------------------------------------------
REM disabled for testing
`stop music 1
REM -------------------------------------------------------------
REM LOAD THE PLAYER SPRITE and OFFSET ITS CENTER POINT
REM -------------------------------------------------------------
sprite 2,Plr_X#,Plr_Y#,2
offset sprite 2,16,16
REM -------------------------------------------------------------
REM LOAD THE TANK SPRITES
REM -------------------------------------------------------------
for e = 3 to 4
sprite e,100*e,100*e,e
next e
REM -------------------------------------------------------------
REM MAKE AND HIDE THE PLAYERS SPRITE BULLET
REM -------------------------------------------------------------
sprite 6,-100,-100,6
hide sprite 6
REM -------------------------------------------------------------
REM MAIN LOOP
REM -------------------------------------------------------------
disable escapekey : while escapekey()=0
REM -------------------------------------------------------------
REM PLAYER CONTROL DETECTION
REM -------------------------------------------------------------
if upkey() = 1
Plr_MovSpd# = 1.0
else
if upkey()=0
Plr_MovSpd# = 0.0
endif
endif
if downkey() = 1
Plr_MovSpd# = -0.3
endif
if rightkey() = 1
Plr_Angle# = Plr_Angle# + 1.5
endif
if leftkey() = 1
Plr_Angle# = Plr_Angle# - 1.5
endif
rem ------------------------------------------------------------------------------------------
rem KeyPess switch toggle action SPACEBAR
rem ------------------------------------------------------------------------------------------
If keystate(57)=1 and Yourname_Switch(1)=0
Yourname_Toggle(1)=1-Yourname_Toggle(1)
Yourname_Switch(1)=1
sprite 6,sprite x(2),sprite y(2),6
show sprite 6
Endif
If keystate(57)=0 then Yourname_Switch(1)=0
if Yourname_Toggle(1)=1
endif
REM -------------------------------------------------------------
REM PLAYER CONTROL MOVMENT
REM -------------------------------------------------------------
move sprite 2,Plr_MovSpd#
rotate sprite 2,wrapvalue(Plr_Angle#)
REM TANK AI
REM GAME WORLD UPDATES HERE
REM TEXT TO SCREEN HERE
text 1,1,"Fps:"+STR$(screen fps())
text 1,16,"scancode"+STR$(scancode())
sync : endwhile
REM -------------------------------------------------------------
REM CLEANUP / DELETE MEDIA
REM -------------------------------------------------------------
for i = 1 to MaxObjects
if sprite exist(i) = 1
delete sprite i
endif
next i
for i = 1 to MaxObjects
if image exist(i) = 1
delete image i
endif
next i
for i = 1 to MaxObjects
if music exist(i) = 1
delete music i
endif
next i
end
REM -------------------------------------------------------------
REM FUNCTIONS
REM -------------------------------------------------------------
function StartMenu()
ink rgb(255,255,255),1
disable escapekey : while returnkey()=0
center text screen width()/2,screen height()/2,"press returnkey to start"
sync : endwhile
exit
endfunction
