Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- limboKeys.lua
- -- Key positions on the screen
- local keyPositions = {
- {x = 5, y = 5},
- {x = 15, y = 5},
- {x = 25, y = 5},
- {x = 35, y = 5},
- {x = 45, y = 5},
- {x = 5, y = 15},
- {x = 15, y = 15},
- {x = 25, y = 15},
- }
- -- Function to draw a key at a given position with a specified color
- local function drawKey(pos, color)
- term.setCursorPos(pos.x, pos.y)
- term.setBackgroundColor(color)
- term.write(" ") -- Draw a 4x1 block
- term.setBackgroundColor(colors.black)
- end
- -- Function to initialize keys as red
- local function initializeKeys()
- term.clear()
- for _, pos in ipairs(keyPositions) do
- drawKey(pos, colors.red)
- end
- end
- -- Function to randomly shuffle the keys
- local function shuffleKeys()
- local shuffledPositions = {}
- for _, pos in ipairs(keyPositions) do
- table.insert(shuffledPositions, pos)
- end
- -- Shuffle positions
- for i = #shuffledPositions, 2, -1 do
- local j = math.random(i)
- shuffledPositions[i], shuffledPositions[j] = shuffledPositions[j], shuffledPositions[i]
- end
- return shuffledPositions
- end
- -- Function to randomly assign colors to keys
- local function assignColors()
- local colorsList = {colors.red, colors.green, colors.blue, colors.yellow, colors.purple, colors.orange, colors.cyan}
- local keyColors = {}
- for _, pos in ipairs(keyPositions) do
- keyColors[pos] = colorsList[math.random(#colorsList)]
- end
- return keyColors
- end
- -- Function to animate key scrambling
- local function animateScrambling()
- local numFrames = 10
- for frame = 1, numFrames do
- initializeKeys()
- local shuffledPositions = shuffleKeys()
- local keyColors = assignColors()
- -- Draw keys in new positions
- for i, pos in ipairs(shuffledPositions) do
- drawKey(pos, keyColors[pos])
- end
- -- Delay to create animation effect
- os.sleep(0.1)
- end
- end
- -- Main function
- local function main()
- math.randomseed(os.time())
- initializeKeys()
- -- Randomly select the key to turn green
- local greenKeyIndex = math.random(#keyPositions)
- local greenKey = keyPositions[greenKeyIndex]
- -- Flash green for 1 second
- drawKey(greenKey, colors.green)
- os.sleep(1)
- -- Clear the green key and animate the scrambling
- initializeKeys()
- animateScrambling()
- -- Prompt user to press the key that was green
- term.setCursorPos(1, 20)
- term.write("Press the key that was green!")
- -- Wait for user input
- local event, key = os.pullEvent("key")
- -- Check if the pressed key matches the green key position
- local pressedPos = nil
- for _, pos in ipairs(keyPositions) do
- if term.getCursorPos() == pos then
- pressedPos = pos
- break
- end
- end
- if pressedPos == greenKey then
- term.setCursorPos(1, 21)
- term.write("Correct key!")
- else
- term.setCursorPos(1, 21)
- term.write("Wrong key!")
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement