Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

Commit

Permalink
More graceful end to the game
Browse files Browse the repository at this point in the history
The game will not end until no more action happens on the screen.
  • Loading branch information
jakubg1 committed Jan 1, 2023
1 parent 72ff654 commit 61691bd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/Level.lua
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ function Level:updateLogic(dt)


-- Clear board once target time reached
if not self.finish and self:areAllObjectivesReached() then
if not self.finish and self:areAllObjectivesReached() and not self:hasShotSpheres() and not self:areMatchesPredicted() then
self.shooter:empty()
_Game.session:destroyAllSpheres(true)
self.finish = true
Expand Down Expand Up @@ -716,6 +716,21 @@ end



---Returns `true` if there are any matches predicted (spheres that magnetize to each other), `false` otherwise.
---@return boolean
function Level:areMatchesPredicted()
for i, path in ipairs(self.map.paths) do
for j, chain in ipairs(path.sphereChains) do
if chain:isMatchPredicted() then
return true
end
end
end
return false
end



---Returns `true` if the level has been finished, i.e. there are no more spheres and no more collectibles.
---@return boolean
function Level:getFinish()
Expand Down
4 changes: 4 additions & 0 deletions src/Shooter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ function Shooter:isActive()
if self.shotCooldown then
return false
end
-- FORK-RELATED CHANGE: If the time's up, don't allow to shoot more spheres.
if level:areAllObjectivesReached() then
return false
end
-- Otherwise, allow.
return true
end
Expand Down

0 comments on commit 61691bd

Please sign in to comment.