-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmain.lua
More file actions
146 lines (122 loc) · 2.95 KB
/
main.lua
File metadata and controls
146 lines (122 loc) · 2.95 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
--[[print = function(...)
local args = {...}
origPrint( unpack(args) )
local str = ""
for k, v in pairs(args) do
str = str .. v .. "\t"
end
love.filesystem.append( "log.txt", str .. "\r\n" )
end]]
network = require( "network.network" )
stats = require( "stats" )
config = require( "config" )
game = require( "game" )
lobby = require( "lobby" )
map = require( "map" )
if not DEDICATED then
ui = require( "lib/punchUI" )
menu = require( "menu" )
images = require( "images" ) -- loads all images.
chat = require( "chat" )
end
utility = require( "utility" ) -- helper functions
require( "callbacks" ) -- helper functions
Timer = require("timer")
Sounds = require("sounds")
server = nil
client = nil
STATE = "Menu"
MAX_PLAYERS = 16
PORT = 3410
MAIN_SERVER_URL = "http://germanunkol.de/gridcars/serverlist"
GAME_ID = "GridCars"
function love.load( args )
config.load()
images:load() -- preload all images
Sounds:load()
chat:init()
lobby:init()
menu:init()
game:init()
map:load()
menu:show()
--[[local startServer = false
local startClient = false
if args[2] == "client" then
startClient = true
elseif args[2] == "server" then
startServer = true
end
if startServer then
-- Start a server with a maximum of 16 users.
server = network:startServer( MAX_PLAYERS, PORT )
-- Connect to the server.
client = network:startClient( 'localhost', PLAYERNAME, PORT )
-- set server callbacks:
setServerCallbacks( server )
-- set client callbacks:
setClientCallbacks( client )
lobby:show()
elseif startClient then
if args[3] then
client = network:startClient( args[3], PLAYERNAME, PORT )
setClientCallbacks( client )
else
print( "Error. To start as client, you should give the address as the argument after 'client'." )
end
end]]
--love.graphics.setBackgroundColor(25,25,25,255)
love.graphics.setBackgroundColor( 20,80,20,255)
end
function love.update( dt )
network:update( dt )
if STATE == "Game" then
game:update( dt )
chat:update( dt )
elseif STATE == "Lobby" then
lobby:update( dt )
chat:update( dt )
elseif STATE == "Menu" then
menu:update( dt )
end
ui:update( dt )
ui:mousemoved( love.mouse.getPosition() )
end
function love.keypressed( key, unicode )
--chat:keypressed( key )
if chat.active then
chat:keypressed( key )
elseif not ui:keypressed( key, unicode ) then
map:keypressed( key )
chat:keypressed( key )
end
end
function love.textinput( letter )
--chat:textinput( letter )
if chat.active then
chat:textinput( letter )
elseif (not ui:textinput( letter )) then
end
end
function love.mousepressed( x, y, button )
if ui:mousepressed( x, y, button ) then
return
end
map:mousepressed( x, y, button )
if STATE == "Game" then
game:mousepressed( x, y, button )
end
end
function love.draw()
if STATE == "Game" then
game:draw()
elseif STATE == "Lobby" then
lobby:draw()
elseif STATE == "Menu" then
menu:draw()
end
if STATE == "Game" or STATE == "Lobby" then
chat:draw()
end
ui:draw()
end