-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.lua
More file actions
67 lines (56 loc) · 1.86 KB
/
main.lua
File metadata and controls
67 lines (56 loc) · 1.86 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
67
-- Definition of the game's main 'loop'.
-- Aurelien Coet, 2017.
local Game = require "engine/game"
local Vector2D = require "lib/vector2d"
function love.load()
game = Game()
end
function love.update(dt)
game:update(dt)
end
function love.draw()
game:draw()
love.graphics.print("Current FPS: "..tostring(love.timer.getFPS( )), 10, 10)
end
--------------------------------------------------------------------------------
-- Callback function to handle mouse buttons being pressed.
--------------------------------------------------------------------------------
function love.mousepressed(x, y, button, istouch)
if game.state == "running" then
-- If a message was being displayed in-game, it is erased when the
-- player moves.
game.message = nil
-- A new path between the player's position and the position where the
-- mouse was clicked is applied to the player.
local mouseX, mouseY = room.camera:toWorld(x, y)
player:newWalkPath(mouseX, mouseY, room)
-- Check if the player clicked on a door to go to another room.
for i, door in ipairs(room.doors) do
if x > door.leftEdge and
x < door.rightEdge and
y > door.topEdge and
y < door.bottomEdge then
room.playerLeavingRoom = true
break
end
room.playerLeavingRoom = false
end
-- Check if the player clicked on an item in the room to observe it
-- (left click) or use it/pick it up (right click).
for i, item in pairs(room.items) do
if x > item.leftEdge and
x < item.rightEdge and
y > item.topEdge and
y < item.bottomEdge then
if button == 1 then
item.clickedLeft = true
elseif button == 2 then
item.clickedRight = true
end
else
item.clickedLeft = false
item.clickedRight = false
end
end
end
end