Thank you both, very helpful and I believe I am starting to grasp the very basics of tables. Maybe.
Here is my new code, table now working and it displays the boxes great!!! I have started working on the collision detection using if statements to check the area around each tile. Only done one tile to test it now but it’s not working yet, I figure I’m very close and going to keep working at it.
-- Break
-- Use this function to perform your initial setup
displayMode(FULLSCREEN)
supportedOrientations(LANDSCAPE_ANY)
function setup()
xpos=512
ballx=512
bally=450
e1=physics.body(EDGE,vec2(0,0),vec2(0,HEIGHT))
e2=physics.body(EDGE,vec2(0,HEIGHT),vec2(WIDTH,HEIGHT))
e3=physics.body(EDGE,vec2(WIDTH,0),vec2(WIDTH,HEIGHT))
ball_diam=30
p_ball = physics.body(CIRCLE,ball_diam/2)
p_ball.gravityScale = 1
p_ball.restitution = .8
p_ball.friction = 0
p_ball.linearVelocity = vec2(math.random(400),math.random(400))
p_ball.x = math.random(75,150)
p_ball.y = math.random(450,650)
--add bat
bat=physics.body(EDGE,vec2(-70,109),vec2(70,109))
bat.gravityScale = 1
bat.restitution = 1.2
bat.friction = 0
-- configure boxes
tiles={}
for box = 1, 10 do
table.insert(tiles,vec2(250+box*42,600))
end
end
function draw()
-- define screen space and add collision detection
strokeWidth(5)
background(40,40,50)
color(255)
line(0,0,0,HEIGHT) -- draw left wall
line(0,HEIGHT,WIDTH,HEIGHT) -- draw top wall
line(WIDTH,0,WIDTH,HEIGHT) -- draw right wall
-- set bat screen limits and collision
xpos=CurrentTouch.x
if xpos<=77 then xpos=78
elseif xpos>=948 then xpos=945
end
bat.x=xpos
sprite("Planet Cute:Plain Block",xpos,100,150,55) -- bat
-- add ball and move towards bat
sprite("Tyrian Remastered:Explosion Ball",p_ball.x,p_ball.y,30,30) -- ball
if p_ball.y <= 75 then
text("Ball Lost",350,350) -- placeholder for lost ball
end
for box=1,10 do -- draw first row of boxes
sprite("Cargo Bot:Crate Green 1",275+box*42,600)
end
-- box collision and removal
if p_ball.x>=317 and p_ball.x<=359 and p_ball.y>=599 and p_ball.y<=641 then -- tile 1 approx bounding box
table.remove(tiles,1)
end
end