I have it so it died when it goes outside the screen but I have no clue where to even start when it comes to killing it on a Bump lib wall, I added each bullet to the world when its made, and made its move system work so it has collisions, just dont know how to kill them on walls, any help is very much appreciated
I have it so it died when it goes outside the screen but I have no clue where to even start when it comes to killing it on a Bump lib wall, I added each bullet to the world when its made, and made its move system work so it has collisions, just dont know how to kill them on walls, any help is very much appreciated
function Bullet:new(x, y)
self.r = 1
self.x = x
self.y = y
self.speed = 700
self.w = 10
self.h = 10
self.vx = 0
self.vy = 0
if player.d == 1 then -- left
self.vx = -self.speed
elseif player.d == 2 then -- right
self.vx = self.speed
elseif player.d == 3 then -- up
self.vy = -self.speed
elseif player.d == 4 then -- down
self.vy = self.speed
end
world:add(self, self.x, self.y, self.w, self.h)
end
function Bullet:update(dt)
local targetX, targetY = self.x+self.vx*dt, self.y+self.vy*dt
local newX, newY = world:move(self, targetX, targetY)
if newX == targetX and newY == targetY then -- no collision
self.x, self.y = newX, newY
else -- collision
self.dead = true
end
if self.x > screenx or self.x < 0 or self.y > screeny or self.y < 0 then
self.dead = true
end
end
I have it so it died when it goes outside the screen but I have no clue where to even start when it comes to killing it on a Bump lib wall, I added each bullet to the world when its made, and made its move system work so it has collisions, just dont know how to kill them on walls, any help is very much appreciated
function Bullet:new(x, y)
self.r = 1
self.x = x
self.y = y
self.speed = 700
self.w = 10
self.h = 10
self.vx = 0
self.vy = 0
if player.d == 1 then -- left
self.vx = -self.speed
elseif player.d == 2 then -- right
self.vx = self.speed
elseif player.d == 3 then -- up
self.vy = -self.speed
elseif player.d == 4 then -- down
self.vy = self.speed
end
world:add(self, self.x, self.y, self.w, self.h)
end
function Bullet:update(dt)
local targetX, targetY = self.x+self.vx*dt, self.y+self.vy*dt
local newX, newY = world:move(self, targetX, targetY)
if newX == targetX and newY == targetY then -- no collision
self.x, self.y = newX, newY
else -- collision
self.dead = true
end
if self.x > screenx or self.x < 0 or self.y > screeny or self.y < 0 then
self.dead = true
end
end