Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- levels = {}
- levels['1'] = {}
- levels['1']['x'] = 9
- levels['1']['y'] = 9
- levels['1']['map'] = {
- "#############################################################################",
- "#BSX #",
- "# #",
- "# #",
- "# #",
- "# #",
- "# #",
- "# #",
- "# #",
- "# #",
- "# #",
- "# #",
- "# #",
- "# #",
- "# #",
- "# #",
- "# #",
- "# #",
- "# #",
- "# #",
- "# #",
- "# #",
- "# #",
- "# #",
- "# #",
- "# #",
- "# #",
- "# #",
- "# #",
- "# #",
- "# #",
- "# #",
- "# #",
- "# #",
- "# #",
- "#############################################################################"
- }
- ball = {}
- ball['size'] = 1
- ball['x'] = levels['1']['x']
- ball['y'] = levels['1']['y']
- ball['drawx'] = levels['1']['x']
- ball['drawy'] = levels['1']['y']
- scroll = {}
- scroll['x'] = 0
- scroll['y'] = 0
- w, h = term.getSize()
- function getChar(x, y)
- lvl = levels['1']['map'][y]
- print(lvl)
- if(lvl ~= nil)then
- char = string.sub(lvl, x, x)
- return char
- end
- return " "
- end
- function canMove(x, y, size)
- if(size == 1)then
- if(getChar(x, y) ~= " ")then
- return false
- end
- elseif(size == 2)then
- for u = 0, 1 do
- for d = 0, 1 do
- if(getChar(x+u, y+d) ~= " ")then
- return false
- end
- end
- end
- end
- return true
- end
- function drawBall()
- term.clear()
- term.setBackgroundColor(colors.orange)
- if(ball['size'] == 1)then
- term.setCursorPos(ball['drawx'], ball['drawy']);
- term.write(" ")
- elseif(ball['size'] == 2)then
- term.setCursorPos(ball['drawx'], ball['drawy']);
- term.write(" ")
- term.setCursorPos(ball['drawx'], ball['drawy']+1);
- term.write(" ")
- end
- term.setBackgroundColor(colors.black)
- end
- function drawMap()
- for id, data in pairs(levels['1']['map']) do
- for f = 1, #data do
- char = string.sub(data, f, f)
- term.setCursorPos(f-scroll['x'], id-scroll['y'])
- if(char == "#")then
- term.setBackgroundColor(colors.yellow)
- elseif(char == "B")then
- term.setBackgroundColor(colors.lightBlue)
- elseif(char == "S")then
- term.setBackgroundColor(colors.pink)
- elseif(char == "X")then
- term.setBackgroundColor(colors.red)
- end
- if(char ~= " ")then
- term.write(" ")
- end
- end
- end
- term.setBackgroundColor(colors.black)
- end
- function checkScroll()
- if(#levels['1']['map'] > h)then
- if(ball['drawx'] < 25)then
- if(scroll['x'] > 0)then
- scroll['x'] = scroll['x'] - 1
- ball['drawx'] = 25
- end
- else
- calc = scroll['x'] + (scroll['x'] - ball['drawx']) + (scroll['x']+w-ball['drawx']) + 2
- if(string.sub(levels['1']['map'][ball['drawy']], calc, calc) ~= "")then
- if(w-ball['drawx'] == 25)then
- scroll['x'] = scroll['x'] + 1
- ball['drawx'] = 25
- end
- end
- end
- end
- if(#levels['1']['map'] > h)then
- if(ball['drawy'] < 9)then
- if(scroll['y'] > 0)then
- scroll['y'] = scroll['y'] - 1
- ball['drawy'] = 9
- end
- else
- if(levels['1']['map'][ball['y']+10] ~= nil)then
- if(h-ball['drawy'] == 9)then
- scroll['y'] = scroll['y'] + 1
- ball['drawy'] = 9
- end
- end
- end
- end
- end
- function drawScreen()
- checkScroll()
- drawBall()
- drawMap()
- end
- drawScreen()
- while true do
- event, key = os.pullEvent("key")
- if key == 205 then
- if(canMove(ball['x']+1, ball['y'], ball['size']))then
- ball['x'] = ball['x'] + 1
- if(ball['x'] < 26)then
- ball['drawx'] = ball['x']
- else
- ball['drawx'] = ball['drawx'] + 1
- end
- end
- elseif key == 203 then
- if(canMove(ball['x']-1, ball['y'], ball['size']))then
- ball['x'] = ball['x'] - 1
- if(ball['x'] < 26)then
- ball['drawx'] = ball['x']
- else
- ball['drawx'] = ball['drawx'] - 1
- end
- end
- elseif key == 200 then
- if(canMove(ball['x'], ball['y']-1, ball['size']))then
- ball['y'] = ball['y'] - 1
- if(ball['y'] < 10)then
- ball['drawy'] = ball['y']
- else
- ball['drawy'] = ball['drawy'] - 1
- end
- end
- elseif key == 208 then
- if(canMove(ball['x'], ball['y']+1, ball['size']))then
- ball['y'] = ball['y'] + 1
- if(ball['y'] < 10)then
- ball['drawy'] = ball['y']
- else
- ball['drawy'] = ball['drawy'] + 1
- end
- end
- elseif key == 42 then
- if ball['size'] == 1 then
- if(canMove(ball['x'], ball['y'], ball['size']+1))then
- ball['size'] = 2
- end
- end
- elseif key == 29 then
- if ball['size'] == 2 then
- ball['size'] = 1
- end
- end
- drawScreen()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement