bullet = {}
function bulletspawn(x,y,direction)
table.insert(bullet,{x = x,y = y, w = 4, h = 2,speed = 120}) -- REALLY BRO, NO DIRECTION IN THERE? DO YOU EVEN LIFT BRUH?
end
function bulletshoot(key)
if key == "d" then
bulletspawn(player.x + (player.w/2),player.y + (player.h/2),"right")
elseif key == "a" then
bulletspawn(player.x + (player.w/2),player.y + (player.h/2),"left")
end
end
function bulletupdate(dt)
for i,v in ipairs(bullet) do
if v.direction == "right" then
v.x = v.x + v.speed * dt
end
if v.direction == "left" then
v.x = v.x - v.speed * dt
end
end
end
function bulletdraw()
for i,v in ipairs(bullet) do
g.setColor(255,255,255,255)
g.rectangle("fill",v.x,v.y ,v.w,v.h)
end
end
function bulletremove()
if v.x < 0 or
v.x < g.getWidth() == 20 then
table.remove(bullet)
end
end
Hope you all can help!
-Wolf
Last edited by WolfNinja2 on Mon Nov 12, 2012 11:03 am, edited 1 time in total.
When you insert into the table bullet you have direction in the function arguments, but you don't actually put that into the table you're inserting. It should be this: