Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local event = require("event")
- local char = require("unicode").char
- local clear = require("term").clear
- local gpu = component.gpu
- local exit = false
- local player
- local old = {
- size = {gpu.getResolution()},
- Foreground = gpu.getForeground(),
- Background = gpu.getBackground()
- }
- local new = {
- --size = {gpu.maxResolution()},
- size = {80, 25},
- Foreground = 0x00ff00,
- Background = 0x000000
- }
- local listimg = {
- man = "ec23"
- }
- for k,v in pairs(listimg) do
- listimg[k] = char("0x" .. v)
- end
- local keyboard = {
- [200] = { 0,-1},
- [203] = {-1, 0},
- [205] = { 1, 0},
- [208] = { 0, 1},
- [ 16] = function() exit = true end
- }
- local function interval(min, n, max)
- return math.max(math.min(max, n), min)
- end
- local function printimg(x, y, color)
- gpu.getForeground(color)
- gpu.set(x,y,listimg["man"])
- end
- local function preload()
- player = {
- x = math.modf(new.size[1]/2),
- y = math.modf(new.size[2]/2),
- color = 0x00ff00
- }
- end
- local function prerendering()
- --empty map
- printimg(player.x, player.y, player.color)
- end
- local function control(input)
- local input = keyboard[input]
- if input then
- if type(input) == "table" then
- local x, y = input[1], input[2]
- player.x = interval(1, player.x + x, new.size[1])
- player.y = interval(1, player.y + y, new.size[2])
- else
- input()
- end
- end
- end
- local function rendering()
- --empty map
- clear()
- printimg(player.x, player.y, player.color)
- end
- local function loop()
- local key = {event.pull("key_down")}
- control(key[4])
- rendering()
- end
- local function game()
- preload()
- prerendering()
- while not exit do
- loop()
- os.sleep(0)
- end
- end
- local function start()
- gpu.setBackground(new.Background)
- gpu.setForeground(new.Foreground)
- clear()
- gpu.setResolution(new.size[1], new.size[2])
- game()
- gpu.setBackground(old.Background)
- clear()
- gpu.setForeground(old.Foreground)
- gpu.setResolution(old.size[1], old.size[2])
- end
- start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement