Bullet death when hitting a bump wall
Posted: Wed Nov 30, 2022 2:20 pm
Im trying to make it so that when a bullet class hits a wall it "dies"
dying =
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
Bullet.lua
dying =
Code: Select all
self.alive = false
Bullet.lua
Code: Select all
Bullet = Object:extend()
function Bullet:new(x, y)
self.r = 1
self.x = x
self.y = y
self.speed = 700
self.w = 10
self.h = 10
self.path = 0
self.vx = 0
self.vy = 0
if player.d == 4 then
self.path = 4
elseif player.d == 1 then
self.path = 1
elseif player.d == 2 then
self.path = 2
elseif player.d == 3 then
self.path = 3
end
world:add(self, self.x, self.y, self.w, self.h)
end
function Bullet:update(dt)
self.vx = 0
self.vy = 0
if self.x > screenx or self.x < 0 or self.y > screeny or self.y < 0 then
self.dead = true
end
if self.path == 4 then
self.vy = self.vy + self.speed * dt
elseif self.path == 1 then
self.vx = self.vx - self.speed * dt
elseif self.path == 2 then
self.vx = self.vx + self.speed * dt
elseif self.path == 3 then
self.vy = self.vy - self.speed * dt
end
self.x, self.y = world:move(self, self.x+self.vx, self.y+self.vy)
end
function Bullet:draw()
--love.graphics.circle("fill", self.x, self.y,self.r)
love.graphics.rectangle("line",self.x,self.y,self.w,self.h)
end