-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.lua
88 lines (79 loc) · 2.3 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
-- (C) 2012 Thomas R. Koll, <info@ananasblau.com>
-- Cross Country Runner
require("lib/middleclass")
gui = require("lib/quickie")
require('table')
require('entities/runner')
require("player_controller")
require("ai_controller")
require("game_controller")
require("game_state")
require('views/gui_main')
require('worker')
require('worker_spawner')
require('job')
require('job_spawner')
require('views/start_menu_view')
function love.load()
game_state = GameState()
gui_main = GUIMain(game_state)
gui_main.font = love.graphics.newFont(14)
gui_main.small_font = love.graphics.newFont(10)
game_controller = GameController(game_state, gui_main)
dt_since_last_move = 1
start_menu_view = StartMenuView()
end
function love.update(dt)
start_menu_view:update()
local moved = false
if game_state.paused then
return
end
gui_main:update(dt, moved)
game_controller:update(dt)
gui_main:drawMaps()
end
function love.keypressed(key, unicode)
if not game_state.started then
return
end
dt_since_last_move = 1 -- to allow rapid key hitting
if unicode >= 49 and unicode < 59 then
game_state.player:setSpeed(unicode - 48)
end
if game_controller.active_controller then
game_controller.active_controller:keypressed(key, unicode)
end
end
function love.draw()
if not game_state.started then
start_menu_view:draw()
drawCopyright()
return
end
if game_state.paused then
-- TODO draw a background
gui_main.instructions_view:draw()
drawCopyright()
return
end
love.graphics.clear()
gui_main:draw()
love.graphics.setColor(255,255,255,255)
love.graphics.setFont(gui_main.font)
if game_state.paused then
love.graphics.print('PAUSED', 10, 20)
else
love.graphics.print("FPS: "..love.timer.getFPS(), 10, 20)
end
drawCopyright()
end
function drawCopyright()
love.graphics.setFont(gui_main.small_font)
love.graphics.print(love.graphics.getCaption(), love.graphics.getWidth(), love.graphics.getHeight(), 0, 1, 1, 176, 14)
love.graphics.setFont(gui_main.font)
end
function finishScreen()
love.graphics.print('AWESOME, you finished on place ' .. game_state:playerPosition(), love.graphics.getWidth() / 2 - 120, love.graphics.getHeight() / 2 - 5)
love.graphics.print('Press [q] to quit', love.graphics.getWidth() / 2 - 40, love.graphics.getHeight() / 2 + 25)
end