bullet.lua 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. -- Note: the following table must be global and uniquely named.
  2. Bullet = Bullet or {
  3. data = {}
  4. }
  5. local data = Bullet.data
  6. -- Called after units are spawned into a world.
  7. function Bullet.spawned(world, units)
  8. if data[world] == nil then
  9. data[world] = {}
  10. end
  11. local world_data = data[world]
  12. for _, unit in pairs(units) do
  13. -- Store instance-specific data.
  14. if world_data[unit] == nil then
  15. world_data[unit] = { }
  16. end
  17. end
  18. end
  19. -- Called once per frame.
  20. function Bullet.update(world, dt)
  21. local world_data = data[world]
  22. for unit, unit_data in pairs(world_data) do
  23. -- Update unit.
  24. end
  25. end
  26. -- Called before units are unspawned from a world.
  27. function Bullet.unspawned(world, units)
  28. local world_data = data[world]
  29. -- Cleanup.
  30. for _, unit in pairs(units) do
  31. if world_data[unit] then
  32. world_data[unit] = nil
  33. end
  34. end
  35. end
  36. function Bullet.collision_begin(world, unit, other_unit, actor, other_actor, position, normal, distance)
  37. World.play_sound(world, "sfx/bounce", false, 1.0, 200, position)
  38. end
  39. return Bullet