Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local c = require("component")
- local computer = require("computer")
- local math = require("math")
- local os = require("os")
- local event = require("event")
- local fs = require("filesystem")
- local serialization = require("serialization")
- local arc = {}
- --os.execute("resolution 124 48")
- local gpu = c.gpu
- local w, h = gpu.getResolution()
- x = w / 2
- y = h / 2
- dy = 1
- dx = 0
- --
- colorPlatforma = 321321
- colorShar = 123123
- N = 1
- mass = {}
- MN = 1
- function PutPixel(x, y, color, text)
- gpu.setBackground(color)
- gpu.set(x, y, text)
- gpu.setBackground(0)
- end
- function GameOver(_)
- computer.beep(20, 3)
- dy = 0 - dy
- gpu.setBackground(0)
- print("YOU LOSER")
- end
- function getKirpich(xk, yk, colorK)
- for i = 1, #mass - 1 do
- if mass[i][1] == math.floor(xk) and mass[i][2] == math.floor(yk) then
- gpu.setBackground(colorK)
- gpu.fill(mass[i][1], mass[i][2], mass[i][3], mass[i][4], " ")
- N = N + 1
- if n == #mass - 1 then
- GameOver(1)
- end
- end
- end
- end
- function printKirpich()
- for i = 1, #mass - 1 do
- gpu.setBackground(mass[i][5])
- gpu.fill(mass[i][1], mass[i][2], mass[i][3], mass[i][4], " ")
- end
- end
- function printPlatform()
- for i = 1, l do
- PutPixel(platformaS + i , h, colorPlatforma, " ")
- end
- end
- function platforma()
- event.listen("key_down", function(k1, k2, k3, k4) key = k4 end)
- if key == 203 and platformaS > 1 then
- PutPixel(platformaS + l, h, 0, " ")
- PutPixel(platformaS, h, colorPlatforma, " ")
- platformaS = platformaS - 1
- key = 0
- end
- if key == 205 and platformaS + l < w then
- PutPixel(platformaS, h, 0, " ")
- PutPixel(platformaS + l, h, colorPlatforma, " ")
- platformaS = platformaS + 1
- key = 0
- end
- event.ignore("key_down", function(k1, k2, k3, k4) end)
- os.sleep(1 / 20)
- end
- function test()
- if x < 3 or x > w - 2 then
- dx = 0 - dx
- end
- if y < 3 then
- dy = 0 - dy
- end
- if y < h - 5 then
- local char, foreColor, backColor = gpu.get(x + dx, y + dy)
- kx = x + dx
- ky = y + dy
- if backColor ~= 0 then
- char, foreColor, backColor1 = gpu.get(x + 1, y)
- char, foreColor, backColor2 = gpu.get(x - 1, y)
- char, foreColor, backColor3 = gpu.get(x, y + 1)
- char, foreColor, backColor4 = gpu.get(x, y - 1)
- if backColor1 ~= backColor and backColor2 ~= backColor then
- dy = 0 - dy
- end
- if backColor3 ~= backColor and backColor4 ~= backColor then
- dx = 0 - dx
- end
- char, foreColor, backColor5 = gpu.get(kx - 1, ky)
- while backColor5 == backColor and kx - 3 > 0 do
- char, foreColor, backColor5 = gpu.get(kx - 2, ky)
- kx = kx - 1
- end
- char, foreColor, backColor5 = gpu.get(kx, ky - 1)
- while backColor5 == backColor and ky - 3 > 0 do
- char, foreColor, backColor5 = gpu.get(kx, ky - 2)
- ky = ky - 1
- end
- getKirpich(kx, ky, 0)
- end
- end
- if y + dy > h or y + dy == h then
- if x < platformaS + 1 or x > platformaS + l + 1 then
- GameOver(1)
- else
- dy = 0 - dy
- dx = ((x % (platformaS + 1)) - l / 2) / l * 2 -- зависимость dx от места попадание на платформу игрок
- dy = 0 - math.sqrt(1 - dx * dx)
- end
- end
- end
- function shar()
- PutPixel(x, y, 0, " ")
- test()
- x = x + dx
- y = y + dy
- PutPixel(x, y, colorShar, " ")
- end
- function Game()
- while key ~= 28 do
- platforma()
- platforma()
- shar()
- end
- end
- function arc.GameStart(file)
- mass = serialization.unserialize(io.lines(file)())
- l = mass[#mass][1]
- platformaS = w / 2 - l / 2
- printKirpich()
- printPlatform()
- Game()
- end
- return arc
Advertisement
Add Comment
Please, Sign In to add comment