Use a for loop from 1 to 2 to create each player the same if you need. Then change each players specifically different data, like location on screen if you need to. i.e.:
for i = 1, #player do
if player[i].state == "jumping" then
player[i].y = player[i].y + player[i].y_vel * dt
player[i].y_vel = player[i].y_vel + gravity * dt
if player[i].y + player[i].h > floor.y then
player[i].y = floor.y - player[i].h
player[i].state = "idle"
player[i].y_vel = player[i].y_vel_base
end
end
end
A benefit is you can add more players easily since #player returns the index count of the player table's children.
Use a for loop from 1 to 2 to create each player the same if you need. Then change each players specifically different data, like location on screen if you need to. i.e.:
for i = 1, #player do
if player[i].state == "jumping" then
player[i].y = player[i].y + player[i].y_vel * dt
player[i].y_vel = player[i].y_vel + gravity * dt
if player[i].y + player[i].h > floor.y then
player[i].y = floor.y - player[i].h
player[i].state = "idle"
player[i].y_vel = player[i].y_vel_base
end
end
end
A benefit is you can add more players easily since #player returns the index count of the player table's children.
oh wow I was actually pretty close with some of my tries LOL I just didn't index the player when initialising them :S