-
Notifications
You must be signed in to change notification settings - Fork 3
/
utility.lua
67 lines (62 loc) · 1.77 KB
/
utility.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
function drawCircle(circle)
love.graphics.circle("fill", circle.x, circle.y, circle.size)
end
function updateObject(object, dt)
if (object == "player") then
local length = distance(object.x, object.y, object.DestX, object.destY)
while (length > 0) do
object.x = object.x + object.vx * dt
object.y = object.y + object.vy * dt
end
else
object.x = object.x + object.vx * dt
object.y = object.y + object.vy * dt
end
end
function distance(x1, y1, x2, y2)
return math.sqrt((x1 - x2) ^ 2 + (y1 - y2) ^ 2)
end
function drawImage(object, image)
local upVec = -1
local rightVec = 1
if not (object.vx == 0 and object.vy == 0) then
object.Yangle = math.acos(upVec * object.vy / math.sqrt(object.vy ^ 2 + object.vx ^ 2))
if object.vx < 0 then
object.Yangle = 2 * math.pi - object.Yangle
end
end
local factorX = 2 * object.size / image:getWidth()
local factorY = 2 * object.size / image:getHeight()
love.graphics.draw(
image,
(object.x),
(object.y),
object.Yangle,
factorX,
factorY,
image:getWidth() / 2,
image:getHeight() / 2
)
end
function drawPlayerAxe(object, image)
local factorX = 2 * object.size / image:getWidth()
local factorY = 3.10639309197 * object.size / image:getHeight()
love.graphics.draw(
image,
(object.x),
(object.y),
object.Yangle,
factorX,
factorY,
image:getWidth() / 2,
image:getHeight()
)
end
function playSound(sound)
love.audio.newSource(sound, "static"):play()
end
function playBackgroundMusic(sound)
music = love.audio.newSource(sound, "static")
music:setLooping(true)
music:play()
end