Advertisement
TraerAlone

Untitled

Aug 20th, 2016
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local c = require("component")
  2. local computer = require("computer")
  3. local math = require("math")
  4. local event = require("event")
  5. local fs = require("filesystem")
  6. local serialization = require("serialization")
  7. local arc = {}
  8. local gpu = c.gpu
  9. local w, h = gpu.getResolution()
  10. x = w / 2
  11. y = h / 2
  12. dy = 1
  13. dx = 0
  14.  
  15. colorPlatforma = 321321
  16. colorShar = 123123
  17. N = 1
  18. mass = {}
  19. MN = 1
  20.  
  21. function PutPixel(x, y, color, text)
  22.   gpu.setBackground(color)
  23.   gpu.set(x, y, text)
  24.   gpu.setBackground(0)
  25. end
  26.  
  27. function GameOver(_)            
  28.   computer.beep(20, 3)
  29.   dy = 0 - dy
  30.   gpu.setBackground(0)
  31.   print("YOU LOSER")
  32. end
  33.  
  34. function getKirpich(i, m)
  35.   if mass[i][6] ~= 0 then
  36.     mass[i][6] = mass[i][6] - m
  37.     gpu.setBackground(mass[i][5] * mass[i][6] / 10)
  38.     gpu.fill(mass[i][1], mass[i][2], mass[i][3], mass[i][4], " ")
  39.     N = N + 1
  40.     if n == #mass - 1 then
  41.       GameOver(1)
  42.     end
  43.   end
  44. end
  45.  
  46.  
  47. function printKirpich()
  48.   for i = 1, #mass - 1 do
  49.     gpu.setBackground(mass[i][5])
  50.     gpu.fill(mass[i][1], mass[i][2], mass[i][3], mass[i][4], " ")
  51.   end
  52. end
  53.  
  54. function printPlatform()
  55.   for i = 1, l do
  56.     PutPixel(platformaS + i , h, colorPlatforma, " ")
  57.   end
  58. end
  59.  
  60. function platforma(k1, k2, k3, k4, k5)
  61.   if k4 == 203 and platformaS > 1 and k1 == "key_down" then
  62.     PutPixel(platformaS + l, h, 0, " ")
  63.     PutPixel(platformaS, h, colorPlatforma, " ")
  64.     platformaS = platformaS - 1
  65.     key = 0
  66.   end
  67.   if k4 == 205 and platformaS + l < w and k1 == "key_down" then
  68.     PutPixel(platformaS, h, 0, " ")
  69.     PutPixel(platformaS + l, h, colorPlatforma, " ")
  70.     platformaS = platformaS + 1
  71.     key = 0
  72.   end
  73.  
  74. end
  75.  
  76. function test()
  77.   if x < 3  or x > w - 2 then
  78.     dx = 0 - dx
  79.   end
  80.   if y < 3 then
  81.     dy = 0 - dy
  82.   end
  83.   for i = 1, #mass - 1 do
  84.     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
  85.       getKirpich(i, 1)
  86.       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
  87.         dx = 0 - dx
  88.       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
  89.         dy = 0 - dy
  90.       else
  91.         dx = 0 - dx
  92.         dy = 0 - dy
  93.       end
  94.     end
  95.   end
  96.   if y + dy > h or y + dy == h then
  97.     if x < platformaS + 1 or x > platformaS + l + 1 then
  98.       GameOver(1)
  99.     else
  100.       dy = 0 - dy
  101.       dx = (x % (platformaS + 1) - l / 2) / l * 2  -- зависимость dx от места попадание на платформу игрок
  102.       dy = 0 - math.sqrt(1 - dx * dx)
  103.       print(dx, x % (platformaS + 1))
  104.     end
  105.   end
  106. end
  107.  
  108. function shar()
  109.   PutPixel(x, y, 0, " ")
  110.   test()
  111.   x = x + dx
  112.   y = y + dy
  113.   PutPixel(x, y, colorShar, " ")
  114. end
  115.  
  116. function Game()
  117.   while not false do
  118.     shar()
  119.     os.sleep(1 / 20)
  120.   end
  121. end
  122.  
  123. function arc.GameStart(file)
  124.   mass = serialization.unserialize(io.lines(file)())
  125.   l = mass[#mass][1]
  126.   platformaS = w / 2 - l / 2 - 1
  127.   printKirpich()
  128.   printPlatform()
  129.   Game()
  130. end
  131.  
  132.  
  133. event.listen("key_down", platforma)
  134. event.listen("key_up", platforma)
  135. arc.GameStart("../test")
  136. event.ignore("key_down", platforma)
  137. event.ignore("key_up", platforma)
  138.  
  139. --return arc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement