merged setInterval logic into the main game loop