Post by fwiss on Aug 24, 2010 11:01:52 GMT -5
I'm having a problem injecting sprites into the Space Invaders Program in one of the Tutorials. Here's the code:
The problem is that sprite 2 "shotsprite" is going over or in place of sprite 0 "charsprite" when it should be invisible and at 700, 500. I think it's order of operations, but I couldn't find a problem.
dim score, lives, turretx, alienx, alieny
dim bulletx, bullety, bulletOnScreen, i
dim charimage, charsprite, aliensprite, shotsprite
lives = 3
turretx = 19
alienx = 0
alieny = 12
bulletOnScreen = false
charimage = LoadTexture("Graphics/0.bmp")
charsprite = NewSprite(charimage)
sprsetpos(320,240)
sprsetsize(1,8)
SprSetZOrder(1)
aliensprite = NewSprite(LoadImageStrip("Graphics/1b.bmp", 32))
sprsetpos(alienx, alieny)
sprsetsize(12, 8)
sprsetzorder(1)
sprsetanimspeed(1)
shotsprite = NewSprite(LoadTexture("Graphics/2.bmp"))
sprsetvisible(false)
sprsetpos(700,700)
sprsetsize(4,6)
TextMode (TEXT_BUFFERED)
while true
bindsprite(aliensprite)
sprsetpos(alienx, alieny)
if ScanKeyDown (VK_LEFT) and turretx > 0 then
turretx = turretx - 5
endif
if ScanKeyDown (VK_RIGHT) and turretx < 640 then
turretx = turretx + 5
endif
alienx = alienx + 7
if alienx > 640 then
alienx = 0
alieny = rnd () % 500 + 1
endif
if bulletOnScreen then
bullety = bullety - 1
if bullety < 1 then
bulletOnScreen = false
bindsprite(shotsprite)
sprsetpos(700, 500)
sprsetvisible(false)
endif
else
if ScanKeyDown (VK_SPACE) then
bulletOnScreen = true
bullety = 240 + 1
bulletx = turretx
bindsprite(shotsprite)
sprsetvisible(true)
endif
endif
cls
if bulletOnScreen and bullety = alieny and bulletx >= alienx and bulletx <= alienx + 2 then
color (255, 255, 100)
for i = 1 to 10
locate alienx, alieny: print "///"
DrawText ()
Sleep (50)
next
bulletOnScreen = false
alienx = 0
alieny = rnd () % 500 + 1
score = score + 100
Sleep (1000)
endif
bindsprite(charsprite)
sprsetpos(turretx, 443)
AnimateSprites()
DrawText ()
Sleep (75)
wend
dim bulletx, bullety, bulletOnScreen, i
dim charimage, charsprite, aliensprite, shotsprite
lives = 3
turretx = 19
alienx = 0
alieny = 12
bulletOnScreen = false
charimage = LoadTexture("Graphics/0.bmp")
charsprite = NewSprite(charimage)
sprsetpos(320,240)
sprsetsize(1,8)
SprSetZOrder(1)
aliensprite = NewSprite(LoadImageStrip("Graphics/1b.bmp", 32))
sprsetpos(alienx, alieny)
sprsetsize(12, 8)
sprsetzorder(1)
sprsetanimspeed(1)
shotsprite = NewSprite(LoadTexture("Graphics/2.bmp"))
sprsetvisible(false)
sprsetpos(700,700)
sprsetsize(4,6)
TextMode (TEXT_BUFFERED)
while true
bindsprite(aliensprite)
sprsetpos(alienx, alieny)
if ScanKeyDown (VK_LEFT) and turretx > 0 then
turretx = turretx - 5
endif
if ScanKeyDown (VK_RIGHT) and turretx < 640 then
turretx = turretx + 5
endif
alienx = alienx + 7
if alienx > 640 then
alienx = 0
alieny = rnd () % 500 + 1
endif
if bulletOnScreen then
bullety = bullety - 1
if bullety < 1 then
bulletOnScreen = false
bindsprite(shotsprite)
sprsetpos(700, 500)
sprsetvisible(false)
endif
else
if ScanKeyDown (VK_SPACE) then
bulletOnScreen = true
bullety = 240 + 1
bulletx = turretx
bindsprite(shotsprite)
sprsetvisible(true)
endif
endif
cls
if bulletOnScreen and bullety = alieny and bulletx >= alienx and bulletx <= alienx + 2 then
color (255, 255, 100)
for i = 1 to 10
locate alienx, alieny: print "///"
DrawText ()
Sleep (50)
next
bulletOnScreen = false
alienx = 0
alieny = rnd () % 500 + 1
score = score + 100
Sleep (1000)
endif
bindsprite(charsprite)
sprsetpos(turretx, 443)
AnimateSprites()
DrawText ()
Sleep (75)
wend
The problem is that sprite 2 "shotsprite" is going over or in place of sprite 0 "charsprite" when it should be invisible and at 700, 500. I think it's order of operations, but I couldn't find a problem.