This commit is contained in:
Igor Timofeev 2015-10-06 14:55:21 +03:00
parent 59829c7c5c
commit d9fe795fc8

View File

@ -61,12 +61,19 @@ local function calculateBrightness(color1, brightness)
end
local function recalculateColors()
--Всякие тени, света для корпуса
colors.light1 = calculateBrightness(colors.tetrisColor, 0xCC)
colors.light2 = calculateBrightness(colors.tetrisColor, 0xAA)
colors.light3 = calculateBrightness(colors.tetrisColor, 0x55)
colors.shadow1 = calculateBrightness(colors.tetrisColor, -(0xCC))
colors.shadow2 = calculateBrightness(colors.tetrisColor, -(0xAA))
colors.shadow3 = calculateBrightness(colors.tetrisColor, -(0x77))
--Для кнопочек
if colors.button > 0x777777 then
colors.buttonText = calculateBrightness(colors.button, -(0x77))
else
colors.buttonText = calculateBrightness(colors.button, 0x77)
end
end
local sizes = {}
@ -172,55 +179,72 @@ function tetris.drawScreen()
end
function tetris.drawButtons()
local xPos, yPos = (sizes.heightOfScreen + sizes.yScreenOffset * 2 + 6)
local xPos, yPos = tetris.x + math.floor(sizes.caseWidth / 2 - 17), tetris.y + (sizes.heightOfScreen + sizes.yScreenOffset * 2 + 6) + 6
ecs.drawButton(xPos, yPos, 6, 3, "", colors.button, colors.buttonText)
xPos = xPos + 12
ecs.drawButton(xPos, yPos, 6, 3, "", colors.button, colors.buttonText)
xPos = xPos - 6
yPos = yPos - 3
ecs.drawButton(xPos, yPos, 6, 3, "", colors.button, colors.buttonText)
yPos = yPos + 3 * 2
ecs.drawButton(xPos, yPos, 6, 3, "", colors.button, colors.buttonText)
xPos = xPos + 17
yPos = yPos - 4
ecs.square(xPos + 2, yPos, 6, 5, colors.button)
ecs.square(xPos, yPos + 1, 10, 3, colors.button)
end
function tetris.drawCase(x, y)
function tetris.drawCase()
--Делаем перерасчет размеров экрана
tetris.recalculateSizes()
--Рассчитываем размер корпуса
sizes.xSize, sizes.ySize = gpu.getResolution()
sizes.caseWidth = sizes.widthOfScreen + sizes.xScreenOffset * 2
sizes.heightOfBottomThing = sizes.ySize - (sizes.heightOfScreen + sizes.yScreenOffset * 2 + 6) - y + 1
local yPos = y
sizes.heightOfBottomThing = sizes.ySize - (sizes.heightOfScreen + sizes.yScreenOffset * 2 + 6) - tetris.y + 1
local yPos = tetris.y
--Рисуем верхнюю штучку
ecs.square(x + 1, yPos, sizes.caseWidth - 2, 1, colors.light1)
ecs.square(tetris.x + 1, yPos, sizes.caseWidth - 2, 1, colors.light2)
yPos = yPos + 1
--Рисуем всю штучку под экраном
ecs.square(x, yPos, sizes.caseWidth, sizes.heightOfScreen + sizes.yScreenOffset * 2 - 1, colors.tetrisColor)
ecs.square(x + sizes.xScreenOffset - 1, yPos + 1, sizes.widthOfScreen + 2, sizes.heightOfScreen + 2, colors.shadow1)
ecs.square(tetris.x, yPos, sizes.caseWidth, sizes.heightOfScreen + sizes.yScreenOffset * 2 - 1, colors.tetrisColor)
ecs.square(tetris.x + sizes.xScreenOffset - 1, yPos + 1, sizes.widthOfScreen + 2, sizes.heightOfScreen + 2, colors.shadow1)
yPos = yPos + sizes.heightOfScreen + sizes.yScreenOffset * 2 - 1
--Рисуем кольцевую штучку
ecs.square(x, yPos, sizes.caseWidth, 1, colors.light2); yPos = yPos + 1
ecs.square(x, yPos, sizes.caseWidth, 1, colors.light1); yPos = yPos + 1
ecs.square(x, yPos, sizes.caseWidth, 2, colors.tetrisColor); yPos = yPos + 2
ecs.square(x, yPos, sizes.caseWidth, 1, colors.shadow1); yPos = yPos + 1
ecs.square(x, yPos, sizes.caseWidth, 1, colors.shadow2); yPos = yPos + 1
ecs.square(tetris.x, yPos, sizes.caseWidth, 1, colors.light2); yPos = yPos + 1
ecs.square(tetris.x, yPos, sizes.caseWidth, 1, colors.light1); yPos = yPos + 1
ecs.square(tetris.x, yPos, sizes.caseWidth, 2, colors.tetrisColor); yPos = yPos + 2
ecs.square(tetris.x, yPos, sizes.caseWidth, 1, colors.shadow1); yPos = yPos + 1
ecs.square(tetris.x, yPos, sizes.caseWidth, 1, colors.shadow2); yPos = yPos + 1
--Рисуем под кнопочками
ecs.square(x, yPos, sizes.caseWidth, sizes.heightOfBottomThing, colors.tetrisColor)
ecs.square(tetris.x, yPos, sizes.caseWidth, sizes.heightOfBottomThing, colors.tetrisColor)
end
function tetris.draw(x, y, screenResolutionWidth, screenResolutionHeight, showInfoPanel)
--Задаем стартовые прелести
tetrisColor = tetrisColor or 0xFF5555
--Задаем переменную показа инфопанели
tetris.showInfoPanel = showInfoPanel
--Просчитываем цвета
recalculateColors()
--Создаем массив основного экрана нужной ширины и высоты
tetris.generateScreenArray(screenResolutionWidth, screenResolutionHeight)
--Девайс
tetris.drawCase(x, y)
--Рисуем экран
tetris.xScreen, tetris.yScreen = x + sizes.xScreenOffset, y + sizes.yScreenOffset
--Рисуем корпус устройства
tetris.x, tetris.y = x, y
tetris.drawCase()
--Рисуем экран тетриса
tetris.xScreen, tetris.yScreen = tetris.x + sizes.xScreenOffset, tetris.y + sizes.yScreenOffset
tetris.drawScreen()
--Кнопочки рисуем
tetris.drawButtons()
end
-------------------------------------------- Программа -------------------------------------------------------------
ecs.prepareToExit()
tetris.changeColors(0xFF33FF, 0x44AA44)
tetris.changeColors(0x008800, 0xFFFF00)
tetris.draw(10, 5, 27, 20, false)
tetris.changeColors(0xFF5555, 0x44AA44)
tetris.changeColors(0xFF5555, 0xFFFF00)
tetris.draw(80, 5, 10, 20, true)