View difference between Paste ID: Pg8edkzJ and SAWJSCim
SHOW: | | - or go back to the newest paste.
1-
local c = require("component")
1+
local c = require("component")
2-
local gpu = c.gpu
2+
local computer = require("computer")
3-
local event = require("event")
3+
local math = require("math")
4-
local w, h = gpu.getResolution()
4+
--local os = require("os")
5-
5+
local event = require("event")
6-
x = 10
6+
os.execute("resolution 124 48")
7-
y = 10
7+
local gpu = c.gpu
8-
dy = 1
8+
local w, h = gpu.getResolution()
9-
dx = 1
9+
x = w / 2                            -- шарик
10-
l = 2 -- только чет пока
10+
y = h / 2                            --
11-
s = w /2 - l /2
11+
dy = 1
12-
12+
dx = 0
13-
function PutPixel(x, y, color, text)
13+
l = 32                               --длина платформы в пикселях
14-
  gpu.setBackground(color)
14+
platformaS = w / 2 - l / 2
15-
  gpu.set(x, y, text)
15+
kirpichNX = 6                        --кол-во кирпичей
16-
  gpu.set(x - 1, y, text)
16+
kirpichNY = 4 
17
PBTkir = 0                           --расстояние между кирпичами
18-
18+
heightKirpich = 2                    
19-
for i = 1, l + 1 do
19+
widthKirpich = 10                    --размер кирпича
20-
PutPixel(s+i, h, 321321, "X") 
20+
strengthKirpich = 321321             --не рабочий стафф
21
colorPlatforma = 321321              --цвет платформы
22-
22+
colorShar = 123123                   --цвет шарика
23-
for i = 1, 100 do
23+
24-
event.listen("key_down", function(k1, k2, k3, k4) key1 = k4 end)
24+
function PutPixel(x, y, color, text)  --просто удобная штука. мне так проще
25-
if key1 == 203 and s > 2 then
25+
  gpu.setBackground(color)
26-
  PutPixel(s + l + 2, h, 0, " ")
26+
  gpu.set(x, y, text)
27-
  PutPixel(s, h, 321321, "Y")
27+
  gpu.setBackground(0)
28-
  s = s - 1
28+
end
29
30-
30+
function getKirpich(xk, yk, colorK)  --рисуем кирпич
31-
--gpu.setBackground(0)
31+
  gpu.setBackground(colorK)
32-
--gpu.fill(1, 1, w, h, " ")
32+
  gpu.fill(xk, yk, widthKirpich, heightKirpich, " ")
33-
PutPixel(x, y, 0, " ")
33+
end
34-
x = x + dx
34+
35-
y = y + dy
35+
function printKirpich()              --рисуем кирпичи
36-
if 2 < x and x < w then
36+
  for i1 = 0, kirpichNX - 1 do
37-
else
37+
    for i2 = 0, kirpichNY - 1 do
38-
dx = 0 - dx
38+
      getKirpich(PBTkir + (widthKirpich + PBTkir) * i1 + 2, PBTkir + (heightKirpich + PBTkir) * i2 + 2, math.random() * 1000000)
39
    end
40-
if 1 < y and y < h - 1 then
40+
  end
41-
else
41+
end
42-
dy = 0 - dy
42+
43
function getPlatform()               --рисуем платформу
44-
PutPixel(x, y, 123123, " ")
44+
  for i = 1, l do
45-
os.sleep(0.2)
45+
    PutPixel(platformaS + i , h, colorPlatforma, " ") 
46
  end
47-
gpu.setBackground(0)
47+
end
48
49
function GameOver(reason)            --ну тут понятно гейм овер
50
  computer.beep(20, 3)
51
  dy = 0 - dy
52
  gpu.setBackground(0)
53
  computer.shutdown()
54
end
55
56
function start()                     --стартует игра и вызывает всякие функции для отрисовки всего
57
  gpu.setBackground(0) 
58
  gpu.fill(1, 1, w, h, " ")
59
  PutPixel(w / 2 - 6, h / 2 - 6, 777777, "Hello World")
60
  os.sleep(1)
61
  gpu.fill(1, 1, w, h, " ")
62
  getPlatform()
63
  printKirpich()
64
end
65
66
function platforma()                 --платформа едет
67
  event.listen("key_down", function(k1, k2, k3, k4) key = k4 end)
68
  if key == 203 and platformaS > 1 then
69
    PutPixel(platformaS + l, h, 0, " ")
70
    PutPixel(platformaS, h, colorPlatforma, " ")
71
    platformaS = platformaS - 1
72
    key = 0
73
  end
74
  if key == 205 and platformaS + l < w - 2 then
75
    PutPixel(platformaS, h, 0, " ")
76
    PutPixel(platformaS + l, h, colorPlatforma, " ")
77
    platformaS = platformaS + 1
78
    key = 0
79
  end
80
  event.ignore("key_down", function(k1, k2, k3, k4) end)
81
  os.sleep(1 / 20)
82
end
83
84
function test()                      --проверка всего
85
  if x < 3  or x > w - 2 then        --отражение от границ экрана
86
    dx = 0 - dx
87
  end
88
  if y < 3 then                      --см верх
89
    dy = 0 - dy
90
  end
91
  if y < h - 5 then                  --определение отражение от кирпичей
92
    local char, foreColor, backColor = gpu.get(x + dx, y + dy)
93
    kx = x + dx
94
    ky = y + dy
95
    if backColor ~= 0 then
96
      char, foreColor, backColor1 = gpu.get(x + 1, y)
97
      char, foreColor, backColor2 = gpu.get(x - 1, y)
98
      char, foreColor, backColor3 = gpu.get(x, y + 1)
99
      char, foreColor, backColor4 = gpu.get(x, y - 1)
100
      if backColor1 ~= backColor and backColor2 ~= backColor then
101
        dy = 0 - dy
102
      end
103
      if backColor3 ~= backColor and backColor4 ~= backColor then
104
        dx = 0 - dx
105
      end
106
      char, foreColor, backColor5 = gpu.get(kx - 1, ky)
107
      while backColor5 == backColor and kx - 2 > 0 do
108
        char, foreColor, backColor5 = gpu.get(kx - 2, ky)
109
        kx = kx - 1
110
      end
111
      char, foreColor, backColor5 = gpu.get(kx, ky - 1)
112
      while backColor5 == backColor and ky - 2 > 0 do
113
        char, foreColor, backColor5 = gpu.get(kx, ky - 2)
114
        ky = ky - 1
115
      end
116
      getKirpich(kx, ky, 0)         --удаляет киприч
117
    end
118
  end
119
  if y + dy > h or y + dy == h then --отражение шарика от платформы
120
    if x < platformaS + 1 or x > platformaS + l + 1 then
121
      GameOver(1)
122
    else
123
      dy = 0 - dy
124
      dx = ((x % (platformaS + 1)) - l / 2) / l * 2  --зависимость dx от места попадание на платформу игрок, надо доработать
125
      dy = 0 - math.sqrt(1 - dx * dx)
126
    end
127
  end
128
end
129
130
function shar()                                      --полет шарика
131
  PutPixel(x, y, 0, " ")
132
  test()
133
  x = x + dx
134
  y = y + dy
135
  PutPixel(x, y, colorShar, " ")
136
end
137
138
start()                                             --старт игры
139
while key ~= 28 do
140
  platforma()
141
  platforma()
142
  shar()
143
end