-
Notifications
You must be signed in to change notification settings - Fork 0
/
anitext.lua
99 lines (86 loc) · 2.2 KB
/
anitext.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
--[[
Squaricles
Copyright (C) 2017 ITR
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
]]--
AniText = {
value = nil,
angularSpeed = 1.,
angularDist = math.pi/8,
jumps = 2,
jumpHeight = 0.5,
jumpSpeed = 1.5,
isJumping = 0,
cJump = 0.,
}
function AniText:new(other)
other = other or {}
local o = clone(self)
for k,v in pairs(other) do o[k] = v end
o.time = math.random()*math.pi*2
return o
end
function AniText:update(dt)
if self.cJump == 0 then
if self.isJumping>0 then
self.isJumping = self.isJumping - 1
self.cJump = dt*self.jumpSpeed
self.time = math.random(2)*math.pi
if self.angularSpeed < 0.4 then
self.angularSpeed = 0.4
else
self.angularSpeed = self.angularSpeed
* ( math.random()*0.4 + 0.8 )
end
else
self.time = self.time + dt*self.angularSpeed
end
else
self.cJump = self.cJump + dt*self.jumpSpeed
if self.cJump > 1 then
if self.isJumping > 0 then
self.cJump = self.cJump - 1
self.isJumping = self.isJumping-1
else
self.cJump = 0
end
end
end
end
function AniText:draw(value, x, y)
if self.value ~= value then
self.isJumping = self.isJumping + self.jumps
self.value = value
end
local h = font:getHeight()
local w = font:getWidth(value)
y = y + self:getJumpHeight(self.cJump)*h
love.graphics.setColor(255,255,255)
love.graphics.print(
value,
x, y,
math.sin(self.time)*self.angularDist,
1, 1,
w/2, h/2
)
end
function AniText:getJumpHeight(x)
if x < 0 or x > 0.8 then
return 0
elseif x < 0.51282 then
x = 1.95*x - 1
else
x = x-0.51282+0.285714
x = 3.5*x-1
end
return (x*x-1)*self.jumpHeight
end