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 event = require("event")
- local fs = require("filesystem")
- local serialization = require("serialization")
- local arc = {}
- 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(i, m)
- if mass[i][6] ~= 0 then
- mass[i][6] = mass[i][6] - m
- gpu.setBackground(mass[i][5] * mass[i][6] / 10)
- 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
- 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(k1, k2, k3, k4, k5)
- if k4 == 203 and platformaS > 1 and k1 == "key_down" then
- PutPixel(platformaS + l, h, 0, " ")
- PutPixel(platformaS, h, colorPlatforma, " ")
- platformaS = platformaS - 1
- key = 0
- end
- if k4 == 205 and platformaS + l < w and k1 == "key_down" then
- PutPixel(platformaS, h, 0, " ")
- PutPixel(platformaS + l, h, colorPlatforma, " ")
- platformaS = platformaS + 1
- key = 0
- end
- end
- function test()
- if x < 3 or x > w - 2 then
- dx = 0 - dx
- end
- if y < 3 then
- dy = 0 - dy
- end
- for i = 1, #mass - 1 do
- if mass[i][1] < x + dx and mass[i][2] < y + dy and mass[i][1] + mass[i][3] > x + dx and mass[i][2] + mass[i][4] > y + dy and mass[i][6] ~= 0 then
- getKirpich(i, 1)
- if mass[i][1] < x + dx and mass[i][2] < y and mass[i][1] + mass[i][3] > x + dx and mass[i][2] + mass[i][4] > y then
- dx = 0 - dx
- elseif mass[i][1] < x and mass[i][2] < y + dy and mass[i][1] + mass[i][3] > x and mass[i][2] + mass[i][4] > y + dy then
- dy = 0 - dy
- else
- dx = 0 - dx
- dy = 0 - dy
- end
- 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)
- print(dx, x % (platformaS + 1))
- end
- end
- end
- function shar()
- PutPixel(x, y, 0, " ")
- test()
- x = x + dx
- y = y + dy
- PutPixel(x, y, colorShar, " ")
- end
- function Game()
- while not false do
- shar()
- os.sleep(1 / 20)
- end
- end
- function arc.GameStart(file)
- mass = serialization.unserialize(io.lines(file)())
- l = mass[#mass][1]
- platformaS = w / 2 - l / 2 - 1
- printKirpich()
- printPlatform()
- Game()
- end
- event.listen("key_down", platforma)
- event.listen("key_up", platforma)
- arc.GameStart("../test")
- event.ignore("key_down", platforma)
- event.ignore("key_up", platforma)
- --return arc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement