Applied the renames for "minimum buttons pressed", "minimum buttons inputted".

This commit is contained in:
brandonevans 2012-04-25 04:35:27 +00:00
parent 82999aa2a9
commit 32a7970a99
1 changed files with 122 additions and 122 deletions

View File

@ -6,10 +6,10 @@ local controllers = 2
local x = 0 local x = 0
local y = 8 local y = 8
local holds = 0
local players = {} local players = {}
local presses = 0
local states = {} local states = {}
local pressed = 0
local inputted = 0
function table.copy(t) function table.copy(t)
local t2 = {} local t2 = {}
@ -20,23 +20,23 @@ function table.copy(t)
end end
function counts() function counts()
--Display the counts of the holds and the presses. --Display the counts of the buttons pressed and inputted.
gui.text(x, y, 'Holds: ' .. holds) gui.text(x, y, 'Pressed: ' .. pressed)
gui.text(x, y + 8, 'Presses: ' .. presses) gui.text(x, y + 8, 'Inputted: ' .. inputted)
end end
function load(slot) function load(slot)
--As Lua starts counting from 1, and there may be a slot 0, increment. --As Lua starts counting from 1, and there may be a slot 0, increment.
slot = slot + 1 slot = slot + 1
if not states[slot] or not states[slot].holds then if not states[slot] or states[slot].inputted == nil then
gui.text(x, y + 16, 'No data loaded from slot ' .. tostring(slot - 1)) gui.text(x, y + 16, 'No data loaded from slot ' .. tostring(slot - 1))
counts() counts()
return return
end end
--Load the data if there is any available for this slot. --Load the data if there is any available for this slot.
holds = states[slot].holds
players = table.copy(states[slot].players) players = table.copy(states[slot].players)
presses = states[slot].presses pressed = states[slot].pressed
inputted = states[slot].inputted
gui.text(x, y + 16, 'Data loaded from slot ' .. tostring(slot - 1)) gui.text(x, y + 16, 'Data loaded from slot ' .. tostring(slot - 1))
counts() counts()
end end
@ -79,13 +79,13 @@ function parse()
button = button + 1 button = button + 1
--Check if this button is pressed. --Check if this button is pressed.
if text ~= ' ' and text ~= '.' then if text ~= ' ' and text ~= '.' then
holds = holds + 1 inputted = inputted + 1
--If the button was not previously pressed, --If the button was not previously pressed,
--increment. --increment.
if table.maxn(last) < player or not last[player][ if table.maxn(last) < player or not last[player][
match[button] match[button]
] then ] then
presses = presses + 1 pressed = pressed + 1
end end
if table.maxn(players) < player then if table.maxn(players) < player then
table.insert(players, {}) table.insert(players, {})
@ -110,9 +110,9 @@ function save(slot)
table.insert(states, {}) table.insert(states, {})
end end
--Mark the current data as the data for this slot. --Mark the current data as the data for this slot.
states[slot].holds = holds
states[slot].players = table.copy(players) states[slot].players = table.copy(players)
states[slot].presses = presses states[slot].pressed = pressed
states[slot].inputted = inputted
gui.text(x, y + 16, 'Data saved to slot ' .. tostring(slot - 1)) gui.text(x, y + 16, 'Data saved to slot ' .. tostring(slot - 1))
counts() counts()
end end
@ -130,19 +130,19 @@ end
while true do while true do
--If this is the first frame, reset the data. --If this is the first frame, reset the data.
if emu.framecount() == 0 then if emu.framecount() == 0 then
holds = 0
players = {} players = {}
presses = 0 pressed = 0
inputted = 0
end end
--Check players one and two. --Check players one and two.
for player = 1, controllers do for player = 1, controllers do
local buttons = joypad.getdown(player) local buttons = joypad.getdown(player)
--Run through all of the pressed buttons. --Run through all of the pressed buttons.
for i, v in pairs(buttons) do for i, v in pairs(buttons) do
holds = holds + 1 inputted = inputted + 1
--If in the previous frame the button was not pressed, increment. --If in the previous frame the button was not pressed, increment.
if table.maxn(players) >= player and not players[player][i] then if table.maxn(players) >= player and not players[player][i] then
presses = presses + 1 pressed = pressed + 1
end end
end end
if table.maxn(players) < player then if table.maxn(players) < player then