Search code examples
javascripthtmlhtml5-canvasgame-physics

HTML5 game freezes in browser


I'm trying to develop a game (Spaceship and Rocks) using only HTML5 and pure JavaScript. But the game is freezing unexpectedly. Everything works fine before Spawning the rocks in CANVAS. I'm not able to rectify the problem.
here's my game in codepen:
http://cdpn.io/vJaoi

update:

I've updated the code for the previous question

But the missile sprites when collide with the rocks, the rocks are popping out unevenly.

Any suggestions on colliding the roks and missiles. Or better algorithms for collision detection in groups of sprites.


Solution

  • This loop never ends :)

        while (distance < 100){
            rock_pos = [random(0, WIDTH), random(0, HEIGHT)];
        }
    

    distance is never incremented