Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local w, h = term.getSize()
- local levels = {
- [0] = {
- "",
- "",
- "",
- "",
- "",
- "",
- "",
- "",
- " REBOOT ",
- " [ ] ",
- "",
- "",
- "",
- "",
- "",
- "",
- "",
- "",
- ""
- },
- [1] = {
- "_l0c?l ???? = ????",
- "????????",
- "",
- "?????????_",
- "???????_",
- "?????? = _{????}",
- "",
- "????????",
- "?????????_",
- "????????_",
- "???????",
- "",
- "???????_",
- "????/????",
- "????? = ???",
- "????_????",
- "???????????_",
- "????????_",
- "?????????_"
- },
- [2] = {
- "for ??, ? ?? o",
- " x??7?",
- " ? ?? > 9 t??",
- " ? ??f????_",
- " ?nd_",
- "e?d",
- "",
- "?un?t??n??l ?d?(?, ??)",
- " ?? o???????_",
- " ?? ?? ??_",
- "?nd????_",
- "",
- " ?? ??_",
- "????/??>?",
- "loc??? an ?? <?_ or??",
- "????_nil ???",
- "????? ?????_",
- "?? i?????_",
- "????//\"????_"
- }
- }
- local cInfo = {}
- for i = 0, #levels do
- cInfo[i] = {}
- for n = 1, 19 do
- cInfo[i][n] = {}
- end
- end
- local cLvl = 1
- local ticknum = 5
- local cSpeed = 4
- local damageTick
- local timers = {
- gametick = os.startTimer(.05)
- }
- local function restartTimers()
- timers = {
- gametick = os.startTimer(.05),
- invuln = os.startTimer(.05)
- }
- end
- local returnTick = {
- [0] = function() if ticknum%5 == 0 then return true end; return false end,
- [1] = function() if ticknum%4 == math.random(0, 3) then return true end; return false end,
- [2] = function() if ticknum%4 == 0 then return true end; return false end,
- [3] = function() if ticknum%3 == math.random(0, 2) then return true end; return false end,
- [4] = function() if ticknum%3 == 0 then return true end; return false end,
- [5] = function() if ticknum%2 == math.random(0, 1) then return true end; return false end,
- [6] = function() if ticknum%2 == 0 then return true end; return false end,
- [7] = function() return true end
- }
- local player = {
- color = colors.lightBlue,
- pos = {x = w - 1, y = 1, char = " ", txt = colors.white, back = colors.black},
- prev = {x = w - 1, y = 1, char = " ", txt = colors.white, back = colors.black},
- lives = 3,
- invuln = false,
- health = 100
- }
- local function printLevel(lvl) ---also buffers it
- for i, v in pairs(levels[lvl]) do
- local offset = 0
- local unders = 0
- for j = 1, string.len(v) do
- term.setCursorPos(j + offset, i)
- term.setTextColor(colors.white)
- if v:sub(j, j) == "?" then
- if math.random(1, 5) == 1 then
- term.setTextColor(2^math.random(1, 15))
- end
- local char = math.random(0, 126)
- term.write(string.char(char))
- cInfo[cLvl][i][j + offset] = char
- elseif v:sub(j, j) == "_" then
- unders = unders + 1
- term.setCursorPos(j, i)
- local addon = math.random(0, cSpeed*2)
- for n = 1, addon do
- if math.random(1, 5) == 1 then
- term.setTextColor(2^math.random(1, 15))
- end
- local char = math.random(0, 126)
- term.write(string.char(char))
- cInfo[cLvl][i][j + n] = char
- end
- offset = offset + addon
- else
- term.write(v:sub(j, j))
- cInfo[cLvl][i][j + offset] = v:sub(j, j)
- end
- end
- term.write(string.rep(" ", cSpeed*2*unders))
- if #cInfo[cLvl][i] > string.len(v) + offset - unders then
- for n = string.len(v) + offset - unders + 1, #cInfo[cLvl][i] do
- cInfo[cLvl][i][n] = nil
- end
- end
- end
- end
- local function drawInfoBars()
- term.setCursorPos(w, 19)
- term.setBackgroundColor(colors.black)
- term.write(player.lives)
- local color = player.invuln and colors.blue or player.color
- for i = 1, 18 do
- term.setCursorPos(w, i)
- term.setBackgroundColor(player.health/100 >= (18 - i + 1)/18 and color or colors.black)
- term.write(" ")
- end
- end
- local function transition(dir)
- local st, en, inc
- if dir == "up" then
- st, en, inc = 1, 19, 1
- player.pos.y = 19
- elseif dir == "down" then
- st, en, inc = 19, 1, -1
- player.pos.y = 1
- end
- term.setBackgroundColor(colors.gray)
- for i = st, en, inc do
- term.setCursorPos(1, i)
- term.clearLine()
- sleep(.01)
- end
- term.setBackgroundColor(colors.black)
- for i = st, en, inc do
- term.setCursorPos(1, i)
- term.clearLine()
- sleep(.01)
- end
- player.prev.char = " "
- player.prev.back = colors.black
- printLevel(cLvl)
- restartTimers()
- end
- local function printPlayer() --again, also buffers
- term.setBackgroundColor(player.invuln and colors.blue or player.color)
- term.setTextColor(player.pos.txt)
- term.setCursorPos(player.pos.x, player.pos.y)
- term.write(player.pos.char)
- player.prev = {x = player.pos.x, y = player.pos.y, char = player.pos.char, txt = player.pos.txt, back = player.pos.back}
- end
- local function updateScreen()
- term.setBackgroundColor(colors.black)
- if returnTick[cSpeed]() then
- damageTick = true
- printLevel(cLvl)
- end
- if player.pos ~= player.prev then
- term.setCursorPos(player.prev.x, player.prev.y)
- term.setBackgroundColor(player.prev.back)
- term.setTextColor(player.prev.txt)
- term.write(player.prev.char)
- end
- printPlayer()
- end
- local function updateGame()
- if cInfo[cLvl][player.pos.y] and cInfo[cLvl][player.pos.y][player.pos.x] and type(cInfo[cLvl][player.pos.y][player.pos.x]) == "number" and damageTick and not player.invuln then
- player.health = player.health - 10
- drawInfoBars()
- end
- if cInfo[cLvl][player.pos.y] and cInfo[cLvl][player.pos.y][player.pos.x] then
- if type(cInfo[cLvl][player.pos.y][player.pos.x]) == "string" then
- player.pos.char = cInfo[cLvl][player.pos.y][player.pos.x]
- else
- player.pos.char = string.char(cInfo[cLvl][player.pos.y][player.pos.x])
- end
- else
- player.pos.char = " "
- end
- if player.pos.y < 1 then
- cLvl = cLvl - 1
- transition("up")
- elseif player.pos.y > 19 then
- cLvl = cLvl + 1
- transition("down")
- end
- if player.health <= 0 then
- player.health = 100
- player.lives = player.lives - 1
- player.invuln = true
- drawInfoBars()
- timers.invuln = os.startTimer(3)
- end
- end
- local function eventHandler(events)
- if events[1] == "key" then
- if events[2] == keys.up then
- if cLvl > 0 or player.pos.y > 1 then
- player.pos.y = player.pos.y - 1
- end
- elseif events[2] == keys.right and player.pos.x < w - 1 then
- player.pos.x = player.pos.x + 1
- elseif events[2] == keys.down then
- if cLvl < #levels or player.pos.y < 19 then
- player.pos.y = player.pos.y + 1
- end
- elseif events[2] == keys.left and player.pos.x > 1 then
- player.pos.x = player.pos.x - 1
- end
- end
- end
- term.setBackgroundColor(colors.black)
- term.clear()
- updateScreen()
- drawInfoBars()
- while player.lives > 0 do
- local events = {os.pullEvent()}
- damageTick = false
- if events[1] == "timer" then
- if events[2] == timers.gametick then
- updateScreen()
- ticknum = ticknum + 1
- if ticknum > 20 then ticknum = 1 end
- timers.gametick = os.startTimer(.05)
- end
- if events[2] == timers.invuln then
- player.invuln = false
- drawInfoBars()
- end
- else
- eventHandler(events)
- end
- updateGame()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement