Detecting a collision between the ground and player

Since we have already created our collision method, we simply go ahead and use the function. We already have a clear understanding of how a collision works because of the previous chapter, so we write the following code in our update() method of our file:

for(int i=0; i<lowerBoundary.size();i++) {    if(collision(lowerBoundary.get(i),playerCharacter)) {        playerCharacter.setPlaying(false);    }}for(int i=0; i<upperBoundary.size();i++) {    if(collision(upperBoundary.get(i),playerCharacter)) {        playerCharacter.setPlaying(false);    }}

Collision detection between the player and the ground is completed. Now, we also have to assign our maximum and minimum boundary heights as well as tweak them ...

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.