Advertisement
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")
- os.execute("resolution 124 48")
- local gpu = c.gpu
- local w, h = gpu.getResolution()
- x = w / 2 -- шарик
- y = h / 2 --
- dy = 1
- dx = 0
- l = 32 --длина платформы в пикселях
- platformaS = w / 2 - l / 2
- kirpichNX = 6 --кол-во кирпичей
- kirpichNY = 4
- PBTkir = 0 --расстояние между кирпичами
- heightKirpich = 2
- widthKirpich = 10 --размер кирпича
- strengthKirpich = 321321 --не рабочий стафф
- colorPlatforma = 321321 --цвет платформы
- colorShar = 123123 --цвет шарика
- function PutPixel(x, y, color, text) --просто удобная штука. мне так проще
- gpu.setBackground(color)
- gpu.set(x, y, text)
- gpu.setBackground(0)
- end
- function getKirpich(xk, yk, colorK) --рисуем кирпич
- gpu.setBackground(colorK)
- gpu.fill(xk, yk, widthKirpich, heightKirpich, " ")
- end
- function printKirpich() --рисуем кирпичи
- for i1 = 0, kirpichNX - 1 do
- for i2 = 0, kirpichNY - 1 do
- getKirpich(PBTkir + (widthKirpich + PBTkir) * i1 + 2, PBTkir + (heightKirpich + PBTkir) * i2 + 2, math.random() * 1000000)
- end
- end
- end
- function getPlatform() --рисуем платформу
- for i = 1, l do
- PutPixel(platformaS + i , h, colorPlatforma, " ")
- end
- end
- function GameOver(reason) --ну тут понятно гейм овер
- computer.beep(20, 3)
- dy = 0 - dy
- gpu.setBackground(0)
- computer.shutdown()
- end
- function start() --стартует игра и вызывает всякие функции для отрисовки всего
- gpu.setBackground(0)
- gpu.fill(1, 1, w, h, " ")
- PutPixel(w / 2 - 6, h / 2 - 6, 777777, "Hello World")
- os.sleep(1)
- gpu.fill(1, 1, w, h, " ")
- getPlatform()
- printKirpich()
- 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 - 2 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 - 2 > 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 - 2 > 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
- start() --старт игры
- while key ~= 28 do
- platforma()
- platforma()
- shar()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement