Bouncy a Ball Test!

Hey guys I made a bouncy ball simulator thing. I am quite new to Lua and my friend seth is teaching me things. If you have anything to reference me to to get better please leave a comment. Anyways, because I still don’t know how to make a collisions detection this runs completely off of y values. The code is below and please comment about waht you think or any feedback about learning. Thanks! :smiley:

--# Main
function setup()
    --This is were I select speed and y values, but because I am a stupid I need to make multiple Y ans Speed values.
    y = 100
    y1 = 100
    y2 = 100
    y3 = 100
    y4 = 100
    y5 = 100
    y5 = 100

    sped = 1
    sped1 = 2
    sped2 = 3
    sped3 = 4
    sped4 = 5
   
    displayMode(FULLSCREEN)
    supportedOrientations(LANDSCAPE_RIGHT)
end

function draw()
    --This function here is for dev purposes, to keep track of all y values.
    print (y,y1,y2,y3,y4,y5)
    --Here I re-state the Y values and add speed to them so they can move.
    y = y+sped
    y1 = y1+sped1
    y2 = y2+sped2
    y3 = y3+sped3
    y4 = y4+sped4
    

    --Here I make the circles that bounce!
    background(40,40,40)
    ellipse(100,y,100,100)
    ellipse(300,y1,100,100)
    ellipse(500,y2,100,100)
    ellipse(700,y3,100,100)
    ellipse(900,y4,100,100)
    
    --Down here is where things get tricky, I needed to make an "If Then" statement for each ball to ensure it won't leave the screen.
    if y >= 700 then sped = -sped end
    if y < 50 then sped = -sped end
    
    if y1 >= 700 then sped1 = -sped1 end
    if y1 < 50 then sped1 = -sped1 end
    
    if y2 == 700 then sped2 = -sped2 end
    if y2 < 50 then sped2 = -sped2 end  
    
    if y3 == 700 then sped3 = -sped3 end
    if y3 < 50 then sped3 = -sped3 end  
    
    if y4 == 700 then sped4 = -sped4 end
    if y4 < 50 then sped4 = -sped4 end  
      
    fill(255, 7, 0, 255)
end 

Sorry it didn’t paste too well guys

@Kai As I said in your other post, put 3~'s on a line before and after your code. I suggest you look at the Wiki link at the top of the forum. You’ll find plenty of information there.

@dave can you tell me how to fix the resetting of the tap count?

@dave1707 on the other program I mean

@Kai Here your above code using tables that you’ll eventually learn about.

displayMode(FULLSCREEN)
supportedOrientations(LANDSCAPE_ANY)

function setup()
    balls={100,100,100,100,100}
    speed={1,2,3,4,5}
    fill(255,0,0)
end

function draw()
    background(0)
    for a=1,#balls do
        ellipse(a*175,balls[a],100)
        balls[a]=balls[a]+speed[a]
        if balls[a]>700 or balls[a]<50 then
            speed[a]=-speed[a]
        end
    end   
end

Thanks I hope I will get there soon :smiley:

Oh I see what you have done, I don’t understand how you did the different speeds