-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
66 lines (57 loc) · 1.18 KB
/
main.lua
File metadata and controls
66 lines (57 loc) · 1.18 KB
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
Kuroko = {
x = 0,
y = 0,
w = 100,
h = 100,
dragging = {
grabbed = false,
grabX = 0,
grabY = 0
},
collide = function(self, cx, cy)
return (cx - self.x < self.w) and (cy - self.y < self.h)
end,
draw = function(self)
love.graphics.draw(kuroko, self.x, self.y)
end
};
function love.load()
kuroko = love.graphics.newImage("images/kuroko.png")
x = 100
y = 100
Kuroko.w = kuroko:getWidth()
Kuroko.h = kuroko:getHeight()
end
function love.draw()
--love.graphics.draw(kuroko, Kuroko.x, Kuroko.y)
Kuroko:draw()
--[[
if( Kuroko:collide(love.mouse.getX(), love.mouse.getY()) )
then
-- Kuroko:draw()
end
]]
end
function love.mousepressed(x, y, button)
if( Kuroko:collide(x, y))
then
Kuroko.dragging.grabbed = true
Kuroko.dragging.grabX = x - Kuroko.x
Kuroko.dragging.grabY = y - Kuroko.y
end
end
function love.update(dt)
if(Kuroko.dragging.grabbed)
then
Kuroko.x = love.mouse.getX() - Kuroko.dragging.grabX
Kuroko.y = love.mouse.getY() - Kuroko.dragging.grabY
end
end
function love.mousereleased(x, y, button)
Kuroko.dragging.grabbed= false
end
function love.keypressed(key, isrepeat)
if key == "escape" then
love.event.push("quit")
end
end