an another form of grid/table ?

hi,

Now, i use this type of grid to make my level :

local gridGame = {} local row = 9 local cell = 14 local rectx = 30 local recty = 30 local gridscaley = 0.35 local gridscalex = 0.35 local space = 2 local spaceleft =40 local spacetop = 20     for i = 1, cell do         gridGame[i] = {};         for k = 1, row do             gridGame[i][k] = display.newImage("dalle.png")             gridGame[i][k].yScale=0.35             gridGame[i][k].xScale=0.35             gridGame[i][k].alpha = 1             gridGame[i][k].x = (k - 1) \* (rectx + space) + spaceleft             gridGame[i][k].y = (i - 1) \* (recty + space) + spacetop                  end end

but in the future i would more personnalize and make this

mytable =  {} 0 0 1 0 1 0 1 0 0 1 0 1 end

where each number represent a cell

**0 for a red cell

1 for a green cell**

but my question is how to have a space between each cell with this type of representation ?

with the previous grid, it’s make with

gridGame[i][k].x = (k - 1) \* (rectx + space) + spaceleft gridGame[i][k].y = (i - 1) \* (recty + space) + spacetop

But i don’t know how to make this with this new table ?

thanks

anybody ? please

i try this but without success

local gridGame = {} local widthscreen =320 local heightscreen =480 local row = 24 local cell = 12 local rectx = 30 local recty = 30 local gridscaley = 0.35 local gridscalex = 0.35 local space = 2 local spaceleft =40 local spacetop = 20 local divx=widthscreen/(row\*2) local divy=heightscreen/(cell\*2) local maze = {         { x, x,  },         { x, w,  },         { x, x,  },         { x, w,  },         { x, x,  },         { x, w,  },         { x, w,  },         { x, w,  },         { x, w,  },         { x, w,  },         { x, w,  },         { x, w,  },     }     maze.rows = table.getn(maze)     maze.columns = table.getn(maze[1])     maze.xStart, maze.yStart = 1, 100     maze.xFinish, maze.yFinish = 24, 7     maze.object = x or w      if maze.object == x then         image="dalle9.png"     end     if maze.object == w then         image="dalle1.png"     end         for i = 1, maze.rows do         gridGame[i] = {};         for k = 1, maze.columns do             gridGame[i][k] = display.newImage(image)                  gridGame[i][k].yScale=0.35             gridGame[i][k].xScale=0.35             gridGame[i][k].alpha = 1             gridGame[i][k].x = (k - 1) \* (rectx + space) + spaceleft             gridGame[i][k].y = (i - 1) \* (recty + space) + spacetop                      end         end

It’s not really clear what you’re trying to do and what is going wrong…

i would simply assign an image to letter x and another image for w.

i try an another way but always without success

local widthscreen =320 local heightscreen =480 local space = 2 local rectx = 0.35 local recty = 0.35 local spaceleft =40 local spacetop = 20 local maze = {         { 1, 2, 1 },         { 2, 2, 2 },         { 2, 1, 2 },         { 2, 2, 1 },         { 1, 1, 2 },         { 2, 2, 1 },         { 1, 1, 1 },         { 2, 1, 1 },         { 2, 2, 1 },         { 2, 1, 2 },         { 2, 1, 2 },         { 1, 2, 1 },     }     maze.rows = table.getn(maze)     maze.cells = table.getn(maze[1])    local gridGame = {}     for i = 1, maze.rows do         gridGame[i] = {};         for k = 1, maze.cells do             if gridGame[i][k] == 2 then             im = display.newImage("icone.png")             end             if gridGame[i][k] == 1 then             im = display.newImage("bulle2.png")             end                 gridGame[i][k] = im             gridGame[i][k].yScale = 0.35             gridGame[i][k].xScale = 0.35             gridGame[i][k].x = (k - 1) \* (rectx + space) + spaceleft             gridGame[i][k].y = (i - 1) \* (recty + space) + spacetop                      end         end

I don’t want to step on Nick, but what you’re asking for seems to be very specific to your own implementation, so unless you explain exactly what you are attempting to achieve, saying “I want a space between each cell” isn’t helping us to help you.

Do you want additional cells to represent the space? Do you just want a specific number of pixels as space between each cell? I’m guessing it’s the later, but without knowing what exactly isn’t working, it’s difficult for us to suggest something  does work.

If you could provide more details, images and code explaining what you want to happen and what is happening now, it would help us to help you.

hi with this code i make a regular grid with 9 images on 14 separated  by a space

local gridGame = {} local row = 9 local cell = 14 local rectx = 30 local recty = 30 local gridscaley = 0.35 local gridscalex = 0.35 local space = 2 local spaceleft =40 local spacetop = 20 local divx=widthscreen/(row\*2) local divy=heightscreen/(cell\*2)     for i = 1, cell do         gridGame[i] = {};         for k = 1, row do             gridGame[i][k] = display.newImage("dalle.png")             gridGame[i][k].yScale=0.35             gridGame[i][k].xScale=0.35             gridGame[i][k].alpha = 1             gridGame[i][k].x = (k - 1) \* (rectx + space) + spaceleft             gridGame[i][k].y = (i - 1) \* (recty + space) + spacetop                  end end

but i want to have a non regular grid with for example  : empty cells and cells filled

so if could represent my grid with a succesion of 0 and 1 it’ would be easy

0 1 0

1 0 0

1 0 0

1 1 1

have you understand ?

i want to do this

mini_140821101423172488.jpg

Something like this?

[lua]

local grid = {}

local gridGame = {}

grid[1] = {0, 0, 1, 0}

grid[2] = {1, 0, 1, 1}

grid[3] = {0, 0, 0, 1}

grid[4] = {1, 0, 0, 1}

local row = #grid

local cell = #grid[1]

local rectx = 30

local recty = 30

local gridscaley = 0.35

local gridscalex = 0.35

local space = 2

local spaceleft =40

local spacetop = 20

local divx=widthscreen/(row*2)

local divy=heightscreen/(cell*2)

for i = 1, row do

  gridGame[i] = {};

    for k = 1, cell do

      if grid[i][k] == 1 then

        gridGame[i][k] = display.newImage(“dalle.png”)

        gridGame[i][k].yScale=0.35

        gridGame[i][k].xScale=0.35

        gridGame[i][k].alpha = 1

        gridGame[i][k].x = (k - 1) * (rectx + space) + spaceleft

        gridGame[i][k].y = (i - 1) * (recty + space) + spacetop

      else

            – cell is blank, do something else

      end

    end

end

[/lua]

To piggyback on Nick’s suggestion, I’d suggest checking out the adapted A* tutorial which has some grid logic built in. I am pointing you to this because it includes information on moving images around a rudimentary “map” which I think would prove useful to you.

thank you guys…it’s truly what i’m looking for :smiley:

hi,

I have an another question about the use of the grid.

For you what is the best way to have a pseudo infinite grid like the concept of flappy bird ?

  • put a big number for the row and cell ?

or

  • make a mini grid and duplicate this grid x number ?

If you have a snippet under the hand it would be cool.

I don’t really ever have a need to generate an infinite grid. If you could give us a bit more detail about what you’re attempting to accomplish, we might be able to suggest some options.

i think of something like that with the perspective.lua to move my grid 

it is clear that this is a representation because my grid should be even higher

mini_14082609274313855.jpg

anybody ? please

i try this but without success

local gridGame = {} local widthscreen =320 local heightscreen =480 local row = 24 local cell = 12 local rectx = 30 local recty = 30 local gridscaley = 0.35 local gridscalex = 0.35 local space = 2 local spaceleft =40 local spacetop = 20 local divx=widthscreen/(row\*2) local divy=heightscreen/(cell\*2) local maze = {         { x, x,  },         { x, w,  },         { x, x,  },         { x, w,  },         { x, x,  },         { x, w,  },         { x, w,  },         { x, w,  },         { x, w,  },         { x, w,  },         { x, w,  },         { x, w,  },     }     maze.rows = table.getn(maze)     maze.columns = table.getn(maze[1])     maze.xStart, maze.yStart = 1, 100     maze.xFinish, maze.yFinish = 24, 7     maze.object = x or w      if maze.object == x then         image="dalle9.png"     end     if maze.object == w then         image="dalle1.png"     end         for i = 1, maze.rows do         gridGame[i] = {};         for k = 1, maze.columns do             gridGame[i][k] = display.newImage(image)                  gridGame[i][k].yScale=0.35             gridGame[i][k].xScale=0.35             gridGame[i][k].alpha = 1             gridGame[i][k].x = (k - 1) \* (rectx + space) + spaceleft             gridGame[i][k].y = (i - 1) \* (recty + space) + spacetop                      end         end

It’s not really clear what you’re trying to do and what is going wrong…

i would simply assign an image to letter x and another image for w.

i try an another way but always without success

local widthscreen =320 local heightscreen =480 local space = 2 local rectx = 0.35 local recty = 0.35 local spaceleft =40 local spacetop = 20 local maze = {         { 1, 2, 1 },         { 2, 2, 2 },         { 2, 1, 2 },         { 2, 2, 1 },         { 1, 1, 2 },         { 2, 2, 1 },         { 1, 1, 1 },         { 2, 1, 1 },         { 2, 2, 1 },         { 2, 1, 2 },         { 2, 1, 2 },         { 1, 2, 1 },     }     maze.rows = table.getn(maze)     maze.cells = table.getn(maze[1])    local gridGame = {}     for i = 1, maze.rows do         gridGame[i] = {};         for k = 1, maze.cells do             if gridGame[i][k] == 2 then             im = display.newImage("icone.png")             end             if gridGame[i][k] == 1 then             im = display.newImage("bulle2.png")             end                 gridGame[i][k] = im             gridGame[i][k].yScale = 0.35             gridGame[i][k].xScale = 0.35             gridGame[i][k].x = (k - 1) \* (rectx + space) + spaceleft             gridGame[i][k].y = (i - 1) \* (recty + space) + spacetop                      end         end