File: joystick.lua

package info (click to toggle)
mrrescue 1.02e-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 13,228 kB
  • sloc: makefile: 9; sh: 1
file content (103 lines) | stat: -rw-r--r-- 2,392 bytes parent folder | download
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
joystick = {}

local lg = love.graphics

function joystick.enter()
	state = STATE_JOYSTICK
	joystick.selection = 1
	joystick.waiting = false
end

function joystick.update(dt)
	updateKeys()
end

function joystick.draw()
	lg.push()
	lg.scale(config.scale)
	lg.setFont(font.bold)

	drawBox(40,54,176,95)

	lg.printf("SET JOYSTICK", 0, 39, WIDTH, "center")
	for i=1,4 do
		if joystick.waiting == true and joystick.selection == i then
			lg.setColor(195/255,52/255,41/255)
		end
		lg.print(string.upper(joykeynames[i]), 65, 53+i*13)
		lg.print(config.joykeys[joykeynames[i]], 165, 53+i*13)
		lg.setColor(1,1,1)
	end
	lg.print("DEFAULT", 65, 118)
	lg.print("BACK", 65, 131)

	lg.print(">", 52, 53+joystick.selection*13)

	lg.pop()
end

function joystick.keypressed(k, uni)
	if k == "down" then
		joystick.selection = wrap(joystick.selection + 1, 1, 6)
		playSound("blip")
	elseif k == "up" then
		joystick.selection = wrap(joystick.selection - 1, 1, 6)
		playSound("blip")
	elseif k == "return" then
		if joystick.selection >= 1 and joystick.selection <= 4 then -- Keys
			playSound("blip")
			joystick.waiting = true
		elseif joystick.selection == 5 then -- Default
			playSound("confirm")
			defaultJoyKeys()
		elseif joystick.selection == 6 then -- Back
			playSound("confirm")
			options.enter()
		end
	elseif k == "escape" then
		if joystick.waiting == true then
			joystick.waiting = false
			playSound("blip")
		else
			options.enter()
			playSound("confirm")
		end
	end
end

function joystick.joystickpressed(joy, k)
	if joystick.waiting == false then
		for a, key in pairs(config.joykeys) do
			if k == key then
				gamestates[state].action(a)
			end
		end
	else
		playSound("blip")
		config.joykeys[joykeynames[joystick.selection]] = k
		joystick.waiting = false
	end
end

function joystick.action(k)
	if k == "down" then
		joystick.selection = wrap(joystick.selection + 1, 1, 6)
		playSound("blip")
	elseif k == "up" then
		joystick.selection = wrap(joystick.selection - 1, 1, 6)
		playSound("blip")
	elseif k == "jump" then
		if joystick.selection >= 1 and joystick.selection <= 4 then -- Keys
			joystick.waiting = true
		elseif joystick.selection == 5 then -- DEFAULT
			playSound("confirm")
			defaultJoyKeys()
		elseif joystick.selection == 6 then -- BACK
			playSound("confirm")
			options.enter()
		end
	elseif k == "action" then
		options.enter()
		playSound("confirm")
	end
end