-
Notifications
You must be signed in to change notification settings - Fork 1
/
tntball_logic.lua
49 lines (38 loc) · 1.01 KB
/
tntball_logic.lua
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
--[[
A variant on the ball which, instead of rebounding on zero velocity,
explodes if it accelerated or decelerated too quickly.
]]
local ydebug = print
local ndebug = function() end
local debug = ydebug
-- the minimum magnitude of acceleration to cause explosion
local crit = 200
-- explosion parameters
local r = 5
tntdef = {
radius = r,
damage_radius = r,
}
local step = function(self, dtime)
local oldv = self.previous
local o = self.object
local newv = o:get_velocity()
-- again, only run processing if we have a previous velocity for reference.
if oldv then
-- measure the difference in the velocities.
local vdiff = vector.distance(newv, oldv)
-- acceleration: ms^-2, velocity: ms^-1
-- divide by dtime to get acceleration over that period.
local adiff = vdiff / dtime
-- pushed around too hard?
if adiff > crit then
-- KABOOM
debug("tntball velocities: adiff="..adiff)
local pos = o:get_pos()
o:remove()
tnt.boom(pos, tntdef)
end
end
self.previous = newv
end
return step