From 1af13c380f2bc9f08369602f2cb152709494e2d8 Mon Sep 17 00:00:00 2001 From: heav Date: Sun, 26 Mar 2023 18:59:13 +0000 Subject: add piece shadow --- game/gfx.lua | 23 ++++++++++++++++++----- heav_optimal_shapes.lua | 32 -------------------------------- 2 files changed, 18 insertions(+), 37 deletions(-) delete mode 100644 heav_optimal_shapes.lua diff --git a/game/gfx.lua b/game/gfx.lua index ebb2241..d935fd9 100644 --- a/game/gfx.lua +++ b/game/gfx.lua @@ -41,20 +41,22 @@ function M:field_dimensions() return block_size, x, y, w, h end -function M:draw_square(block, x, y, block_size) +function M:draw_square(block, x, y, block_size, shadow) if colors[block] then love.graphics.setColor(unpack(colors[block])) else love.graphics.setColor(1, 1, 1) end + local r, g, b = love.graphics.getColor() + love.graphics.setColor(r, g, b, shadow and 0.2 or 1) love.graphics.rectangle("fill", x, y, block_size, block_size) end -function M:draw_block(block, line, column) +function M:draw_block(block, line, column, shadow) local block_size, field_x, field_y, _, field_h = self:field_dimensions() local x = field_x + (column - 1) * block_size local y = field_y + field_h - line * block_size - if block then self:draw_square(block, x, y, block_size) end + if block then self:draw_square(block, x, y, block_size, shadow) end end function M:draw_tetromino(tetromino, x, y, block_size, trim_margins) @@ -108,15 +110,23 @@ function M:draw_queue() end end -function M:draw_piece() +function M:draw_piece(shadow) local piece = self.game.piece + if shadow then + local old_piece = piece + piece = piece.poly:drop(self.game.field) + piece.line = old_piece.line + piece.column = old_piece.column + piece.rotation = old_piece.rotation + while piece:move(-1,0) do end + end if not piece then return end for l = 0, piece.poly.size - 1 do if piece.line + l <= self.game.field.lines then for c = 0, piece.poly.size - 1 do local block = piece:get_cell(l, c) if block then - self:draw_block(block, piece.line + l, piece.column + c) + self:draw_block(block, piece.line + l, piece.column + c, shadow) end end end @@ -142,6 +152,9 @@ function M:draw(dt) self:draw_piece() self:draw_hold() self:draw_queue() + if self.game.piece then + self:draw_piece(true) -- shadow. + end end function M:loop() diff --git a/heav_optimal_shapes.lua b/heav_optimal_shapes.lua deleted file mode 100644 index 784ba8e..0000000 --- a/heav_optimal_shapes.lua +++ /dev/null @@ -1,32 +0,0 @@ -local poly = require "polyomino" - -local M = {} -M.__index = M - -M.spite_shape = poly.def("heav.spite_shape", [[ - #.# - .#.# - #.#. - .#.# -]]) - -M.heav = poly.def("heav.heav", [[ - .#.. - .### - ###. - ..#. -]]) - -M.colon = poly.def("heav.colon", [[ - .#. - ... - .#. -]]) - -M.semicolon = poly.def("heav.semicolon", [[ - .#. - ... - ##. -]]) - -return M -- cgit v1.2.3