Creating a new game

We will create a newGame() function that will get called every time the player crashes with an object. We're doing nothing, but just resetting our objects as they were initially when we started the game. So, here's how we do it:

public void newGame () {    lowerBoundary.clear();    upperBoundary.clear();    rocks.clear();    minBoundaryHeight = 5;    maxBoundaryHeight = 30;    playerCharacter.resetScore();    playerCharacter.resetDYC();    playerCharacter.setYC(HEIGHT/2);    for(int i = 0; i * 20 < WIDTH + 40;i++) {        if(i == 0) {            upperBoundary.add(new            UpperBoundary(BitmapFactory.decodeResource            (getResources(),R.drawable.ground),            i * 20, 0, 10));        } else {            upperBoundary.add(new            UpperBoundary(BitmapFactory.decodeResource (getResources(),R.drawable. ...

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.