Hi @martinlim520,
Please review the resources under “Physics” on this page:
http://docs.coronalabs.com/guide/index.html
Regards,
Brent Sorrentino
Hi @martinlim520,
Please review the resources under “Physics” on this page:
http://docs.coronalabs.com/guide/index.html
Regards,
Brent Sorrentino
Thanks , can I change the transition.to to enterframe and how to make two block move down together in same column .
Same as one but you have to check under both if horizontal
If use physics the blocks will falling down when stack too high .
Why my blocks overlap together ?
local cols = 6 -- number of columns local rows = 10 -- number of rows local blockSize = 35 -- size of blocks local blocks = {} -- table of blocks on screen local gridTable = {} -- table of open slots local ready = true -- ready for next block local count = 1 local grid ={} function setupGrid() for c = 0, cols do gridTable[c] = {} for r = 0, rows do gridTable[c][r] = 0 end end end function moveBlockDown( arg ) local c,r = arg.loc[1], arg.loc[2] local newy = arg.y + blockSize arg.loc[1] = c arg.loc[2] = r+1 if gridTable[c+1][r+1] == 0 then transition.to(arg, {time = 500, y = newy, onComplete = function() arg.y = newy moveBlockDown(arg) end}) else -- add a little bounce newy = arg.y - blockSize/10 transition.to( arg, { time = 100, y = newy, onComplete = function() newy = arg.y+blockSize/10 transition.to( arg, { time = 100, y = newy }) end}) --set gridTable to 1 gridTable[c+1][r] = 1 ready = true end end function newBlock() pick = 3 --math.random(0, 6) if gridTable[1][1] == 0 then ready = false -- prevents new block until done with prev. block block = display.newRect(pick\*blockSize+60 , 0-blockSize+100 , blockSize , blockSize) block:setFillColor(math.random(255), math.random(255), math.random(255), 255) block2 = display.newRect( pick\*blockSize+60 , 0-blockSize+100+blockSize , blockSize , blockSize ) block2:setFillColor(math.random(255), math.random(255), math.random(255), 255) blocks[#blocks+1] = block blocks[#blocks+1] = block2 block.loc = {pick ,0} block2.loc = {pick , 0} arg = blocks[#blocks] print("move "..#blocks) moveBlockDown(block) moveBlockDown(block2) elseif gridTable[1][1] == 1 then print("picking new start") newBlock() end end -- call setupGrid setupGrid() -- this is just here to produce new blocks function callNewBlock() if ready == true and count \< 6 then --rows\*cols then count = count + 1 newBlock() callNewBlock() elseif ready == false and count \< 6 then--rows\*cols then timer.performWithDelay(250, callNewBlock) else print("done") end end -- start calling new block callNewBlock()
At what point do they overlap
Would you be interested in non-physics collision detection? Here’s a tutorial on it:
http://omnigeek.robmiracle.com/2011/12/14/collision-detection-without-physics/
Brent Sorrentino
Is there any other way because I’m self teaching corona programming , I can’t undestand the http://omnigeek.robmiracle.com/2011/12/14/collision-detection-without-physics/ .Someone say use the array to check the space empty and move down but how to do it .
Is there any other way because I’m self teaching corona programming , I can’t undestand the http://omnigeek.robmiracle.com/2011/12/14/collision-detection-without-physics/ .Someone say use the array to check the space empty and move down but how to do it .
The block2 overlap with the next first block .
couple issues
you not handling both blocks in the move down function
when blocks are created you are checking to see if the first grid position is open instead of checking under both blocks
heres some things that may help you with coding
a good lua crash course
and code exchange
and some other helpful stuff
Hello again,
You could build a basic array, like a grid, and then check if a particular space is “empty” or not. The first thing you’ll need to learn is how to build multi-dimensional arrays (tables) in Lua. Do you know how to do that?
Regards,
Brent
I’ve got code somewhere in the forums from about 2 years ago that does this I think been a long time ago. I’ll see if I can find it
its not exactly what you need but this may help you figure out what you need
https://developer.coronalabs.com/forum/2011/09/06/checking-grid-array-line-patterns
https://developer.coronalabs.com/forum/2011/09/06/checking-grid-array-line-patterns . Is this code for detecting the same object .
Yes like a bejeweled style
Actually I want to know how to make the block stop falling down and stack when touch with other block .Do you know how to do it .
Is anyone know how to do that .This is my moveDown function :
local function moveDown(self) if self.y \< board[2][11].y then self.y =self.y + 1 else end end
Not at computer at the moment but the steps you need to take are
Say you have a grid of 5 by 5, just keeping it simple
You want to set each array entry to 0,
grid={} for a=1,5 do grid[a]={} for b=1,5 do grid[a][b]=0 end end
Now say you have a block enter at top
You check the grid at, lets say it’s coming in in row 2, position (1,2) if it 0 then it’s ok to move down one position and you set (1,2)=1 meaning there’s a block in that position now. Now the block is at (1,2) so now you check (2,2) if it’s 0 you move change (1,2) back to 0 and set (2,2)=1. Same thing if you move left or right. You just keep doing this until the position below the block is not a 0 which means now it’s stacked on top or it’s reached the bottom.
This is my grid array
local grid ={} for i =1,6 do grid[i] = {} for j =1 ,11 do grid[i][j] = 0 grid[i][j] = display.newRect(0,0,36,36) grid[i][j].x = i\*37 + 22 grid[i][j].y = j\*37 + 22 grid[i][j].alpha = 0.1 end end
then how to set the position be 1 and drop the block .