Thanks for the help,
I know there will be lot’s of math involved in this and math is not my strong side so…
The most difficult part in programming is how to structure the project the best way, I had a look at a tutorial over at mobile tuts and they listed all the functions and vars before they started writing the code so that’s what I will do because it seamed like a wise thing to do. I’m also using the director class for scene management.
Please give me feedback and if I should modulize the project.
game.lua
[code]
module(…, package.seeall)
function new( )
local gameGroup = display.newGroup()
local hudGroup = display.newGroup()
local screenWidth = display.contentWidth
local screenHeight = display.contentHeight
local gameBg
local scoreLabel
local timeBar
local levelLabel
local pauseButton
local rows = 9
local columns = 7
local offSetY = 18
local boxWidth = 40
local boxHeight = 40
local color = {“red.png”, “green.png”, “blue.png”, “yellow.png”}
local saveColors = {}
local boxes = {}
local makeBoxes = {}
local checkForMatch = {}
local removeBoxes = {}
local moveBoxesDown = {}
local directions = {“N”, “NW”, “NE”, “S”, “SW”, “SE”}
local canRemoveBoxes = true
local cleanMemory = {}
– Create the grid and add boxes to it.
makeBoxes = function()
for row = 1, rows do
for col = 1, columns do
local mRand = math.random(#color);
ct = ((row-1)*columns) + row
boxes[ct] = display.newImageRect(color[mRand], 36, 36 )
boxes[ct].x = (col-1) * boxWidth
boxes[ct].y = ((col%-2) * offSetY) + (row-1) * boxHeight
localGroup:insert(boxes[ct]);
localGroup:setReferencePoint(display.BottomCenterReferencePoint);
localGroup.x = screenWidth * 0.5;
localGroup.y = screenHeight - 32
boxes[ct]:addEventListener(“touch”, removeBoxes)
end
end
end
– Check if there are any adjacent boxes of the same color, need at least 3 adjacent to remove.
checkForMatch = function()
end
– Touch handler for removing boxes
removeBoxes = function(event)
if (event.phase == “ended”) then
event.target:removeSelf()
print(" box removed ")
end
– Move boxes down if there is an empty space below.
moveBoxesDown = function()
end
– Remove listeners and other things not needed anymore.
cleanMemory = function()
end
– Insert into groups
gameGroup:insert(hudGroup)
return gameGroup
end
[/code] [import]uid: 65840 topic_id: 14407 reply_id: 53400[/import]