-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.lua
More file actions
63 lines (49 loc) · 1.26 KB
/
Copy pathgame.lua
File metadata and controls
63 lines (49 loc) · 1.26 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
local rot=require 'lib/rotLove/rotLove/rotLove'
local game = {}
-- private variables
local _display = nil
local _currentScreen = nil
local _screenWidth = 80
local _screenHeight = 24
function game.init()
math.randomseed(os.time())
-- Any necessary initialization will go here.
_display = rot.Display(_screenWidth, _screenHeight + 1)
end
function game.getDisplay()
return _display
end
function game.switchScreen(screen)
-- If we had a screen before, notify it that we exited
if _currentScreen ~= nil then
_currentScreen.exit()
end
-- Clear the display
_display:clearCanvas()
-- Update our current screen, notify it we entered
-- and then render it
_currentScreen = screen
if _currentScreen ~= nil then
_currentScreen.enter()
game.refresh()
end
end
function game.handleInput(key, isrepeat)
if _currentScreen ~= nil then
-- Send the event type and data to the screen
_currentScreen.handleInput(key, isrepeat)
end
end
function game.refresh()
-- Clear the screen
_display:clear()
-- Render the screen
_currentScreen.render(_display)
end
function game.getScreenWidth()
return _screenWidth
end
function game.getScreenHeight()
return _screenHeight
end
return game