Snake and apple game in python pygame - 5. Snake eats apple, find score | Python project tutorial -

Snake and apple game in python pygame – 5. Snake eats apple, find score | Python project tutorial

Views: 7801
Like: 64
In this pygame tutorial video we will build a logic for snake eating an apple and calculate the score. We will write a collision detection function which will find out of two rectangles overlap each other or not and if they do than increase the score. This video is part of snake and apple game series in pygame.

Final code for complete game:

Hindi playlist for this snake game: –
English playlist for this snake game:

Python tutorials (first 16):
Python Hindi tutorials (first 16):

Do you want to learn technology from me? Check for my affordable video courses.


DISCLAIMER: All opinions expressed in this video are of my own and not that of my employers’.


  1. In previous sessions, we learnt to move the snake, and in order to do that, the code was: if self.direction == 'up':
    self.y[0] -= SIZE
    if self.direction == 'down':
    self.y[0] += SIZEwhich made me think the Y axis is inverted from the traditional maths axis, and the coordinate (0,0) belongs in the UPPER left corner of the screen, since we are detracting size to move up, and adding size to move down.Now, in the collision thread of this session: if y1 >= y2 and y1 <= y2 + SIZE:
    return Truey1 is the upper line of the box that belongs to the apple, and y2 is the bottom one, and since the condition y1>=y2 is met, now this make me thinks that we are back to the original behaviour of the axis, being the coordinate (0,0) the BOTTOM left corner. This is driving me crazy, can someone explain why this works like that? PS: Great job love your channel it's gonna be a beautiful learning journey!

  2. As I understood it:

    y1 = snake head's upper line, x1 = snake head's left line

    y2 = apple's upper line, x2 = apple's left line

    Please correct me if I am wrong

    And of course, many thanks for the videos you are creating 🙂

Leave a Reply

Your email address will not be published.