Here's the fixed code. Basically I added the
color backdrop rgb(0,0,0) and got rid of a few unecessary syncs. I also moved the
cls to the beginning of the loop.
Rem Project: random2
Rem Created: 05/12/2008 8:43:02 PM
Rem ***** Main Source File *****
sync on
sync rate 60
disable escapekey
color backdrop rgb(0,0,0)
rem variable
cs1 = screen width()/2
cs2 = screen height()/2
sped = 1
rem images
load image "tank2.jpg",1
load image "turret.jpg",2
load image "bullet.png",3
rem sprites
sprite 1,cs1,cs2,1
scale sprite 1,10
sprite 2,cs1+5,cs2-5,2
scale sprite 2,10
sprite 3,cs1+5,cs2-4,3
scale sprite 3,10
rem loop
do
cls
if spacekey() = 1:input "Choose your speed. ":endif
if sped > 20 Then sped = 20
if sped < 1 Then sped = 1
if shiftkey() = 1:gosub firebullet:endif
rem dumb controls
if upkey() = 1:dec cs2,sped:endif
if downkey() = 1:inc cs2,sped:endif
if leftkey() = 1:dec cs1,sped:endif
if rightkey() = 1:inc cs1,sped:endif
rem limits
if cs1 > 630 Then cs1 = 0
if cs1 < 0 Then cs1 = 630
if cs2 > 470 Then cs2 = 0
if cs2 < 0 Then cs2 = 470
if cs1 > 1:gosub printcs1cs2:endif
rem good controls
if inkey$() = "a":rotate sprite 1,a:rotate sprite 2,a:gosub angle:endif
if inkey$() = "d":rotate sprite 1,a:rotate sprite 2,a:gosub angle2:endif
if inkey$() = "w":move sprite 1,10:endif
if inkey$() = "s":move sprite 1,5:endif
rem set2
if inkey$() = "A":rotate sprite 1,a:gosub angle:endif
if inkey$() = "D":rotate sprite 1,a:gosub angle2:endif
if inkey$() = "W":move sprite 1,sped:endif
if inkey$() = "S":move sprite 1,5:endif
rem exit
if keystate(1) = 1:goto deleteall:endif
rem refresh
sprite 1,cs1,cs2,1
sprite 2,cs1+5,cs2-5,2
sync
loop
angle:
inc a,1
return
angle2:
dec a,1
return
printcs1cs2:
set text size 20
print cs1
print cs2
return
deleteall:
cls
delete image 1
delete image 2
delete image 3
end
firebullet:
cs22 = cs2
repeat
if keystate(1) = 1:goto deleteall:endif
dec cs22,1
sprite 3,cs1,cs22,3
scale sprite 3,20
sync
until cs22 = 0
delete sprite 3
return
There are still 2 other problems that need to be addressed. One is the
repeat... until loop in your firing code. By coding it inside it's own loop you are stalling the main loop from running. Meaning that when you fire a bullet, no other action/processing takes place until the bullet reaches it's limit. You have to take that loop out of the mix, and just keep track of variable values to position the bullet during each pass through the main loop. Then reset the position. I'll code something up for you
Second issue has to do with rotation of the sprite. I haven't looked at the code for that part yet, but it causes the program to crash.
~Zenassem