Guest User

Untitled

a guest
Feb 21st, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 24.80 KB | None | 0 0
  1. local F, C = unpack(Aurora)
  2.  
  3. local INC_SPEED, START_SPEED = 0, .5
  4. local scale, space = 20, 20
  5. local stop, isPause, figure, gorizont, ind, nextFigure, speed, panespeed = true, false, 0, false, 0, nil, START_SPEED, .1
  6. local VYY,VYX,YY,XX,OXX,OYY = {},{},{},{},{},{}
  7.  
  8. local fcolors = {
  9.    {1,0,0,1},
  10.    {1,1,0,1},
  11.    {1,1,1,1},
  12.    {1,0,1,1},
  13.    {0,0,1,1},
  14.    {0,1,1,1},
  15.    {0,1,0,1},
  16. }
  17.  
  18. local Flash = function(self, duration)
  19.    if not self.anim then
  20.       self.anim = self:CreateAnimationGroup("Flash")
  21.       self.anim.fadein = self.anim:CreateAnimation("ALPHA", "FadeIn")
  22.       self.anim.fadein:SetChange(1)
  23.       self.anim.fadein:SetOrder(2)
  24.  
  25.       self.anim.fadeout = self.anim:CreateAnimation("ALPHA", "FadeOut")
  26.       self.anim.fadeout:SetChange(-1)
  27.       self.anim.fadeout:SetOrder(1)
  28.    end
  29.  
  30.    self.anim.fadein:SetDuration(duration)
  31.    self.anim.fadeout:SetDuration(duration)
  32.    self.anim:Play()
  33. end
  34.  
  35.    -- îïèñûâàåì ìàòðèöó 10*20
  36. local texture = {}
  37. for i=1,20 do tinsert(texture, {0,0,0,0,0,0,0,0,0,0}) end
  38. local nexttexture = {}
  39. for i=1,4 do tinsert(nexttexture, {0,0,0,0}) end
  40.    
  41. local mainWnd = CreateFrame("button", "GameTetrisFrame", UIParent)
  42. mainWnd:SetWidth(10*scale + space*2)
  43. mainWnd:SetHeight(20*scale + space*4)
  44. mainWnd:SetPoint("CENTER")
  45.  
  46. mainWnd:EnableMouse(true)
  47. mainWnd:SetMovable(true)
  48. mainWnd:SetUserPlaced(true)
  49. mainWnd:SetClampedToScreen(true)
  50. mainWnd:SetScript("OnMouseDown", function(self) self:StartMoving() end)
  51. mainWnd:SetScript("OnMouseUp", function(self) self:StopMovingOrSizing() end)
  52.    
  53. mainWnd:SetBackdrop({
  54.         bgFile = C.media.backdrop,
  55.         edgeFile = C.media.backdrop,
  56.         tileSize = 64,
  57.         edgeSize = 1,
  58.         insets ={left =1, right =1, top =1, bottom =1},
  59.    })
  60. mainWnd:SetBackdropColor(.0, .0, .0, .5)
  61. mainWnd:SetBackdropBorderColor(0,0,0,1)
  62. mainWnd:Hide()
  63.  
  64. local title = mainWnd:CreateFontString(nil, "OVERLAY")
  65. title:SetFont("Interface\\AddOns\\Stuff\\media\\fonts\\semplice.ttf", 8, "OUTLINEMONOCHROME")
  66. title:SetPoint("TOPLEFT", space/2, -space/2)
  67. title:SetText("Tetris")
  68.  
  69. local gamePane = CreateFrame("frame", nil, mainWnd)
  70. gamePane:SetPoint("TOPLEFT", space, -space-10)
  71. gamePane:SetPoint("BOTTOMRIGHT", mainWnd, "BOTTOMRIGHT", -space, space*3)
  72.  
  73. gamePane:SetBackdrop({
  74.         edgeFile = "Interface\\Buttons\\WHITE8x8",
  75.         tile = false,
  76.         tileSize = 0,
  77.         edgeSize = 1,
  78.         insets = {left =0, right =0, top =0, bottom =0},
  79.    })
  80. gamePane:SetBackdropBorderColor(0, 0, 0, 1)
  81.  
  82. local gamePaneNext = CreateFrame("frame", nil, mainWnd)
  83. gamePaneNext:SetPoint("TOPLEFT", gamePane, 4,-4)
  84. gamePaneNext:SetWidth(space*2)
  85. gamePaneNext:SetHeight(space*2)
  86. gamePaneNext:SetAlpha(.4)
  87.  
  88. local gptex = gamePane:CreateTexture(nil, "BACKGROUND")
  89. gptex:SetAllPoints(gamePane)
  90. gptex:SetTexture(C.media.backdrop)
  91. gptex:SetTexCoord(.3,.7,.3,.7)
  92. gptex:SetVertexColor(0,0,0,.5)
  93.  
  94. local gameMsg = gamePane:CreateFontString(nil, "OVERLAY")
  95. gameMsg:SetFont("Interface\\AddOns\\Stuff\\media\\fonts\\semplice.ttf", 8, "OUTLINEMONOCHROME")
  96. gameMsg:SetShadowOffset(0,0)
  97. gameMsg:SetPoint("CENTER")
  98.  
  99. UpdatePane = function(self, elapsed)
  100.    if self.ts == nil then self.ts = 0 end
  101.    self.ts = self.ts + elapsed
  102.    if (self.ts >= panespeed) then
  103.       for j = 1,20 do
  104.          for i = 1,10 do
  105.             if (texture[j][i].visible) then
  106.                texture[j][i]:SetVertexColor(unpack(texture[j][i].color))
  107.             else
  108.                texture[j][i]:SetVertexColor(1,1,1,0)
  109.             end
  110.          end
  111.       end
  112.  
  113.       for j = 1,4 do
  114.          for i = 1,4 do
  115.             if (nexttexture[j][i].visible) then
  116.                nexttexture[j][i]:SetVertexColor(unpack(nexttexture[j][i].color))
  117.             else
  118.                nexttexture[j][i]:SetVertexColor(1,1,1,0)
  119.             end
  120.          end
  121.       end
  122.      
  123.       self.ts = 0
  124.    end
  125. end
  126.  
  127. local score = mainWnd:CreateFontString(nil, "OVERLAY", "GameFontNormal")
  128. score:SetFont("Interface\\AddOns\\Stuff\\media\\fonts\\semplice.ttf", 8, "OUTLINEMONOCHROME")
  129. score:SetShadowOffset(0,0)
  130. score:SetPoint("TOPLEFT", gamePane,"BOTTOMLEFT", 0, -space/2)
  131. score:SetText("Score: 0")
  132.  
  133. local checkstr = mainWnd:CreateFontString(nil, "OVERLAY", "GameFontNormal")
  134. checkstr:SetFont("Interface\\AddOns\\Stuff\\media\\fonts\\semplice.ttf", 8, "OUTLINEMONOCHROME")
  135. checkstr:SetShadowOffset(0,0)
  136. checkstr:SetText("|cff00ff66Zombie|r mode")
  137. checkstr:SetPoint("TOPLEFT", score, "BOTTOMLEFT", 0, -space/2)
  138.  
  139. local checkbox1 = CreateFrame("CheckButton", "$parent_cb1", mainWnd, "OptionsCheckButtonTemplate")
  140. checkbox1:SetPoint("LEFT", checkstr, "RIGHT", 5, 0)
  141. checkbox1:SetWidth(18)
  142. checkbox1:SetHeight(18)
  143. checkbox1:SetScript("OnClick", function() zombieMode = not zombieMode end)
  144. checkbox1:SetChecked(zombieMode)
  145.  
  146. local playButton = CreateFrame("button", "playButton", mainWnd, "UIPanelButtonTemplate")
  147. local pauseButton = CreateFrame("button", "pauseButton", mainWnd, "UIPanelButtonTemplate")
  148. playButton:SetWidth(50)
  149. playButton:SetHeight(22)
  150. playButton:SetPoint("BOTTOMRIGHT", -space, space)
  151. playButton:SetText("Play")
  152. playButton:SetScript("OnClick", function(self)
  153.    str=0
  154.    score:SetText("Score: "..str)
  155.    stop = not stop
  156.    isPause = false
  157.    gameMsg:SetText("")
  158.  
  159.    if stop then
  160.       checkbox1:Enable()
  161.       self:SetText("Play")
  162.  
  163.       gptex:SetTexture(C.media.backdrop)
  164.      
  165.       for j = 1,20 do
  166.          for i = 1,10 do
  167.             texture[j][i]:SetVertexColor(1,1,1,0)
  168.          end
  169.       end
  170.  
  171.       -- çàïóñê òàéìåðà, êàæäûå 500 ìèëëèñåêóíä áóäåò äâèãàòñÿ ôèãóðà
  172.       mainWnd:SetScript("OnUpdate", nil)
  173.       mainWnd:SetScript("OnKeyDown", nil)
  174.       mainWnd:EnableKeyboard(false)
  175.       gamePane:SetScript("OnUpdate", nil)
  176.       pauseButton:Disable()
  177.       StopMusic()
  178.    else
  179.       checkbox1:Disable()
  180.       self:SetText("Stop")
  181.       for j = 1,20 do
  182.          for i = 1,10 do
  183.             texture[j][i].visible = false
  184.             texture[j][i].color = {0,0,0,0}
  185.          end
  186.       end
  187.            
  188.       -- ñîçäàåì íîâóþ ôèãóðó
  189.       NewFigure()
  190.      
  191.       -- êàæäûå 500 ìèëëèñåêóíä áóäåò äâèãàòñÿ ôèãóðà
  192.       mainWnd:SetScript("OnUpdate", OnUpdateGame)
  193.       mainWnd:EnableKeyboard(true)
  194.       mainWnd:SetScript("OnKeyDown", OnKeyDown)
  195.  
  196.       gamePane:SetScript("OnUpdate", UpdatePane)
  197.       pauseButton:Enable()
  198.    end
  199. end)
  200.  
  201. pauseButton:SetWidth(50)
  202. pauseButton:SetHeight(22)
  203. pauseButton:SetPoint("RIGHT", playButton, "LEFT", -5, 0)
  204. pauseButton:SetText("Pause")
  205. pauseButton:Disable()
  206. pauseButton:SetScript("OnClick", function(self)
  207.    if isPause then
  208.       isPause = false
  209.       gameMsg:SetText("")
  210.       mainWnd:EnableKeyboard(true)
  211.       self:SetText("Pause")
  212.    else
  213.       isPause = true
  214.       gameMsg:SetTextColor(1,1,0)
  215.       gameMsg:SetText("Pause")
  216.       mainWnd:EnableKeyboard(false)
  217.       self:SetText("Resume")
  218.    end
  219. end)
  220.  
  221. local CloseButton = CreateFrame("button", "tetriscloseButton", mainWnd, "UIPanelCloseButton")
  222. CloseButton:SetPoint("TOPRIGHT", mainWnd, "TOPRIGHT", 0, 0)
  223. CloseButton:SetScript("OnClick", function()
  224.    isPause = true
  225.    gameMsg:SetTextColor(1,1,0)
  226.    gameMsg:SetText("Pause")
  227.    pauseButton:SetText("Resume")
  228.    mainWnd:Hide()
  229. end)
  230.  
  231.  
  232. local DrawFigure = function(visible, color)
  233.    if visible then
  234.       for i=1,4 do
  235.          texture[YY[i]][XX[i]].visible = true
  236.          texture[YY[i]][XX[i]].color = color
  237.       end
  238.    else
  239.       for i=1,4 do
  240.          texture[YY[i]][XX[i]].visible = false
  241.          texture[YY[i]][XX[i]].color = {0,0,0,0}
  242.       end
  243.    end
  244. end
  245.  
  246. InitTetris = function()
  247.    local x,y = gamePane:GetWidth()/10, gamePane:GetHeight()/20
  248.    
  249.    for j = 1,20 do
  250.       for i = 1,10 do
  251.          local t = _G["brick"..i.."_"..j] or gamePane:CreateTexture("brick"..i.."_"..j, "ARTWORK")
  252.          t:SetTexture("Interface\\Buttons\\WHITE8x8")
  253.          t:SetPoint("TOPLEFT", gamePane, "TOPLEFT", x*i-x, -y*j+y)
  254.          t:SetWidth(x-1)
  255.          t:SetHeight(y-1)
  256.          texture[j][i]=t
  257.       end
  258.    end
  259.  
  260.    x,y = gamePaneNext:GetWidth()/4, gamePaneNext:GetHeight()/4
  261.    for j = 1,4 do
  262.       for i = 1,4 do
  263.          local t = _G["brickn"..i.."_"..j] or gamePaneNext:CreateTexture("brickn"..i.."_"..j, "ARTWORK")
  264.          t:SetTexture("Interface\\Buttons\\WHITE8x8")
  265.          t:SetPoint("TOPLEFT", gamePaneNext, "TOPLEFT", x*i-x, -y*j+y)
  266.          t:SetWidth(x-1)
  267.          t:SetHeight(y-1)
  268.          nexttexture[j][i]=t
  269.       end
  270.    end
  271.    
  272. end
  273.  
  274. OnUpdateGame = function(self, elapsed)
  275.    if self.ts == nil then self.ts = 0 end
  276.    self.ts = self.ts + elapsed
  277.    if (self.ts >= speed) then
  278.    
  279.    if isPause then return end
  280.    
  281.       if stop==true then
  282.          mainWnd:SetScript("OnUpdate", nil)
  283.          mainWnd:SetScript("OnKeyDown", nil)
  284.          gamePane:SetScript("OnUpdate", nil)
  285.          mainWnd:EnableKeyboard(false)
  286.          return
  287.       else
  288.          
  289.          local col = texture[YY[1]][XX[1]].color
  290.          -- ñòèðàåì ôèãóðó
  291.          DrawFigure(false)
  292.          -- äåëàåì ñëåäóþùèé øàã
  293.          for i=1,4 do
  294.             YY[i]=YY[i]+1
  295.          end
  296.          
  297.          -- åñëè ôèãóðà ïåðåñåêàåòñÿ õîòü ñ îäíèì âèäèìûì êâàäðàòîì òî îñòàíàâëèâàåì åå è ñîçäàåì íîâóþ ôèãóðó
  298.          if texture[YY[1]][XX[1]].visible == true or texture[YY[2]][XX[2]].visible == true or texture[YY[3]][XX[3]].visible == true or texture[YY[4]][XX[4]].visible == true then
  299.             speed = START_SPEED
  300.             panespeed = .1
  301.            
  302.             for i=1,4 do
  303.                YY[i]=YY[i]-1
  304.             end
  305.          
  306.             DrawFigure(true, col)
  307.            
  308.             NewFigure()
  309.          else
  310.             DrawFigure(true, col)
  311.          end
  312.  
  313.          
  314.          -- åñëè õîòü îäèí êâàäðàò ïðèáëèçèëñÿ ê íèæíåé ãðàíèöå îñòàíàâëèâàåì åãî è ñîçäàåì íîâóþ ôèãóðó
  315.          for i=1,4 do
  316.             if YY[i]>19 then
  317.                speed = START_SPEED
  318.                panespeed = .1
  319.                NewFigure()
  320.                break
  321.             end
  322.          end
  323.       end
  324.      
  325.       self.ts = 0
  326.    end
  327. end
  328.  
  329. OnKeyDown = function(self, tetriskey, ...)
  330.  
  331.    if GetBindingFromClick(tetriskey) == "SCREENSHOT" then
  332.       RunBinding("SCREENSHOT")
  333.       return
  334.    elseif GetBindingFromClick(tetriskey) == "ESCAPE" then
  335.       RunBinding("ESCAPE")
  336.       return
  337.    end
  338.    
  339.    if tetriskey == "UNKNOWN" then
  340.       return
  341.    end
  342.    
  343.    local col = texture[YY[1]][XX[1]].color
  344.    if tetriskey=="LEFT" then
  345.       DrawFigure(false)
  346.       --ïðîâåðÿåì ãðàíèöó ñòàêàíà (1 êâàäðàòèê â ôèãóðå âñåãäà êðàéíèé ñëåâà)
  347.       if XX[1]~=1 then
  348.          if texture[YY[1]][XX[1]-1].visible == true or texture[YY[2]][XX[2]-1].visible == true or texture[YY[3]][XX[3]-1].visible == true or texture[YY[4]][XX[4]-1].visible == true then
  349.             -- ïðîâåðÿåì ñòîëêíîâåíèÿ ñëåâà
  350.          else
  351.             XX[1]=XX[1]-1
  352.             XX[2]=XX[2]-1
  353.             XX[3]=XX[3]-1
  354.             XX[4]=XX[4]-1
  355.          end
  356.       end
  357.  
  358.       DrawFigure(true, col)
  359.    elseif tetriskey=="RIGHT" then
  360.       DrawFigure(false)
  361.       --ïðîâåðÿåì ãðàíèöó ñòàêàíà (4 êâàäðàòèê â ôèãóðå âñåãäà êðàéíèé ñïðàâà)
  362.       if XX[4]~=10 then
  363.          if texture[YY[1]][XX[1]+1].visible == true or texture[YY[2]][XX[2]+1].visible == true or texture[YY[3]][XX[3]+1].visible == true or texture[YY[4]][XX[4]+1].visible == true then
  364.             -- ïðîâåðÿåì ñòîëêíîâåíèÿ ñïðàâà
  365.          else
  366.             XX[1]=XX[1]+1
  367.             XX[2]=XX[2]+1
  368.             XX[3]=XX[3]+1
  369.             XX[4]=XX[4]+1
  370.          end
  371.       end
  372.  
  373.       DrawFigure(true, col)
  374.      
  375.    elseif tetriskey == "UP" then
  376.       RotateFigure()
  377.      
  378.    elseif tetriskey=="DOWN" then
  379.       DrawFigure(false)
  380.      
  381.       --ïðîâåðÿåì íèæíþþ ãðàíèöó ñòàêàíà
  382.       if (YY[1]>18) or (YY[2]>18) or (YY[3]>18) or (YY[4]>18) then
  383.          -- ïîñëå 18 êëåòêè áûñòðûé ñïóñê íå ðàáîòàåò
  384.       else
  385.          YY[1]=YY[1]+1
  386.          YY[2]=YY[2]+1
  387.          YY[3]=YY[3]+1
  388.          YY[4]=YY[4]+1
  389.       end
  390.      
  391.       -- ïðîâåðÿåì íå âñòðåòèëîñü ëè ïðåïÿòñòâèå
  392.       if texture[YY[1]][XX[1]].visible == true or texture[YY[2]][XX[2]].visible == true or texture[YY[3]][XX[3]].visible == true or texture[YY[4]][XX[4]].visible == true then
  393.          -- åñëè âñòðåòèëîñü âîçâðàùàåì êîîðäèíàòû îáðàòíî  
  394.          YY[1]=YY[1]-1
  395.          YY[2]=YY[2]-1
  396.          YY[3]=YY[3]-1
  397.          YY[4]=YY[4]-1
  398.       end
  399.       -- ïðîðèñîâûâàåì ôèãóðó
  400.       DrawFigure(true, col)
  401.      
  402.    elseif tetriskey == "SPACE" then
  403.       speed = .01
  404.       panespeed = speed
  405.    else
  406.       return
  407.    end -- tetriskey
  408. end
  409.  
  410. GameOverCheck = function()
  411.    -- åñëè ôèãóðà ïåðåñåêàåòñÿ õîòü ñ îäíèì âèäèìûì êâàäðàòîì òî îñòàíàâëèâàåì èãðó
  412.    if texture[YY[1]][XX[1]].visible == true or texture[YY[2]][XX[2]].visible == true or texture[YY[3]][XX[3]].visible == true or texture[YY[4]][XX[4]].visible == true then
  413.       stop = true
  414.  
  415.       gameMsg:SetTextColor(1,0,0)
  416.       gameMsg:SetText("Game over!")
  417.       playButton:SetText("Play")
  418.    end
  419. end
  420.  
  421. NewFigure = function()
  422.    local isFilled = 0
  423.    if not nextFigure then nextFigure = math.random(1,7) end
  424.    
  425.    figure = nextFigure
  426.    
  427.    nextFigure = math.random(1,7)
  428.  
  429.    -- óêàçàòåëü ïîëîæåíèÿ â ìàòðèöå
  430.    local ii, jj = 5, 1
  431.    local jj1, ii1, jj2, ii2, jj3, ii3, jj4, ii4 = 0, 0, 0, 0, 0, 0, 0, 0
  432.    local filled = 0
  433.    
  434.    local shapes = {
  435.       { -- êâàäðàò
  436.          {1,1,0,0},
  437.          {1,1,0,0},
  438.          {0,0,0,0},
  439.          {0,0,0,0},
  440.       },
  441.       { -- ëèíèÿ
  442.          {1,1,1,1},
  443.          {0,0,0,0},
  444.          {0,0,0,0},
  445.          {0,0,0,0},
  446.       },
  447.       { -- ò-îáðàçàíàÿ
  448.          {1,1,1,0},
  449.          {0,1,0,0},
  450.          {0,0,0,0},
  451.          {0,0,0,0},
  452.       },
  453.       { -- L-îáðàçíàÿ ëåâàÿ
  454.          {0,1,0,0},
  455.          {0,1,0,0},
  456.          {0,1,1,0},
  457.          {0,0,0,0},
  458.       },
  459.       { -- L-îáðàçíàÿ ïðàâàÿ
  460.          {0,1,0,0},
  461.          {0,1,0,0},
  462.          {1,1,0,0},
  463.          {0,0,0,0},
  464.       },
  465.       { -- s-îáðàçíàÿ ëåâàÿ
  466.          {1,1,0,0},
  467.          {0,1,1,0},
  468.          {0,0,0,0},
  469.          {0,0,0,0},
  470.       },
  471.       { -- s-îáðàçíàÿ ïðàâàÿ
  472.          {0,1,1,0},
  473.          {1,1,0,0},
  474.          {0,0,0,0},
  475.          {0,0,0,0},
  476.       },
  477.    }
  478.  
  479.    -- ïðîâåðêà íà çàïîëíåíîñòü ëèíèè
  480.    for j=1,20 do
  481.       for i=1,10 do
  482.          if texture[j][i].visible == true then
  483.             filled = filled + 1
  484.          end
  485.          if filled == 10 then  -- åñëè çàïîëíåíû âñå 10 ÿ÷ååê, òî ñìåùàåì âåðõíþþ ÷àñòü òàáëèöû âíèç
  486.             for k=1,10 do
  487.                Flash(texture[j][k], 0.1)
  488.             end
  489.             isFilled = isFilled + 1
  490.             if isFilled > 1 then
  491.                str=str+(2*isFilled)
  492.                end
  493.             else
  494.                str=str+1
  495.             end
  496.             -- ðèñóåì â íàäïèñè êîëè÷åñòâî íàáðàííûõ î÷êîâ
  497.             score:SetText("Score: "..str)
  498.             for kj=2,j do
  499.                for ki=1,10 do
  500.                   texture[j-kj+2][ki].visible=texture[j-kj+1][ki].visible
  501.                   texture[j-kj+2][ki].color=texture[j-kj+1][ki].color
  502.                end
  503.             end
  504.          end
  505.       end
  506.       filled=0
  507.    end
  508.  
  509.    --êâàäðàò
  510.    if figure == 1 then
  511.       -- âêëþ÷àåì êâàäðàòû òàì ãäå îíè âèäèìû
  512.       jj1=jj
  513.       ii1=ii
  514.       jj2=jj
  515.       ii2=ii+1
  516.       jj3=jj+1
  517.       ii3=ii
  518.       jj4=jj+1
  519.       ii4=ii+1
  520.       YY={jj,jj,jj+1,jj+1}
  521.       XX={ii,ii+1,ii,ii+1}
  522.    end
  523.  
  524.    --ëèíèÿ
  525.    if figure == 2 then
  526.       gorizont = true
  527.       jj1=jj
  528.       ii1=ii
  529.       jj2=jj
  530.       ii2=ii+1
  531.       jj3=jj
  532.       ii3=ii+2
  533.       jj4=jj
  534.       ii4=ii+3
  535.       YY={jj,jj,jj,jj}
  536.       XX={ii,ii+1,ii+2,ii+3}
  537.    end
  538.  
  539.    -- ò-îáðàçàíàÿ
  540.    if figure == 3 then
  541.       ind=1
  542.       jj1=jj
  543.       ii1=ii
  544.       jj2=jj
  545.       ii2=ii+1
  546.       jj3=jj
  547.       ii3=ii+2
  548.       jj4=jj+1
  549.       ii4=ii+1
  550.       YY={jj,jj,jj+1,jj}
  551.       XX={ii,ii+1,ii+1,ii+2}
  552.    end
  553.  
  554.    -- L-îáðàçíàÿ ëåâàÿ
  555.    if figure == 4 then
  556.       ind=1
  557.       jj1=jj
  558.       ii1=ii
  559.       jj2=jj+1
  560.       ii2=ii
  561.       jj3=jj+2
  562.       ii3=ii
  563.       jj4=jj+2
  564.       ii4=ii+1
  565.  
  566.       YY={jj,jj+1,jj+2,jj+2}
  567.       XX={ii,ii,ii,ii+1}
  568.    end
  569.  
  570.    -- L-îáðàçíàÿ ïðàâàÿ
  571.    if figure == 5 then
  572.       jj=3
  573.       ii=5
  574.       ind=1
  575.       jj1=jj
  576.       ii1=ii
  577.       jj2=jj-1
  578.       ii2=ii+1
  579.       jj3=jj
  580.       ii3=ii+1
  581.       jj4=jj-2
  582.       ii4=ii+1
  583.  
  584.       YY={jj,jj-1,jj,jj-2}
  585.       XX={ii,ii+1,ii+1,ii+1}
  586.    end
  587.  
  588.    -- s-îáðàçíàÿ ëåâàÿ
  589.    if figure == 6 then
  590.       ind=1
  591.       jj1=jj
  592.       ii1=ii
  593.       jj2=jj
  594.       ii2=ii+1
  595.       jj3=jj+1
  596.       ii3=ii+1
  597.       jj4=jj+1
  598.       ii4=ii+2
  599.  
  600.       YY={jj,jj,jj+1,jj+1}
  601.       XX={ii,ii+1,ii+1,ii+2}
  602.    end
  603.    
  604.    -- s-îáðàçíàÿ ïðàâàÿ
  605.    if figure == 7 then
  606.       jj=2
  607.       ii=5
  608.       ind=1
  609.       jj1=jj
  610.       ii1=ii
  611.       jj2=jj
  612.       ii2=ii+1
  613.       jj3=jj-1
  614.       ii3=ii+1
  615.       jj4=jj-1
  616.       ii4=ii+2
  617.  
  618.       YY={jj,jj,jj-1,jj-1}
  619.       XX={ii,ii+1,ii+1,ii+2}
  620.    end
  621.  
  622.    GameOverCheck()
  623.    newfigure={texture[jj1][ii1],texture[jj2][ii2],texture[jj3][ii3],texture[jj4][ii4]}
  624.    for qq,gg in pairs(newfigure) do
  625.       gg.visible = true
  626.       gg.color = fcolors[figure]
  627.    end
  628.    
  629.    for kk=1,4 do
  630.       for ff=1,4 do
  631.          if shapes[nextFigure][kk][ff] == 1 then
  632.             nexttexture[kk][ff].visible = true
  633.             nexttexture[kk][ff].color = fcolors[nextFigure]
  634.          else
  635.             nexttexture[kk][ff].visible = false
  636.             nexttexture[kk][ff].color = {0,0,0,0}
  637.          end
  638.       end
  639.    end
  640.    
  641. end
  642.  
  643. checkBounds = function()
  644.    for i=1,4 do
  645.       if YY[i] < 1 or YY[i] > 19 or XX[i] < 1 or XX[i] > 9 then
  646.          return true
  647.       end
  648.    end
  649.    if texture[YY[1]][XX[1]].visible == true or texture[YY[2]][XX[2]].visible == true or texture[YY[3]][XX[3]].visible == true or texture[YY[4]][XX[4]].visible == true then
  650.       return true
  651.    end
  652.    return false
  653. end
  654.  
  655. RotateFigure = function()
  656.    if ind==0 then
  657.       ind=1
  658.    end
  659.    
  660.    if figure==2 then -- êðóòèì ëèíèþ
  661.       if YY[1]>2 then
  662.          if gorizont==false and XX[1]<2  then
  663.             --íè÷åãî íå äåëàåì åñëè ôèãóðà ñòîèò âåðòèêàëüíî âîçëå ãðàíèöû
  664.          else
  665.             if (XX[1]>0) and (XX[1]<10)  then
  666.                if XX[1]==9 and gorizont==false then
  667.                   VY={1,0,-1,-2}
  668.                   VX={2,1,0,-1}
  669.                else
  670.                   VY={1,0,-1,-2}
  671.                   VX={1,0,-1,-2}
  672.                end
  673.                
  674.                if gorizont==true then
  675.                   DrawFigure(false)
  676.                   for i=1,4 do
  677.                      YY[i]=YY[i]+VY[i]
  678.                      XX[i]=XX[i]+VX[i]
  679.                   end
  680.                   if checkBounds() == true then
  681.                      for i=1,4 do
  682.                         YY[i]=YY[i]-VY[i]
  683.                         XX[i]=XX[i]-VX[i]
  684.                      end
  685.                   end
  686.  
  687.                   DrawFigure(true, fcolors[2])
  688.                else
  689.                   DrawFigure(false)
  690.                   for i=1,4 do
  691.                      YY[i]=YY[i]-VY[i]
  692.                      XX[i]=XX[i]-VX[i]
  693.                   end
  694.                   if checkBounds() == true then
  695.                      for i=1,4 do
  696.                         YY[i]=YY[i]+VY[i]
  697.                         XX[i]=XX[i]+VX[i]
  698.                      end
  699.                   end
  700.  
  701.                   DrawFigure(true, fcolors[2])
  702.                end
  703.                gorizont = not gorizont
  704.             end
  705.          end
  706.       end
  707.    end
  708.  
  709.    if figure==3 then -- êðóòèì ò-îáðàçíóþ ôèãóðó
  710.       if YY[1]>1 then
  711.  
  712.          VYY={{0,0,0,-1},{0,0,-2,1},{1,0,0,0},{-1,0,2,0}}
  713.          VXX={{0,0,0,-1},{0,0,0,1},{1,0,0,0},{-1,0,0,0}}
  714.          VY={}
  715.          VX={}
  716.          if ind==5 then
  717.             ind=1
  718.          end
  719.          
  720.          if (XX[1]>0) and (XX[2]<9)  then
  721.             VY=VYY[ind]
  722.             VX=VXX[ind]
  723.  
  724.             DrawFigure(false)
  725.             for i=1,4 do
  726.                YY[i]=YY[i]+VY[i]
  727.                XX[i]=XX[i]+VX[i]
  728.             end
  729.             if checkBounds() == true then
  730.                for i=1,4 do
  731.                   YY[i]=YY[i]-VY[i]
  732.                   XX[i]=XX[i]-VX[i]
  733.                end
  734.             ind=ind-1
  735.             end
  736.             DrawFigure(true, fcolors[3])
  737.  
  738.             ind=ind+1
  739.          end
  740.       end
  741.    end
  742.  
  743.    if figure==4 then -- êðóòèì L-îáðàçíóþ ëåâóþ ôèãóðó
  744.       if YY[1]>1 then
  745.  
  746.          VYY={{1,0,0,-1},{-1,0,-2,1},{1,0,0,-1},{-1,0,2,1}}
  747.          VXX={{-1,0,-1,0},{0,0,1,-1},{0,0,1,1},{1,0,-1,0}}
  748.          VY={}
  749.          VX={}
  750.          if ind==5 then
  751.             ind=1
  752.          end
  753.          
  754.          if (XX[1]>0) and (XX[2]<9)  then
  755.  
  756.             VY=VYY[ind]
  757.             VX=VXX[ind]
  758.  
  759.             DrawFigure(false)
  760.             for i=1,4 do
  761.                YY[i]=YY[i]+VY[i]
  762.                XX[i]=XX[i]+VX[i]
  763.             end
  764.             if checkBounds() == true then
  765.                for i=1,4 do
  766.                   YY[i]=YY[i]-VY[i]
  767.                   XX[i]=XX[i]-VX[i]
  768.                end
  769.             ind=ind-1
  770.             end
  771.             DrawFigure(true, fcolors[4])
  772.  
  773.             ind=ind+1
  774.          end
  775.       end
  776.    end
  777.  
  778.    if figure==5 then -- êðóòèì L-îáðàçíóþ ïðàâóþ ôèãóðó
  779.       if YY[1]>1 then
  780.          VYY={{-2,0,-1,1},{0,0,1,-1},{1,0,-1,2},{1,0,1,-2}}
  781.          VXX={{0,0,-1,1},{1,0,1,0},{-1,0,1,0},{0,0,-1,-1}}
  782.          VY={}
  783.          VX={}
  784.          if ind==5 then
  785.             ind=1
  786.          end
  787.          
  788.          if (XX[1]>0) and (XX[2]<9)  then
  789.             VY=VYY[ind]
  790.             VX=VXX[ind]
  791.  
  792.             DrawFigure(false)
  793.             for i=1,4 do
  794.                YY[i]=YY[i]+VY[i]
  795.                XX[i]=XX[i]+VX[i]
  796.             end
  797.             if checkBounds() == true then
  798.                for i=1,4 do
  799.                   YY[i]=YY[i]-VY[i]
  800.                   XX[i]=XX[i]-VX[i]
  801.                end
  802.             ind=ind-1
  803.             end
  804.             DrawFigure(true, fcolors[5])
  805.  
  806.             ind=ind+1
  807.          end
  808.       end
  809.    end
  810.  
  811.    if figure==6 then -- êðóòèì S-îáðàçíóþ ïðàâóþ ôèãóðó
  812.       VYY={{1,0,-1,-2},{-1,0,1,2}}
  813.       VXX={{1,0,1,0},{-1,0,-1,0}}
  814.       VY={}
  815.       VX={}
  816.       if ind==3 then
  817.          ind=1
  818.       end
  819.      
  820.       if (XX[2]>1 and XX[2]<9) then
  821.          VY=VYY[ind]
  822.          VX=VXX[ind]
  823.  
  824.          DrawFigure(false)
  825.          for i=1,4 do
  826.             YY[i]=YY[i]+VY[i]
  827.             XX[i]=XX[i]+VX[i]
  828.          end
  829.          if checkBounds() == true then
  830.             for i=1,4 do
  831.                YY[i]=YY[i]-VY[i]
  832.                XX[i]=XX[i]-VX[i]
  833.             end
  834.             ind=ind-1
  835.          end
  836.          DrawFigure(true, fcolors[6])
  837.          
  838.          ind=ind+1
  839.       end
  840.    end
  841.  
  842.    if figure==7 then -- êðóòèì S-îáðàçíóþ ëåâóþ ôèãóðó
  843.       VYY={{-1,0,1,2},{1,0,-1,-2}}
  844.       VXX={{1,0,1,0},{-1,0,-1,0}}
  845.       VY={}
  846.       VX={}
  847.       if ind==3 then
  848.          ind=1
  849.       end
  850.  
  851.       if (XX[2]>1 and XX[2]<9)  then
  852.          VY=VYY[ind]
  853.          VX=VXX[ind]
  854.  
  855.          DrawFigure(false)
  856.          for i=1,4 do
  857.             YY[i]=YY[i]+VY[i]
  858.             XX[i]=XX[i]+VX[i]
  859.          end
  860.          if checkBounds() == true then
  861.             for i=1,4 do
  862.                YY[i]=YY[i]-VY[i]
  863.                XX[i]=XX[i]-VX[i]
  864.             end
  865.             ind=ind-1
  866.          end
  867.          DrawFigure(true, fcolors[7])          
  868.          
  869.          ind=ind+1
  870.       end
  871.    end
  872. end
  873.  
  874. InitTetris()
  875.  
  876. mainWnd:SetScript("OnSizeChanged", function(self)
  877.    mainWnd:SetWidth(mainWnd:GetHeight()/2)
  878.    local x,y = gamePane:GetWidth()/10, gamePane:GetHeight()/20
  879.    
  880.    for j = 1,20 do
  881.       for i = 1,10 do
  882.          texture[j][i]:SetPoint("TOPLEFT", gamePane, "TOPLEFT", x*i-x, -y*j+y)
  883.          texture[j][i]:SetWidth(x-1)
  884.          texture[j][i]:SetHeight(y-1)
  885.       end
  886.    end
  887. end)
  888.  
  889. -- slash command
  890. SLASH_TETRIS1 = "/tetris"
  891. SLASH_TETRIS2 = "/tt"
  892. SlashCmdList["TETRIS"] = function (msg)
  893.    gamePane:SetScript("OnUpdate", UpdatePane)
  894.    mainWnd:Show()
  895. end
Add Comment
Please, Sign In to add comment