Files
tromi_mobile/game/piece.lua
Squishy (C6H12O6+NaCl+H2O) 3343d8711b V0 version
Add ``.gitignore``

Update ``.vscode\settings.json``

Main file changed a bit

Replace every single ``io.open`` into ``fs.read()``

Add ``input.waiting2trigger`` as buffer for too quick inputs

Replace ``binser`` with ``bitser``

Add the missing buffer logical code in training mode

Add a debug connector

Not a big update

Update VirtualControl.lua

Update in vctrl system

Trimming some unnecessary empty lines in classic library

Update virtual control stuff

Replace ``table.getn`` with ``#`` and ``scene`` with ``SCENE``

Renaming and moving some modules

Removing unnecessary ``local mino = {...}``

Add loading screen

Update loading screen

Apply replay patch

Not showing virtual control on computer

Adding touch screen configuration scene (placeholder)

Fix loading screen

update virtual control texture

Do some preparation for touch config screen

Quick patch

Compress background

Not important uodates

Small changes on how virtual key call action

Add ``SCENE:onInputMove``

Apply V2.2 patch

Clean up unnecessary imports

Test

.

Remove a redudant global variable

Small change

Split up alpha number

Sorting code

Update storeInput function

Optimize replay storing, saving and reading

Add VCTRL.export (for saving feature)

Remove unnecessary imports

Redesign loading screen

Replace loading screen

Make a simple BUTTON module

Update BUTTON module

Update button module

Add new callback

Add new callback

TEST

Update simple-button module

Update simple button module

Set default draw function for button

Add scene type notation

TEST

Not important updates

Design a error screen

Small update

Remove error key

Update

TEST

TEST

Test

TEST

TEST

Update button module

TEST

TEST

TEST

TEST

TEST

TEST

TEST

TEST

test

TEST

TEST

TEST

test

TEST

test

Fix a bug in VCTRL module that affect to SCENE:onInputRelease

Moving VCTRL related calls and adding buttons for name entry screen

Add type notation

Update modules

Final update for touch configuration scene

Fix 2 buttons can be highlighted at the same time in simple-button module

Narrow the safe border

Remove id = b (it was there for test)

Update of touch configuration scene

Add touch gesture for replay and input configuration scene

Add buttons for Replay, add MENU to go out after finishing game or in 20G Training mode

TEST

Fix some bugs (TEST)

Fix lỗi giữa đêm

Fix bug again

It should work imo

TEST

Fix SCENE:onInputMove{type="touch"} is not working

Fix bug once again (DONE!)

Temproraily allowing save

Fix settings module

Fix VCTRL.exportAll()

Fix VCTRL.exportAll returns userdata

Reverse a change

Fix forgetting to import virtual control settings

Fix grid drawing

Fix bugs related to the first time launching game

Add README file

Add README file

Update README and add LICENSE files

Update README

Add TV remote code

Disable debug code

Fix Android code

Small fix

Rename LICENSE to COPYING

Moving scene.lua to modules folder

Add new libraries

Make a new FILE API and add a simple error screen in case most thing went down

Change special code, add a way to skip keys

Update icon + README file

Rename screenshot file

Update README

Updating README file

Replace loading screen

Update README

Update virtual control texture

Fix virtual button method

Update README

Add icon font

Add importing and exporting replays

Update touch control

Update conf.lua

Replacing font, to avoid license issue

convert indents to spaces

Update font related stuff

Replace font

Updating README file

Update virtual control texture
2024-06-05 18:54:11 +07:00

175 lines
4.9 KiB
Lua

local Object = require 'libs.classic'
local Piece = Object:extend()
function Piece:new(shape, rotation, position, block_offsets, gravity, lock_delay, skin, colour, big)
self.shape = shape
self.rotation = rotation
self.position = position
self.block_offsets = block_offsets
self.gravity = gravity
self.lock_delay = lock_delay
self.skin = skin
self.colour = colour
self.lowest_point = -1
-- self.ghost = false
self.locked = false
-- self.big = big
end
-- Functions that return a new piece to test in rotation systems.
function Piece:withOffset(offset)
return Piece(
self.shape, self.rotation,
{x = self.position.x + offset.x, y = self.position.y + offset.y},
self.block_offsets, self.gravity, self.lock_delay, self.skin, self.colour
)
end
function Piece:withRelativeRotation(rot)
local new_rot = self.rotation + rot
while new_rot < 0 do new_rot = new_rot + 4 end
while new_rot >= 4 do new_rot = new_rot - 4 end
return Piece(
self.shape, new_rot, self.position,
self.block_offsets, self.gravity, self.lock_delay, self.skin, self.colour
)
end
-- Functions that return predicates relative to a grid.
function Piece:getBlockOffsets()
return self.block_offsets[self.shape][self.rotation + 1]
end
function Piece:occupiesSquare(x, y)
local offsets = self:getBlockOffsets()
for index, offset in pairs(offsets) do
local new_offset = {x = self.position.x + offset.x, y = self.position.y + offset.y}
if new_offset.x == x and new_offset.y == y then
return true
end
end
return false
end
function Piece:isMoveBlocked(grid, offset)
local moved_piece = self:withOffset(offset)
return not grid:canPlacePiece(moved_piece)
end
function Piece:isDropBlocked(grid)
return self:isMoveBlocked(grid, { x=0, y=1 })
end
-- Procedures to actually do stuff to pieces.
function Piece:setOffset(offset)
self.position.x = self.position.x + offset.x
self.position.y = self.position.y + offset.y
return self
end
function Piece:setRelativeRotation(rot)
new_rot = self.rotation + rot
while new_rot < 0 do new_rot = new_rot + 4 end
while new_rot >= 4 do new_rot = new_rot - 4 end
self.rotation = new_rot
return self
end
function Piece:moveInGrid(step, squares, grid, instant)
local moved = false
for x = 1, squares do
if grid:canPlacePiece(self:withOffset(step)) then
moved = true
self:setOffset(step)
if instant then
self:dropToBottom(grid)
end
else
break
end
end
return self
end
function Piece:dropSquares(dropped_squares, grid)
self:moveInGrid({ x = 0, y = 1 }, dropped_squares, grid)
end
function Piece:dropToBottom(grid)
local piece_y = self.position.y
self:dropSquares(math.huge, grid)
self.gravity = 0
if self.position.y > piece_y then
--self.lock_delay = 0
end
return self
end
function Piece:lockIfBottomed(grid)
if self:isDropBlocked(grid) then
self.locked = true
end
return self
end
function Piece:addGravity(gravity, grid, classic_lock)
gravity = gravity / (self.big and 2 or 1)
local new_gravity = self.gravity + gravity
if self:isDropBlocked(grid) then
if classic_lock then
self.gravity = new_gravity
else
self.gravity = 0
self.lock_delay = self.lock_delay + 1
end
elseif not (
self:isMoveBlocked(grid, { x=0, y=-1 }) and gravity < 0
) then
local dropped_squares = math.floor(math.abs(new_gravity))
if gravity >= 0 then
local new_frac_gravity = new_gravity - dropped_squares
self.gravity = new_frac_gravity
self:dropSquares(dropped_squares, grid)
if self:isDropBlocked(grid) then
PlaySE("bottom")
end
else
local new_frac_gravity = new_gravity + dropped_squares
self.gravity = new_frac_gravity
self:moveInGrid({ x=0, y=-1 }, dropped_squares, grid)
if self:isMoveBlocked(grid, { x=0, y=-1 }) then
PlaySE("bottom")
end
end
else
self.gravity = 0
end
return self
end
-- Procedures for drawing.
function Piece:draw(opacity, brightness, grid, partial_das)
if opacity == nil then opacity = 1 end
if brightness == nil then brightness = 1 end
love.graphics.setColor(brightness, brightness, brightness, opacity)
local offsets = self:getBlockOffsets()
local gravity_offset = 0
if partial_das == nil then partial_das = 0 end
for index, offset in pairs(offsets) do
local x = self.position.x + offset.x
local y = self.position.y + offset.y
love.graphics.draw(
BLOCKS[self.skin][self.colour],
216+x*16+partial_das, 80+y*16+gravity_offset
)
end
return false
end
return Piece