Some kind of runner

Hi kind community , i have some problems with the algorithm of appearance my white bricks in black field. Il explain this.
This how it looks now

And this how i expect it would like (photoshoped)

White blocks must appear in the right of the screen and go to the left , replacing black bricks.
There is my code :

 Field = class()
function Field:init()
    -- you can accept and set parameters here
    self.field = {}
    self.posrand = {}

    self.w = 10
    self.h = 3
  self.bpos = HEIGHT/2
    
end


function Field:draw()
    -- Codea does not automatically call this method
    
    for x = 1,self.w do
        self.field[x] = {}

        for y = 1,self.h do
-- i dont know how, but this makes bricks stand up like a field
            self.field[x][y] = vec2(x*110-55,150+y*110)

        table.insert(poslimit,self.field[x][y])
        end
    
    pushStyle()
    for k,v in pairs(self.field[x]) do
    sprite("Documents:ColorunBrickBlackSharp",v.x,v.y,1024/4,768/4)
    
    end 
    popStyle()
    end    
end    



function Field:touched(touch)
    -- Codea does not automatically call this method
end

Simple example would be useful too

@dave1707 THANK YOU! Dave, you are amazing!

@Ignatz, thank you for respond.

  1. I dont want mess up Main class

  2. didnt understand what you want to say

  3. white blocks appears (randomly) in the right and go to the left, every block must contact with previous block. Then white blocks moves to the right, they moves above black blocks, so white blocks makes path, where you run (you can see what i mean in the top of the post)

  4. I think both of this solutions would be good

@lupino8211 Is this what you’re after. Tap above the squares to move the circle up. Tap below to move it down. The circle changes color from green to red if it lands on a black square. You can change the speed with the parameters slider. A lower value increases the speed of the squares.


displayMode(FULLSCREEN)
supportedOrientations(LANDSCAPE_ANY)

function setup()
    rectMode(CENTER)
    parameter.integer("speed",10,120,45)
    tab={}
    size=40
    for x=1,size do
        tab[x]={}
        for y=1,3 do
            tab[x][y]=0
        end
    end
    x=1
    y=2
    tab[x][y]=1
    while x<size do
        path()
    end
    count=0
    playerX=1
    playerY=2
end
    
function draw()
    background(79, 140, 149, 255)
    fill(0)
    count=count+1
    for y1=1,3 do
        for x1=1,size do
            if tab[x1][y1]==0 then
                fill(0)
            else
                fill(255)
            end
            rect((x1)*50,300+y1*50,48,48)
        end
    end
    if count>speed then
        count=0
        if nextCol then
            for z=1,size-1 do
                tab[z][1]=tab[z+1][1]
                tab[z][2]=tab[z+1][2]
                tab[z][3]=tab[z+1][3]
            end
            tab[size][1]=0
            tab[size][2]=0
            tab[size][3]=0  
            x=x-1 
        end
    end
    if x<size then
        path()
    end
    fill(0,255,0)
    if tab[playerX][playerY]~=1 then
        fill(255,0,0)
    end
    ellipse(playerX*50,300+playerY*50,30)
end

function path()
    local x1
    local y1
    done=false
    nextCol=false
    while not done do
        local p=math.random(3)
        if p==1 then
            x1=x
            y1=y+1
        end
        if p==2 then
            x1=x+1
            y1=y
        end
        if p==3 then
            x1=x
            y1=y-1
        end
        if y1>0 and y1<4 then
            if tab[x1][y1]==0 then
                tab[x1][y1]=1
                done=true
                x=x1
                y=y1
                if p==2 then
                    nextCol=true
                end
            end
        end
    end
end

function touched(t)
    if t.state==BEGAN then
        if t.y>300 then
            playerY=playerY+1
            if playerY>3 then
                playerY=3
            end
        else
            playerY=playerY-1
            if playerY<1 then
                playerY=1
            end
        end        
    end
end

@lupino8211 - why are you using a class, when you will only ever have one table of blocks?

Where is the code that uses this class?

What is the rule for making white blocks?

Do you want the blocks to be removed when they reach the left, to be replaced by new blocks on the right?

PS Please indent your code properly so it is easier to read!!

Help, please