-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu.lua
62 lines (45 loc) · 1.33 KB
/
menu.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
local _ = require "lib/moses"
local sti = require "lib/sti"
local class = require "lib/middleclass"
local bump = require "lib/bump"
local cache = require "cache"
local tween = require "lib/tween"
local Camera = require "entity/camera"
local Menu = {}
function Menu:init()
self.world = bump.newWorld(64)
self.img = cache:getOrLoadImage("asset/menu.png")
self.blackScreen = { opacity = 255 }
self.enterIn = tween.new(2, self.blackScreen, { opacity = 0 })
self.enterOut = tween.new(2, self.blackScreen, { opacity = 255 })
-- camera photo used as pointer
self.camera = Camera:new(self.world, 0, 0)
self.clicked = false
end
function Menu:enter()
love.mouse.setVisible(false)
end
function Menu:update(dt)
self.enterIn:update(dt)
local x, y = love.mouse.getPosition()
self.camera:update(dt)
self.camera:move(x, y)
if self.clicked and not self.camera.takingPhoto then
local ended = self.enterOut:update(dt)
if ended then
GameState.switch(Game)
end
end
end
function Menu:mousePressed(x, y, button)
self.camera:takePhoto()
self.clicked = true
end
function Menu:draw()
love.graphics.draw(self.img, 0, 0)
self.camera:draw()
love.graphics.setColor(0, 0, 0, self.blackScreen.opacity)
love.graphics.rectangle("fill", 0, 0, 1280, 720)
love.graphics.setColor(255, 255, 255, 255)
end
return Menu