Files
paku/data/modules/ia/bullet.lua
T
Raimon @ quifisraimon d2ebbccbf6 - [NEW] El mono
- [NEW] Noves animacions de detallets
- [NEW] Més particles i eye candy
- [FIX] Si es ficava un item/enemic en la fila de baix del tot no es guardaba
- [FIX] Quan se disaparaba cap a la dreta amb el final de la pantalla o una pared en la esquena, la bala no eixia
- [WIP] Treballant en el marcador
2026-10-06 15:56:37 +02:00

50 lines
2.1 KiB
Lua

function ia.update_bullet(spr)
local tx, ty, ty2 = sprites.get_tile(spr.pos.x+2), sprites.get_tile(spr.pos.y+1), sprites.get_tile(spr.pos.y+2)
if rooms.is_outside(tx,ty) then sprites.remove(spr) return end
local x1,y1,w1,h1 = util.aabb(spr)
for i,v in ipairs(sprites.list) do
if v.enemy and v.state ~= templates.DEAD then
local x2,y2,w2,h2 = util.aabb(v)
if util.check_aabb_collision(x1,y1,w1,h1, x2,y2,w2,h2) then
if v.state == templates.ALIVE then
if v.bulletproof then
bullet_ricochet(spr)
else
v.state = templates.DYING
end
end
local dir = 0.1
if spr.flipped then dir = -dir end
sprites.dust_ex(spr, {pos={x=spr.pos.x, y=spr.pos.y}, dir={x=-0.1,y=-1.2}, flipped=not spr.flipped})
sprites.remove(spr)
return
end
end
end
if map.tile(tx,ty) < 16 or map.tile(tx,ty2) < 16 then
if spr.flipped then
spr.pos.x = spr.pos.x - 8
else
spr.pos.x = spr.pos.x + 8
end
else
bullet_ricochet(spr)
--sprites.remove(spr)
end
end
function bullet_ricochet(spr)
local dir = 0.1
if spr.flipped then dir = -dir end
sprites.dust_ex(spr, {pos={x=spr.pos.x, y=spr.pos.y}, dir={x=-0.1,y=-1.2}, flipped=not spr.flipped})
sprites.remove(spr)
table.insert(sprites.list, templates.create("bullet_particle", {pos={x=spr.pos.x, y=spr.pos.y}, dir={x= 1,y= math.random(3,5)}, flipped=spr.flipped}))
table.insert(sprites.list, templates.create("bullet_particle", {pos={x=spr.pos.x, y=spr.pos.y}, dir={x=-1,y= math.random(3,5)}, flipped=spr.flipped}))
table.insert(sprites.list, templates.create("bullet_particle", {pos={x=spr.pos.x, y=spr.pos.y}, dir={x=-1,y=-math.random(3,5)}, flipped=spr.flipped}))
table.insert(sprites.list, templates.create("bullet_particle", {pos={x=spr.pos.x, y=spr.pos.y}, dir={x= 1,y=-math.random(3,5)}, flipped=spr.flipped}))
end