Collision behavior

After this, we define what exactly will happen if there is a collision between two objects, which is defined in our update() method. We also address the situation if the rocks go out of the screen:

long rockElapsed = (System.nanoTime() - rockStartTime/1000000);if(rockElapsed>(2000 - playerCharacter.getScore())){    if(rocks.size() == 0){        rocks.add(new Rock(BitmapFactory.decodeResource        (getResources(), R.drawable.rock),         WIDTH+10, HEIGHT/2, 66, 82,         playerCharacter.getScore(),3));    } else {        rocks.add(new Rock(BitmapFactory.decodeResource        (getResources(), R.drawable.rock),         WIDTH+10, (int) (rnd.nextDouble() * (HEIGHT)), 66, 82,                   playerCharacter.getScore(),3));    }    rockStartTime = System.nanoTime();}for(int i=0; i<rocks.size();i++) ...

Get Learning Android Game Development now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.