Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local F, C = unpack(Aurora)
- local INC_SPEED, START_SPEED = 0, .5
- local scale, space = 20, 20
- local stop, isPause, figure, gorizont, ind, nextFigure, speed, panespeed = true, false, 0, false, 0, nil, START_SPEED, .1
- local VYY,VYX,YY,XX,OXX,OYY = {},{},{},{},{},{}
- local fcolors = {
- {1,0,0,1},
- {1,1,0,1},
- {1,1,1,1},
- {1,0,1,1},
- {0,0,1,1},
- {0,1,1,1},
- {0,1,0,1},
- }
- local Flash = function(self, duration)
- if not self.anim then
- self.anim = self:CreateAnimationGroup("Flash")
- self.anim.fadein = self.anim:CreateAnimation("ALPHA", "FadeIn")
- self.anim.fadein:SetChange(1)
- self.anim.fadein:SetOrder(2)
- self.anim.fadeout = self.anim:CreateAnimation("ALPHA", "FadeOut")
- self.anim.fadeout:SetChange(-1)
- self.anim.fadeout:SetOrder(1)
- end
- self.anim.fadein:SetDuration(duration)
- self.anim.fadeout:SetDuration(duration)
- self.anim:Play()
- end
- -- îïèñûâàåì ìàòðèöó 10*20
- local texture = {}
- for i=1,20 do tinsert(texture, {0,0,0,0,0,0,0,0,0,0}) end
- local nexttexture = {}
- for i=1,4 do tinsert(nexttexture, {0,0,0,0}) end
- local mainWnd = CreateFrame("button", "GameTetrisFrame", UIParent)
- mainWnd:SetWidth(10*scale + space*2)
- mainWnd:SetHeight(20*scale + space*4)
- mainWnd:SetPoint("CENTER")
- mainWnd:EnableMouse(true)
- mainWnd:SetMovable(true)
- mainWnd:SetUserPlaced(true)
- mainWnd:SetClampedToScreen(true)
- mainWnd:SetScript("OnMouseDown", function(self) self:StartMoving() end)
- mainWnd:SetScript("OnMouseUp", function(self) self:StopMovingOrSizing() end)
- mainWnd:SetBackdrop({
- bgFile = C.media.backdrop,
- edgeFile = C.media.backdrop,
- tileSize = 64,
- edgeSize = 1,
- insets ={left =1, right =1, top =1, bottom =1},
- })
- mainWnd:SetBackdropColor(.0, .0, .0, .5)
- mainWnd:SetBackdropBorderColor(0,0,0,1)
- mainWnd:Hide()
- local title = mainWnd:CreateFontString(nil, "OVERLAY")
- title:SetFont("Interface\\AddOns\\Stuff\\media\\fonts\\semplice.ttf", 8, "OUTLINEMONOCHROME")
- title:SetPoint("TOPLEFT", space/2, -space/2)
- title:SetText("Tetris")
- local gamePane = CreateFrame("frame", nil, mainWnd)
- gamePane:SetPoint("TOPLEFT", space, -space-10)
- gamePane:SetPoint("BOTTOMRIGHT", mainWnd, "BOTTOMRIGHT", -space, space*3)
- gamePane:SetBackdrop({
- edgeFile = "Interface\\Buttons\\WHITE8x8",
- tile = false,
- tileSize = 0,
- edgeSize = 1,
- insets = {left =0, right =0, top =0, bottom =0},
- })
- gamePane:SetBackdropBorderColor(0, 0, 0, 1)
- local gamePaneNext = CreateFrame("frame", nil, mainWnd)
- gamePaneNext:SetPoint("TOPLEFT", gamePane, 4,-4)
- gamePaneNext:SetWidth(space*2)
- gamePaneNext:SetHeight(space*2)
- gamePaneNext:SetAlpha(.4)
- local gptex = gamePane:CreateTexture(nil, "BACKGROUND")
- gptex:SetAllPoints(gamePane)
- gptex:SetTexture(C.media.backdrop)
- gptex:SetTexCoord(.3,.7,.3,.7)
- gptex:SetVertexColor(0,0,0,.5)
- local gameMsg = gamePane:CreateFontString(nil, "OVERLAY")
- gameMsg:SetFont("Interface\\AddOns\\Stuff\\media\\fonts\\semplice.ttf", 8, "OUTLINEMONOCHROME")
- gameMsg:SetShadowOffset(0,0)
- gameMsg:SetPoint("CENTER")
- UpdatePane = function(self, elapsed)
- if self.ts == nil then self.ts = 0 end
- self.ts = self.ts + elapsed
- if (self.ts >= panespeed) then
- for j = 1,20 do
- for i = 1,10 do
- if (texture[j][i].visible) then
- texture[j][i]:SetVertexColor(unpack(texture[j][i].color))
- else
- texture[j][i]:SetVertexColor(1,1,1,0)
- end
- end
- end
- for j = 1,4 do
- for i = 1,4 do
- if (nexttexture[j][i].visible) then
- nexttexture[j][i]:SetVertexColor(unpack(nexttexture[j][i].color))
- else
- nexttexture[j][i]:SetVertexColor(1,1,1,0)
- end
- end
- end
- self.ts = 0
- end
- end
- local score = mainWnd:CreateFontString(nil, "OVERLAY", "GameFontNormal")
- score:SetFont("Interface\\AddOns\\Stuff\\media\\fonts\\semplice.ttf", 8, "OUTLINEMONOCHROME")
- score:SetShadowOffset(0,0)
- score:SetPoint("TOPLEFT", gamePane,"BOTTOMLEFT", 0, -space/2)
- score:SetText("Score: 0")
- local checkstr = mainWnd:CreateFontString(nil, "OVERLAY", "GameFontNormal")
- checkstr:SetFont("Interface\\AddOns\\Stuff\\media\\fonts\\semplice.ttf", 8, "OUTLINEMONOCHROME")
- checkstr:SetShadowOffset(0,0)
- checkstr:SetText("|cff00ff66Zombie|r mode")
- checkstr:SetPoint("TOPLEFT", score, "BOTTOMLEFT", 0, -space/2)
- local checkbox1 = CreateFrame("CheckButton", "$parent_cb1", mainWnd, "OptionsCheckButtonTemplate")
- checkbox1:SetPoint("LEFT", checkstr, "RIGHT", 5, 0)
- checkbox1:SetWidth(18)
- checkbox1:SetHeight(18)
- checkbox1:SetScript("OnClick", function() zombieMode = not zombieMode end)
- checkbox1:SetChecked(zombieMode)
- local playButton = CreateFrame("button", "playButton", mainWnd, "UIPanelButtonTemplate")
- local pauseButton = CreateFrame("button", "pauseButton", mainWnd, "UIPanelButtonTemplate")
- playButton:SetWidth(50)
- playButton:SetHeight(22)
- playButton:SetPoint("BOTTOMRIGHT", -space, space)
- playButton:SetText("Play")
- playButton:SetScript("OnClick", function(self)
- str=0
- score:SetText("Score: "..str)
- stop = not stop
- isPause = false
- gameMsg:SetText("")
- if stop then
- checkbox1:Enable()
- self:SetText("Play")
- gptex:SetTexture(C.media.backdrop)
- for j = 1,20 do
- for i = 1,10 do
- texture[j][i]:SetVertexColor(1,1,1,0)
- end
- end
- -- çàïóñê òàéìåðà, êàæäûå 500 ìèëëèñåêóíä áóäåò äâèãàòñÿ ôèãóðà
- mainWnd:SetScript("OnUpdate", nil)
- mainWnd:SetScript("OnKeyDown", nil)
- mainWnd:EnableKeyboard(false)
- gamePane:SetScript("OnUpdate", nil)
- pauseButton:Disable()
- StopMusic()
- else
- checkbox1:Disable()
- self:SetText("Stop")
- for j = 1,20 do
- for i = 1,10 do
- texture[j][i].visible = false
- texture[j][i].color = {0,0,0,0}
- end
- end
- -- ñîçäàåì íîâóþ ôèãóðó
- NewFigure()
- -- êàæäûå 500 ìèëëèñåêóíä áóäåò äâèãàòñÿ ôèãóðà
- mainWnd:SetScript("OnUpdate", OnUpdateGame)
- mainWnd:EnableKeyboard(true)
- mainWnd:SetScript("OnKeyDown", OnKeyDown)
- gamePane:SetScript("OnUpdate", UpdatePane)
- pauseButton:Enable()
- end
- end)
- pauseButton:SetWidth(50)
- pauseButton:SetHeight(22)
- pauseButton:SetPoint("RIGHT", playButton, "LEFT", -5, 0)
- pauseButton:SetText("Pause")
- pauseButton:Disable()
- pauseButton:SetScript("OnClick", function(self)
- if isPause then
- isPause = false
- gameMsg:SetText("")
- mainWnd:EnableKeyboard(true)
- self:SetText("Pause")
- else
- isPause = true
- gameMsg:SetTextColor(1,1,0)
- gameMsg:SetText("Pause")
- mainWnd:EnableKeyboard(false)
- self:SetText("Resume")
- end
- end)
- local CloseButton = CreateFrame("button", "tetriscloseButton", mainWnd, "UIPanelCloseButton")
- CloseButton:SetPoint("TOPRIGHT", mainWnd, "TOPRIGHT", 0, 0)
- CloseButton:SetScript("OnClick", function()
- isPause = true
- gameMsg:SetTextColor(1,1,0)
- gameMsg:SetText("Pause")
- pauseButton:SetText("Resume")
- mainWnd:Hide()
- end)
- local DrawFigure = function(visible, color)
- if visible then
- for i=1,4 do
- texture[YY[i]][XX[i]].visible = true
- texture[YY[i]][XX[i]].color = color
- end
- else
- for i=1,4 do
- texture[YY[i]][XX[i]].visible = false
- texture[YY[i]][XX[i]].color = {0,0,0,0}
- end
- end
- end
- InitTetris = function()
- local x,y = gamePane:GetWidth()/10, gamePane:GetHeight()/20
- for j = 1,20 do
- for i = 1,10 do
- local t = _G["brick"..i.."_"..j] or gamePane:CreateTexture("brick"..i.."_"..j, "ARTWORK")
- t:SetTexture("Interface\\Buttons\\WHITE8x8")
- t:SetPoint("TOPLEFT", gamePane, "TOPLEFT", x*i-x, -y*j+y)
- t:SetWidth(x-1)
- t:SetHeight(y-1)
- texture[j][i]=t
- end
- end
- x,y = gamePaneNext:GetWidth()/4, gamePaneNext:GetHeight()/4
- for j = 1,4 do
- for i = 1,4 do
- local t = _G["brickn"..i.."_"..j] or gamePaneNext:CreateTexture("brickn"..i.."_"..j, "ARTWORK")
- t:SetTexture("Interface\\Buttons\\WHITE8x8")
- t:SetPoint("TOPLEFT", gamePaneNext, "TOPLEFT", x*i-x, -y*j+y)
- t:SetWidth(x-1)
- t:SetHeight(y-1)
- nexttexture[j][i]=t
- end
- end
- end
- OnUpdateGame = function(self, elapsed)
- if self.ts == nil then self.ts = 0 end
- self.ts = self.ts + elapsed
- if (self.ts >= speed) then
- if isPause then return end
- if stop==true then
- mainWnd:SetScript("OnUpdate", nil)
- mainWnd:SetScript("OnKeyDown", nil)
- gamePane:SetScript("OnUpdate", nil)
- mainWnd:EnableKeyboard(false)
- return
- else
- local col = texture[YY[1]][XX[1]].color
- -- ñòèðàåì ôèãóðó
- DrawFigure(false)
- -- äåëàåì ñëåäóþùèé øàã
- for i=1,4 do
- YY[i]=YY[i]+1
- end
- -- åñëè ôèãóðà ïåðåñåêàåòñÿ õîòü ñ îäíèì âèäèìûì êâàäðàòîì òî îñòàíàâëèâàåì åå è ñîçäàåì íîâóþ ôèãóðó
- 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
- speed = START_SPEED
- panespeed = .1
- for i=1,4 do
- YY[i]=YY[i]-1
- end
- DrawFigure(true, col)
- NewFigure()
- else
- DrawFigure(true, col)
- end
- -- åñëè õîòü îäèí êâàäðàò ïðèáëèçèëñÿ ê íèæíåé ãðàíèöå îñòàíàâëèâàåì åãî è ñîçäàåì íîâóþ ôèãóðó
- for i=1,4 do
- if YY[i]>19 then
- speed = START_SPEED
- panespeed = .1
- NewFigure()
- break
- end
- end
- end
- self.ts = 0
- end
- end
- OnKeyDown = function(self, tetriskey, ...)
- if GetBindingFromClick(tetriskey) == "SCREENSHOT" then
- RunBinding("SCREENSHOT")
- return
- elseif GetBindingFromClick(tetriskey) == "ESCAPE" then
- RunBinding("ESCAPE")
- return
- end
- if tetriskey == "UNKNOWN" then
- return
- end
- local col = texture[YY[1]][XX[1]].color
- if tetriskey=="LEFT" then
- DrawFigure(false)
- --ïðîâåðÿåì ãðàíèöó ñòàêàíà (1 êâàäðàòèê â ôèãóðå âñåãäà êðàéíèé ñëåâà)
- if XX[1]~=1 then
- 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
- -- ïðîâåðÿåì ñòîëêíîâåíèÿ ñëåâà
- else
- XX[1]=XX[1]-1
- XX[2]=XX[2]-1
- XX[3]=XX[3]-1
- XX[4]=XX[4]-1
- end
- end
- DrawFigure(true, col)
- elseif tetriskey=="RIGHT" then
- DrawFigure(false)
- --ïðîâåðÿåì ãðàíèöó ñòàêàíà (4 êâàäðàòèê â ôèãóðå âñåãäà êðàéíèé ñïðàâà)
- if XX[4]~=10 then
- 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
- -- ïðîâåðÿåì ñòîëêíîâåíèÿ ñïðàâà
- else
- XX[1]=XX[1]+1
- XX[2]=XX[2]+1
- XX[3]=XX[3]+1
- XX[4]=XX[4]+1
- end
- end
- DrawFigure(true, col)
- elseif tetriskey == "UP" then
- RotateFigure()
- elseif tetriskey=="DOWN" then
- DrawFigure(false)
- --ïðîâåðÿåì íèæíþþ ãðàíèöó ñòàêàíà
- if (YY[1]>18) or (YY[2]>18) or (YY[3]>18) or (YY[4]>18) then
- -- ïîñëå 18 êëåòêè áûñòðûé ñïóñê íå ðàáîòàåò
- else
- YY[1]=YY[1]+1
- YY[2]=YY[2]+1
- YY[3]=YY[3]+1
- YY[4]=YY[4]+1
- end
- -- ïðîâåðÿåì íå âñòðåòèëîñü ëè ïðåïÿòñòâèå
- 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
- -- åñëè âñòðåòèëîñü âîçâðàùàåì êîîðäèíàòû îáðàòíî
- YY[1]=YY[1]-1
- YY[2]=YY[2]-1
- YY[3]=YY[3]-1
- YY[4]=YY[4]-1
- end
- -- ïðîðèñîâûâàåì ôèãóðó
- DrawFigure(true, col)
- elseif tetriskey == "SPACE" then
- speed = .01
- panespeed = speed
- else
- return
- end -- tetriskey
- end
- GameOverCheck = function()
- -- åñëè ôèãóðà ïåðåñåêàåòñÿ õîòü ñ îäíèì âèäèìûì êâàäðàòîì òî îñòàíàâëèâàåì èãðó
- 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
- stop = true
- gameMsg:SetTextColor(1,0,0)
- gameMsg:SetText("Game over!")
- playButton:SetText("Play")
- end
- end
- NewFigure = function()
- local isFilled = 0
- if not nextFigure then nextFigure = math.random(1,7) end
- figure = nextFigure
- nextFigure = math.random(1,7)
- -- óêàçàòåëü ïîëîæåíèÿ â ìàòðèöå
- local ii, jj = 5, 1
- local jj1, ii1, jj2, ii2, jj3, ii3, jj4, ii4 = 0, 0, 0, 0, 0, 0, 0, 0
- local filled = 0
- local shapes = {
- { -- êâàäðàò
- {1,1,0,0},
- {1,1,0,0},
- {0,0,0,0},
- {0,0,0,0},
- },
- { -- ëèíèÿ
- {1,1,1,1},
- {0,0,0,0},
- {0,0,0,0},
- {0,0,0,0},
- },
- { -- ò-îáðàçàíàÿ
- {1,1,1,0},
- {0,1,0,0},
- {0,0,0,0},
- {0,0,0,0},
- },
- { -- L-îáðàçíàÿ ëåâàÿ
- {0,1,0,0},
- {0,1,0,0},
- {0,1,1,0},
- {0,0,0,0},
- },
- { -- L-îáðàçíàÿ ïðàâàÿ
- {0,1,0,0},
- {0,1,0,0},
- {1,1,0,0},
- {0,0,0,0},
- },
- { -- s-îáðàçíàÿ ëåâàÿ
- {1,1,0,0},
- {0,1,1,0},
- {0,0,0,0},
- {0,0,0,0},
- },
- { -- s-îáðàçíàÿ ïðàâàÿ
- {0,1,1,0},
- {1,1,0,0},
- {0,0,0,0},
- {0,0,0,0},
- },
- }
- -- ïðîâåðêà íà çàïîëíåíîñòü ëèíèè
- for j=1,20 do
- for i=1,10 do
- if texture[j][i].visible == true then
- filled = filled + 1
- end
- if filled == 10 then -- åñëè çàïîëíåíû âñå 10 ÿ÷ååê, òî ñìåùàåì âåðõíþþ ÷àñòü òàáëèöû âíèç
- for k=1,10 do
- Flash(texture[j][k], 0.1)
- end
- isFilled = isFilled + 1
- if isFilled > 1 then
- str=str+(2*isFilled)
- end
- else
- str=str+1
- end
- -- ðèñóåì â íàäïèñè êîëè÷åñòâî íàáðàííûõ î÷êîâ
- score:SetText("Score: "..str)
- for kj=2,j do
- for ki=1,10 do
- texture[j-kj+2][ki].visible=texture[j-kj+1][ki].visible
- texture[j-kj+2][ki].color=texture[j-kj+1][ki].color
- end
- end
- end
- end
- filled=0
- end
- --êâàäðàò
- if figure == 1 then
- -- âêëþ÷àåì êâàäðàòû òàì ãäå îíè âèäèìû
- jj1=jj
- ii1=ii
- jj2=jj
- ii2=ii+1
- jj3=jj+1
- ii3=ii
- jj4=jj+1
- ii4=ii+1
- YY={jj,jj,jj+1,jj+1}
- XX={ii,ii+1,ii,ii+1}
- end
- --ëèíèÿ
- if figure == 2 then
- gorizont = true
- jj1=jj
- ii1=ii
- jj2=jj
- ii2=ii+1
- jj3=jj
- ii3=ii+2
- jj4=jj
- ii4=ii+3
- YY={jj,jj,jj,jj}
- XX={ii,ii+1,ii+2,ii+3}
- end
- -- ò-îáðàçàíàÿ
- if figure == 3 then
- ind=1
- jj1=jj
- ii1=ii
- jj2=jj
- ii2=ii+1
- jj3=jj
- ii3=ii+2
- jj4=jj+1
- ii4=ii+1
- YY={jj,jj,jj+1,jj}
- XX={ii,ii+1,ii+1,ii+2}
- end
- -- L-îáðàçíàÿ ëåâàÿ
- if figure == 4 then
- ind=1
- jj1=jj
- ii1=ii
- jj2=jj+1
- ii2=ii
- jj3=jj+2
- ii3=ii
- jj4=jj+2
- ii4=ii+1
- YY={jj,jj+1,jj+2,jj+2}
- XX={ii,ii,ii,ii+1}
- end
- -- L-îáðàçíàÿ ïðàâàÿ
- if figure == 5 then
- jj=3
- ii=5
- ind=1
- jj1=jj
- ii1=ii
- jj2=jj-1
- ii2=ii+1
- jj3=jj
- ii3=ii+1
- jj4=jj-2
- ii4=ii+1
- YY={jj,jj-1,jj,jj-2}
- XX={ii,ii+1,ii+1,ii+1}
- end
- -- s-îáðàçíàÿ ëåâàÿ
- if figure == 6 then
- ind=1
- jj1=jj
- ii1=ii
- jj2=jj
- ii2=ii+1
- jj3=jj+1
- ii3=ii+1
- jj4=jj+1
- ii4=ii+2
- YY={jj,jj,jj+1,jj+1}
- XX={ii,ii+1,ii+1,ii+2}
- end
- -- s-îáðàçíàÿ ïðàâàÿ
- if figure == 7 then
- jj=2
- ii=5
- ind=1
- jj1=jj
- ii1=ii
- jj2=jj
- ii2=ii+1
- jj3=jj-1
- ii3=ii+1
- jj4=jj-1
- ii4=ii+2
- YY={jj,jj,jj-1,jj-1}
- XX={ii,ii+1,ii+1,ii+2}
- end
- GameOverCheck()
- newfigure={texture[jj1][ii1],texture[jj2][ii2],texture[jj3][ii3],texture[jj4][ii4]}
- for qq,gg in pairs(newfigure) do
- gg.visible = true
- gg.color = fcolors[figure]
- end
- for kk=1,4 do
- for ff=1,4 do
- if shapes[nextFigure][kk][ff] == 1 then
- nexttexture[kk][ff].visible = true
- nexttexture[kk][ff].color = fcolors[nextFigure]
- else
- nexttexture[kk][ff].visible = false
- nexttexture[kk][ff].color = {0,0,0,0}
- end
- end
- end
- end
- checkBounds = function()
- for i=1,4 do
- if YY[i] < 1 or YY[i] > 19 or XX[i] < 1 or XX[i] > 9 then
- return true
- end
- end
- 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
- return true
- end
- return false
- end
- RotateFigure = function()
- if ind==0 then
- ind=1
- end
- if figure==2 then -- êðóòèì ëèíèþ
- if YY[1]>2 then
- if gorizont==false and XX[1]<2 then
- --íè÷åãî íå äåëàåì åñëè ôèãóðà ñòîèò âåðòèêàëüíî âîçëå ãðàíèöû
- else
- if (XX[1]>0) and (XX[1]<10) then
- if XX[1]==9 and gorizont==false then
- VY={1,0,-1,-2}
- VX={2,1,0,-1}
- else
- VY={1,0,-1,-2}
- VX={1,0,-1,-2}
- end
- if gorizont==true then
- DrawFigure(false)
- for i=1,4 do
- YY[i]=YY[i]+VY[i]
- XX[i]=XX[i]+VX[i]
- end
- if checkBounds() == true then
- for i=1,4 do
- YY[i]=YY[i]-VY[i]
- XX[i]=XX[i]-VX[i]
- end
- end
- DrawFigure(true, fcolors[2])
- else
- DrawFigure(false)
- for i=1,4 do
- YY[i]=YY[i]-VY[i]
- XX[i]=XX[i]-VX[i]
- end
- if checkBounds() == true then
- for i=1,4 do
- YY[i]=YY[i]+VY[i]
- XX[i]=XX[i]+VX[i]
- end
- end
- DrawFigure(true, fcolors[2])
- end
- gorizont = not gorizont
- end
- end
- end
- end
- if figure==3 then -- êðóòèì ò-îáðàçíóþ ôèãóðó
- if YY[1]>1 then
- VYY={{0,0,0,-1},{0,0,-2,1},{1,0,0,0},{-1,0,2,0}}
- VXX={{0,0,0,-1},{0,0,0,1},{1,0,0,0},{-1,0,0,0}}
- VY={}
- VX={}
- if ind==5 then
- ind=1
- end
- if (XX[1]>0) and (XX[2]<9) then
- VY=VYY[ind]
- VX=VXX[ind]
- DrawFigure(false)
- for i=1,4 do
- YY[i]=YY[i]+VY[i]
- XX[i]=XX[i]+VX[i]
- end
- if checkBounds() == true then
- for i=1,4 do
- YY[i]=YY[i]-VY[i]
- XX[i]=XX[i]-VX[i]
- end
- ind=ind-1
- end
- DrawFigure(true, fcolors[3])
- ind=ind+1
- end
- end
- end
- if figure==4 then -- êðóòèì L-îáðàçíóþ ëåâóþ ôèãóðó
- if YY[1]>1 then
- VYY={{1,0,0,-1},{-1,0,-2,1},{1,0,0,-1},{-1,0,2,1}}
- VXX={{-1,0,-1,0},{0,0,1,-1},{0,0,1,1},{1,0,-1,0}}
- VY={}
- VX={}
- if ind==5 then
- ind=1
- end
- if (XX[1]>0) and (XX[2]<9) then
- VY=VYY[ind]
- VX=VXX[ind]
- DrawFigure(false)
- for i=1,4 do
- YY[i]=YY[i]+VY[i]
- XX[i]=XX[i]+VX[i]
- end
- if checkBounds() == true then
- for i=1,4 do
- YY[i]=YY[i]-VY[i]
- XX[i]=XX[i]-VX[i]
- end
- ind=ind-1
- end
- DrawFigure(true, fcolors[4])
- ind=ind+1
- end
- end
- end
- if figure==5 then -- êðóòèì L-îáðàçíóþ ïðàâóþ ôèãóðó
- if YY[1]>1 then
- VYY={{-2,0,-1,1},{0,0,1,-1},{1,0,-1,2},{1,0,1,-2}}
- VXX={{0,0,-1,1},{1,0,1,0},{-1,0,1,0},{0,0,-1,-1}}
- VY={}
- VX={}
- if ind==5 then
- ind=1
- end
- if (XX[1]>0) and (XX[2]<9) then
- VY=VYY[ind]
- VX=VXX[ind]
- DrawFigure(false)
- for i=1,4 do
- YY[i]=YY[i]+VY[i]
- XX[i]=XX[i]+VX[i]
- end
- if checkBounds() == true then
- for i=1,4 do
- YY[i]=YY[i]-VY[i]
- XX[i]=XX[i]-VX[i]
- end
- ind=ind-1
- end
- DrawFigure(true, fcolors[5])
- ind=ind+1
- end
- end
- end
- if figure==6 then -- êðóòèì S-îáðàçíóþ ïðàâóþ ôèãóðó
- VYY={{1,0,-1,-2},{-1,0,1,2}}
- VXX={{1,0,1,0},{-1,0,-1,0}}
- VY={}
- VX={}
- if ind==3 then
- ind=1
- end
- if (XX[2]>1 and XX[2]<9) then
- VY=VYY[ind]
- VX=VXX[ind]
- DrawFigure(false)
- for i=1,4 do
- YY[i]=YY[i]+VY[i]
- XX[i]=XX[i]+VX[i]
- end
- if checkBounds() == true then
- for i=1,4 do
- YY[i]=YY[i]-VY[i]
- XX[i]=XX[i]-VX[i]
- end
- ind=ind-1
- end
- DrawFigure(true, fcolors[6])
- ind=ind+1
- end
- end
- if figure==7 then -- êðóòèì S-îáðàçíóþ ëåâóþ ôèãóðó
- VYY={{-1,0,1,2},{1,0,-1,-2}}
- VXX={{1,0,1,0},{-1,0,-1,0}}
- VY={}
- VX={}
- if ind==3 then
- ind=1
- end
- if (XX[2]>1 and XX[2]<9) then
- VY=VYY[ind]
- VX=VXX[ind]
- DrawFigure(false)
- for i=1,4 do
- YY[i]=YY[i]+VY[i]
- XX[i]=XX[i]+VX[i]
- end
- if checkBounds() == true then
- for i=1,4 do
- YY[i]=YY[i]-VY[i]
- XX[i]=XX[i]-VX[i]
- end
- ind=ind-1
- end
- DrawFigure(true, fcolors[7])
- ind=ind+1
- end
- end
- end
- InitTetris()
- mainWnd:SetScript("OnSizeChanged", function(self)
- mainWnd:SetWidth(mainWnd:GetHeight()/2)
- local x,y = gamePane:GetWidth()/10, gamePane:GetHeight()/20
- for j = 1,20 do
- for i = 1,10 do
- texture[j][i]:SetPoint("TOPLEFT", gamePane, "TOPLEFT", x*i-x, -y*j+y)
- texture[j][i]:SetWidth(x-1)
- texture[j][i]:SetHeight(y-1)
- end
- end
- end)
- -- slash command
- SLASH_TETRIS1 = "/tetris"
- SLASH_TETRIS2 = "/tt"
- SlashCmdList["TETRIS"] = function (msg)
- gamePane:SetScript("OnUpdate", UpdatePane)
- mainWnd:Show()
- end
Add Comment
Please, Sign In to add comment