Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local w,h = term.getSize()
- local running
- local notes = {}
- local receptor = {
- x = 3,
- y = 2,
- blink = 4
- }
- local keymap = {
- left=1,
- down=2,
- up=3,
- right=4
- }
- local notemap = {'<', 'V', '^', '>'}
- local utime = 0.1
- local utimer
- local judgement
- local judgetime = 0
- local score = 0
- local bgcolor = colors.black
- local function doJudge(num)
- judgement = num
- judgetime = 0.5 + utime
- end
- local function update(dt)
- for i=#notes, 1, -1 do
- local note = notes[i]
- if note.y > -receptor.y then
- note.y = note.y - 1
- else
- table.remove(notes, i)
- doJudge(0)
- score = score - 5
- end
- end
- if receptor.blink > 0 then
- receptor.blink = receptor.blink - 1
- else
- receptor.blink = 4
- -- for testing
- table.insert(notes, {
- col = math.random(4);
- y = 19;
- })
- end
- judgetime = judgetime - dt
- if utime == 0 then
- bgcolor = 2^math.random(15)
- end
- end
- local function keypressed(k)
- if keymap[k] then
- for i,note in pairs(notes) do
- if note.col == keymap[k] then
- local dist = math.abs(note.y)
- if dist == 0 then
- doJudge(1) -- marvelous
- score = score + 10
- elseif dist <= 1 then
- doJudge(2) -- perfect
- score = score + 5
- elseif dist <= 2 then
- doJudge(3) -- great
- score = score + 1
- end
- if dist <= 2 then
- table.remove(notes, i)
- end
- break
- end
- end
- end
- if k == 'backspace' then
- running = false
- end
- end
- local function draw()
- local t = term
- local w,h = term.getSize()
- t.setBackgroundColor(bgcolor)
- t.clear()
- -- draw the receptor
- t.setTextColor(
- receptor.blink == 0 and
- colors.white or
- colors.lightGray
- )
- t.setCursorPos(receptor.x, receptor.y)
- t.write('> <')
- -- draw the notes
- local notecolors = {
- colors.red,
- colors.yellow,
- colors.lime,
- colors.lightBlue
- }
- for _, note in pairs(notes) do
- t.setCursorPos(note.col + receptor.x, note.y + receptor.y)
- t.setTextColor(notecolors[note.col])
- t.write(notemap[note.col])
- end
- -- judgement
- local words = {
- [0] = {'miss', colors.red};
- {'Amazing!', colors.lightBlue};
- {'Perfect!', colors.yellow};
- {'Nice!', colors.lime};
- }
- if judgement and judgetime > 0 then
- local item = words[judgement]
- local word, color = item[math.random(#item - 1)], item[#item]
- t.setCursorPos(receptor.x + 8, receptor.y)
- t.setTextColor(judgetime >= 0.5 and colors.white or color)
- t.write(word)
- end
- -- score
- local scorestr = ('0'):rep(4 - #tostring(score)) ..score
- t.setCursorPos(receptor.x + 8, receptor.y + 2)
- t.setTextColor(colors.yellow)
- t.write(scorestr)
- end
- local function selectMode()
- local modes = {'Easy','Normal','Hard','Satan',"You're high."}
- local times = {0.2, 0.15, 0.1, 0.05, 0}
- local selection = 1
- local t = term
- while true do
- t.setTextColor(colors.white)
- t.setBackgroundColor(colors.black)
- t.clear()
- t.setCursorPos(3, 2)
- t.write 'Select Difficulty'
- for i,v in pairs(modes) do
- t.setTextColor(colors.white)
- if selection == i then
- t.setTextColor(colors.lime)
- t.setCursorPos(2, i + 3)
- t.write '>'
- end
- t.setCursorPos(3, i + 3)
- t.write(v)
- end
- local _, k = os.pullEvent('key')
- if k == keys.up then
- selection =
- selection > 1 and
- selection - 1 or
- #modes
- elseif k == keys.down then
- selection =
- selection < #modes and
- selection + 1 or
- 1
- elseif k == keys.enter then
- return times[selection]
- end
- end
- end
- term.setBackgroundColor(colors.black)
- term.clear()
- utime = selectMode()
- utimer = os.startTimer(utime)
- running = true
- while running do
- draw()
- local ev, p1 = os.pullEvent()
- if ev == 'timer' and p1 == utimer then
- update(utime)
- utimer = os.startTimer(utime)
- elseif ev == 'key' then
- keypressed(keys.getName(p1))
- end
- end
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(1,1)
Advertisement
Add Comment
Please, Sign In to add comment