(Help) Adding the explosion sprite "explosion huge" to my code...

I need help with adding the “explosion huge” to my code. For when the bullet hits the enemy sprite… Here’s the code I’m working with:

function makeEnemy()

    local enemy = {}
    enemy.type = math.random(#enemysprite)
    enemy.img = enemysprite[enemy.type]
    local size = math.max(enemy.img.width,enemy.img.height)
    enemy.body = physics.body(CIRCLE,size/2)
    enemy.body.position = vec2(math.random(0+size/2,WIDTH-size/2),HEIGHT+size/2)
    enemy.body.bullet = true
    enemy.body.gravityScale = 0
    enemy.body.linearVelocity = vec2(0,-math.random(30,125))
    enemy.body.type1 = "enemy"
    enemies[#enemies+1] = enemy
    lastEnemyTime=ElapsedTime
end

function collide(contactinfo)

    if (contactinfo.bodyA.type1 == "enemy" or
    contactinfo.bodyB.type1 == "enemy") and
    (contactinfo.bodyA.type1 == "bullet" or
    contactinfo.bodyB.type1 == "bullet") then
sound(SOUND_EXPLODE)
        -- sprite("Tyrian Remastered:Explosion Huge")
        contactinfo.bodyA.collided = true
        contactinfo.bodyB.collided = true
        score = score + 1
    end

end

And here’s the code for spawning a bullet…

function makeBullet()

    local bullet = physics.body(CIRCLE,5)
    bullet.position = vec2(shipPosition.x,90)
    bullet.bullet = true
    bullet.gravityScale = 0
    bullet.linearVelocity = vec2(dx,750)
    bullet.type1 = "bullet"
    bullets[#bullets+1] = bullet
    lastBulletTime = ElapsedTime
    sound(SOUND_SHOOT, 28355)
    end
    
    
function touched(t)

    if t.state == BEGAN and not touch then

        touch = t

        if ElapsedTime-lastBulletTime > .25 then

            makeBullet()

        end

        elseif t.state == ENDED then

        touch = nil

    end

end

What do I need to change?

You need the explosion to last several frames, and to gradually disappear

Try this (unchecked code)

--first, read the explosion image into a variable in the setup function
--this saves continually reading it off disk, also, we will need its size later
explosion=readImage("Tyrian Remastered:Explosion Huge")
explosionSize=explosion.width --or any size you want
explosionDuration=2 --seconds

function collide(contactinfo)
    local e
    if (contactinfo.bodyA.type1 == "enemy" and 
        contactinfo.bodyB.type1 == "bullet" then
            e=contactinfo.bodyA
    elseif contactinfo.bodyB.type1 == "enemy") and
             contactinfo.bodyA.type1 == "bullet" then
            e=contactinfo.bodyB
    end
    if e then
        sound(SOUND_EXPLODE)
        e.explosionTimer=ElapsedTime+explosionDuration
        score = score + 1
    end
end

--then in draw
for i,e in pairs(enemies) do
    if e.explosionTimer then --this enemy is being destroyed
        if ElapsedTime<e.explosionTimer then --still being destroyed
            --calculate size of explosion image, phases toward 0
            size=explosionSize*(ElapsedTime-e.explosionTimer)/explosionDuration
            sprite(explosion,body.position.x,body.position.y,size)
        else --explosion is finished, get rid of enemy
            e=nil --destroy enemy item in table
        end
    else --enemy is alive and well
        --code here to sprite enemy normally
    end
end