Repository navigation
Expand file tree
/
Copy pathmain.lua
More file actions
106 lines (84 loc) · 2.49 KB
/
Copy pathmain.lua
File metadata and controls
106 lines (84 loc) · 2.49 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
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
100
101
102
103
104
105
106
------------------------------------------------
-- Entry point for game.
-- This is the entry poing to the Love game
-- @author jose@josellausas.com
local Engine = require('src.Engine')
local InputManager = require('src.InputManager')
local world00 = require('rules.world00')
---------------------------------------------------------
-- The windows width
-- @return number The width in pixels
local function getWidth()
return love.graphics.getWidth()
end
---------------------------------------------------------
-- The window's height.
-- @return number The height in pixels
local function getHeight()
return love.graphics.getHeight()
end
---------------------------------------------------------
-- Load Game.
-- Loads and initializes the game
function love.load()
InputManager:init()
Engine:init(world00)
end
---------------------------------------------------------
-- Update Game.
-- The game loop, updates all physics
-- @tparam float Time since last frame
function love.update(dt)
Engine:update(dt)
end
---------------------------------------------------------
-- Draw Game.
-- Renders the scene after the update
function love.draw()
Engine:draw()
end
---------------------------------------------------------
-- Quits the program.
-- Exits the program in a clean way.
function love.quit()
-- Before quits runs this:
Engine:shutdown()
InputManager:shutdown()
end
---------------------------------------------------------
-- Handles the focus event
-- @param f Indicates if we have focus
function love.focus(f)
if not f then
print("Lost focus")
else
print("Gained focus")
print("Window dimensions = { " .. getWidth() .. " , " .. getHeight() .. " } ")
end
end
---------------------------------------------------------
-- Handles mouse presses.
--
-- @param x **(Number)** The x coordinate
-- @param y **(Number)** The y coordinate
-- @param button **(Button)** the button pressed
function love.mousepressed(x,y,button)
InputManager:handleMousePressed(button, x, y)
end
---------------------------------------------------------
-- Mouse button has been released.
function love.mousereleased(x,y,button)
InputManager:handleMouseReleased(button, x, y)
end
---------------------------------------------------------
-- A key has been presed.
function love.keypressed(key)
InputManager:handleKeyPressed(key)
end
---------------------------------------------------------
-- Handles heyboard input
--
-- @param key The key that was pressed
function love.keyreleased(key)
InputManager:handleKeyReleased(key)
end