summaryrefslogtreecommitdiff
path: root/logic/bullets.lua
blob: 70e7dc13828be90abb9b6342bc349e34161fd96c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
local Shot = require "objects.shot"
local bulletData = require "data.bulletData"
local audio = require "utils.audio"

local bullets = {}

function bullets.fire(bulletType, target, firer)
    table.insert(
        G.currentRoom.objects.shots,
        Shot:new(bulletType, target, firer)
    )

    local data = bulletData[bulletType]
    if data and data.afterShot then
        data.afterShot()
    end

    local audioName = data and data.sound or "shootNormal"
    audio.play(audioName)
end

function bullets.hit(name, x, y, enemyType)
    local data = bulletData[name]
    -- x, y represents the position of the bullet when it hit the target
    if data and data.afterHit then
        data.afterHit(x, y, enemyType)
    end
end

return bullets