-
Notifications
You must be signed in to change notification settings - Fork 5
/
namedConstants.lua2p
46 lines (34 loc) · 1.2 KB
/
namedConstants.lua2p
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
--[[============================================================
--=
--= LuaPreprocess example: Named constants.
--=
--= Here we use named constants in the code but the final
--= program will only have literal values.
--=
--============================================================]]
!DEFAULT_ANIMATION_NAME = "my_animation"
!DOUBLE_ANIMATION_SPEED = true
!ANIMATION_SPEED = DOUBLE_ANIMATION_SPEED and 2 or 1
function newAnimation(totalDuration, name)
name = name or !(DEFAULT_ANIMATION_NAME)
local animation = {}
animation.name = name
animation.totalDuration = totalDuration
animation.currentPosition = 0
return animation
end
function updateAnimation(animation, deltaTime)
local deltaPosition = deltaTime * !(ANIMATION_SPEED)
animation.currentPosition = (animation.currentPosition + deltaPosition) % animation.totalDuration
end
function testAnimationStuff()
!local ANIMATION_DURATION = 5.0
!local LOOP_COUNT = 5
!local DELTA_TIME = 0.1
local animation = newAnimation(!(ANIMATION_DURATION))
for i = 1, !(LOOP_COUNT) do
updateAnimation(animation, !(DELTA_TIME))
print(animation.name.." position: "..animation.currentPosition)
end
end
testAnimationStuff()