My problems are this:
1. I can only fire one bullet at a time, i'd like to be able to fire multiple bullets.
2. When i think i have the logic right for collision detection, it thinks that the bullet hits no matter where it is on screen.
3. Because it thinks it is constantly hitting, i suffer a framerate hit until the bullet reaches the right side of the screen.
I'd really like to get into coding games, as figuring this out just by trial and error, and following the tutorials has been the most fun i've had in a long time. Somebody please tell me where my logic errors are and how to correct them. Thanks!
-J. Hemperly
Here's My Source
System.usbDiskModeActivate()
background = Image.load("/images/background.png")
smiley = Image.load("/images/smiley.png")
bullet = Image.load("/images/bullet.png")
fly = Image.load("/images/fly.png")
X = 0
Y = 0
BX = 0
BY = 0
BH = 0
function checkhit()
for BY=100,140 do
BH = BH+1
end
end
function shoot()
for BX=X+40,480 do
screen:clear()
screen:blit(0, 0, background, 0, 0, background:width(), background:height(), false)
pad = Controls.read()
if pad:start() then
break
end
if pad:right() then
X=X+2
end
if pad:left() then
X=X-2
end
if pad:up() then
Y=Y-2
end
if pad:down() then
Y=Y+2
end
if BH=1 then
screen:print (0, 0, "Hit")
screen.waitVblankStart()
bullethit=0
end
screen:blit(X, Y, smiley)
screen:blit(BX, BY, bullet)
screen:blit(400, 100, fly)
screen.waitVblankStart()
screen.flip()
BX = BX+7
end
end
while true do
if X>440 then X=440
else X = X
end
if X<0 then X=0
else X = X
end
if Y>232 then Y=232
else Y = Y
end
if Y<0 then Y=0
else Y = Y
end
screen:blit(0, 0, background, 0, 0, background:width(), background:height(), false)
screen:blit(X, Y, smiley)
screen:blit(400, 100, fly)
screen.waitVblankStart()
screen.flip()
pad = Controls.read()
if pad:start() then
break
end
if pad:right() then
X=X+2
end
if pad:left() then
X=X-2
end
if pad:up() then
Y=Y-2
end
if pad:down() then
Y=Y+2
end
if pad:cross() then do
BX=X+40
BY=Y+18
shoot()
checkhit()
end
end
end