summaryrefslogtreecommitdiff
path: root/client/main.lua
blob: 1d9409ffd151820ee2504c0282eb8ca4a85ed048 (plain)
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
local gamescene = require"game"
local utf8 = require 'utf8'

local current_scene
local function switch_scene(newscene,...)
	if current_scene.quit then current_scene.quit() end
	current_scene = newscene
	if newscene.load then newscene.load(...) end
end


local big_font = love.graphics.newFont(72)
local normal_font = love.graphics.getFont()

local username = 'horace'


local titlescene = {}
function titlescene.draw()
	love.graphics.clear(1,1,1)
	love.graphics.origin()
	love.graphics.setColor(0,0,0)
	love.graphics.setFont(big_font)
	love.graphics.print("hexagon emulator",30,30)
	love.graphics.setFont(normal_font)

	love.graphics.print("enter username: ",40,120)

	love.graphics.setColor(0,0,0,0.8)
	love.graphics.rectangle('fill', 60,150, 3+normal_font:getWidth(username), 15)
	love.graphics.setColor(1,1,1)
	love.graphics.print(username,   60, 150)

	love.graphics.setColor(0,0,0)
	love.graphics.print("press <enter> to start",40,250)
end

function titlescene.keypressed(k,s,r)
	if k=='backspace' then
		local b = utf8.offset(username, -1)
		if b then
			username = username:sub(1,b-1)
		end
	elseif k=="return" then
		switch_scene(gamescene)
	end
end

function titlescene.textinput(text)
	username = username .. text
end

function titlescene.load()
	love.keyboard.setKeyRepeat(true)
end




for _,f in ipairs{
	"update",
	"draw",
	"keypressed",
	"textinput",
	"wheelmoved",
	"quit",
} do
	love[f] = function(...)
		local x = current_scene[f]
		if x then return x(...) end
	end
end

current_scene=titlescene
current_scene.load()