Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local c = require("component")
- local computer = require("computer")
- local gpu = c.gpu
- local event = require("event")
- local math = require("math")
- local w, h = gpu.getResolution()
- x = w - 4
- y = h - 4
- l = 16
- t = 0
- platformaS = w / 2 - l / 2 - 1 -- стартовая позиция платформ
- platformaS2 = platformaS -- платформа2 позиция старта
- platformaS1 = platformaS -- 1
- dy = -1 -- изменение положения шарика по у
- dx = 0 -- по х (вектор = 1)
- ez = 16 -- не знаю работает ли... в теории дает возможность двигаться платформе в 16 быстрее шара.
- colorPlatforma = 321321 -- цвет платформы
- colorShar = 123123 -- цвет шара
- function GameOver(player) -- конец игры(player = loser)
- computer.beep(20, 3)
- return 0
- end
- function PutPixel(x, y, color, text) -- люблю эту функцию, получает пиксель там где надо
- gpu.setBackground(color)
- gpu.set(x, y, text)
- gpu.setBackground(0)
- end
- function getPlatform() -- подготовка, рисует платформу
- for i = 0, l - 1 do
- PutPixel(platformaS + i , h, colorPlatforma, " ")
- PutPixel(platformaS + i , 1, colorPlatforma, " ")
- end
- 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()
- end
- function platforma() -- движение платформы - 205 = --> 203 = <-- 208 = <-- 200 = -->
- for i = 1, ez do
- event.listen("key_down", function(k1, k2, k3, k4) key = k4 end) -- подходит с трудом ибо если оба нажали работает у последнего
- if key == 203 and platformaS1 - 1 > 0 then --1 игрок
- PutPixel(platformaS1 + l - 1, h, 0, " ")
- PutPixel(platformaS1 - 1, h, colorPlatforma, " ")
- platformaS1 = platformaS1 - 1
- key = 0
- end
- if key == 205 and platformaS1 + l < w + 1 then
- PutPixel(platformaS1, h, 0, " ")
- PutPixel(platformaS1 + l, h, colorPlatforma, " ")
- platformaS1 = platformaS1 + 1
- key = 0
- end
- if key == 208 and platformaS2 + 1 > 0 then --2 игрок
- PutPixel(platformaS2 + l - 1, 1, 0, " ")
- PutPixel(platformaS2 - 1, 1, colorPlatforma, " ")
- platformaS2 = platformaS2 - 1
- key = 0
- end
- if key == 200 and platformaS2 + l < w + 1 then
- PutPixel(platformaS2, 1, 0, " ")
- PutPixel(platformaS2 + l, 1, colorPlatforma, " ")
- platformaS2 = platformaS2 + 1
- key = 0
- end
- os.sleep(0,05)
- end
- end
- function test() -- физика(нет) не работает. Если у шарика у < 1 то меняет направление несколько раз = не работает
- if 3 > x or x > w - 3 then
- dx = 0 - dx
- end
- if 3 > y or y > h - 2 then
- dy = 0 - dy
- end
- if t < 1 then
- if y == 2 then
- if x < platformaS2 or x > platformaS2 + l then
- GameOver(0)
- else
- dx = ((x % platformaS2) - l / 2) / l * 2 -- зависимость dx от места попадание на платформу игрок
- dy = 0 - math.sqrt(1 - dx * dx)
- end
- end
- if y == h - 1 then
- if x < platformaS1 or x > platformaS1 + l then
- GameOver(1)
- else
- dx = ((x % platformaS2) - l / 2) / l * 2 -- зависимость dx от места попадание на платформу игрок
- dy = 0 - math.sqrt(1 - dx * dx)
- t = 8
- end
- end
- end
- end
- function shar() --движение шара, надо переделать последовательность.
- PutPixel(x, y, 0, " ")
- x = x + dx
- y = y + dy
- test()
- PutPixel(x, y, colorShar, " ")
- end
- start()
- while key ~= 28 do -- конец игры если нажали enter
- shar()
- platforma()
- platforma() -- ez не работало сделал костыль безногому
- end
- gpu.setBackground(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement