This repository has been archived by the owner on May 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.lua
71 lines (62 loc) · 1.98 KB
/
main.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
68
69
70
71
--- This is the main Love file, containing all the pieces of the game loop.
-- Services
local Args = require 'src/services/args'
local Camera = require 'src/services/camera'
local Entity = require 'src/services/entity'
local Input = require 'src/services/input'
local Love = require 'src/services/love'
local Map = require 'src/services/map'
local World = require 'src/services/world'
-- Systems
local UpdateCamera = require 'src/systems/update-camera'
local UpdateEntityAnimation = require 'src/systems/update-entity-animation'
local UpdateEntityVelocity = require 'src/systems/update-entity-velocity'
local UpdatePlayerVelocity = require 'src/systems/update-player-velocity'
-- Functions to initialize on game boot
function Love.load(args)
Args.load(args)
Map.load('general')
-- Press esc to close game
Input.register_key_press('escape', function()
Love.event.quit()
end)
end
-- Functions to run on re-draw
function Love.draw()
Camera.set()
Map.draw()
Camera.unset()
end
-- Gamepad/Joystick dpad button press event
-- joystick (joystick table) https://love2d.org/wiki/Joystick
-- button (string)
function Love.gamepadpressed(_, button)
Input.call_key_press(button)
end
-- Gamepad/Joystick dpad button release event
-- joystick (joystick table) https://love2d.org/wiki/Joystick
-- button (string)
function Love.gamepadreleased(_, button)
Input.call_key_release(button)
end
-- All active callbacks for pressing a key
-- pressedKey (string)
function Love.keypressed(pressed_key)
Input.call_key_press(pressed_key)
end
-- All active callbacks for releasing a key
-- releasedKey (string)
function Love.keyreleased(released_key)
Input.call_key_release(released_key)
end
-- Calculations to re-run on going through another loop
-- dt (integer) delta time (in seconds)
function Love.update(dt)
for _, entity in ipairs(Entity.list) do
UpdateCamera(entity)
UpdateEntityVelocity(entity)
UpdatePlayerVelocity(entity)
UpdateEntityAnimation(entity, dt)
end
World:update(dt)
end