Debian Codegraph @

components/collision.lua

raw symbols SCIP
1 local collision = require 'dokidoki.collision'
2
3 -- umm, looks like brute force n^2 checking is fast enough
4 local bodies = {}
5
6 function add_body(body)
7 bodies[#bodies+1] = body
8 end
9
10 game.actors.new_generic('collision', function ()
11 function collision_check()
12 for i = 1, #bodies do
13 local b1 = bodies[i]
14 for j = i+1, #bodies do
15 local b2 = bodies[j]
16 if b1.type ~= b2.type and b1.player ~= b2.player
17 and collision.collide(b1, b2) then
18 if b1.type == 'bullet' then
19 b1, b2 = b2, b1
20 end
21 local ship = b1.actor
22 local bullet = b2.actor
23 game.log.record_hit(ship, bullet)
24 game.particles.bullet_hit(ship, bullet)
25 ship.ship.damage(bullet.collision.damage)
26 bullet.dead = true
27
28 end
29 end
30 end
31
32 bodies = {}
33 end
34 end)