title: snake does not catch the fruit when i increase the snake_block to 20. I don’t understand what code should I change
body: <p>I’m new in python and have used pygame to make this snake game. But it lacks when i increase the snake_block and keep it as 20. The snake does not eat the fruit. It works well when the snake_block is 10. I tried to find the solution but didn’t find any... Also want know how can i add highscore and levels to this game.
  Here is source code:</p>
  <pre><code>#importing libraries
  import pygame
  import time
  import random
  
  #initialising pygame 
  pygame.init()
  
  #defining colors
  white = (255, 255, 255)
  yellow = (255, 255, 102)
  black = (0, 0, 0)
  red = (213, 50, 80)
  green = (0, 255, 0)
  blue = (50, 153, 213)
  
  #size of game window
  dis_width = 1200
  dis_height = 700
  
  #initialising game window 
  dis = pygame.display.set_mode((dis_width, dis_height))
  pygame.display.set_caption('Snake Game by Sakshi')
  
  #track time
  clock = pygame.time.Clock()
  
  snake_block = 10
  snake_speed = 10
  
  direction = &quot;right&quot;
  snake_List = []
  Length_of_snake = 1
  
  #creating font object for score
  font_style = pygame.font.SysFont(&quot;bahnschrift&quot;, 25)
  score_font = pygame.font.SysFont(&quot;comicsansms&quot;, 25)
  font_width = 0
  font_height = 0
  
  #sound effects
  game_over_sound = pygame.mixer.Sound(&quot;./sounds/game_over1.wav&quot;)
  food_ate_sound = pygame.mixer.Sound(&quot;./sounds/food_eaten.wav&quot;)
  
  #defining score
  def Your_score(score):
      value = score_font.render(&quot;Your Score: &quot; + str(score * 5), True, yellow)
      dis.blit(value, [0, 0])
  
  #defining snake 
  def our_snake(snake_block, snake_list):
      for x in snake_list:
          pygame.draw.rect(dis, black, [x[0], x[1], snake_block, snake_block])
   
  #defining message to be printed on screen
  def message(msg, color):
      mesg = font_style.render(msg, True, color)
      dis.blit(mesg, [dis_width / 6, dis_height / 3])
  
  #defining pause function    
  def pause():
      paused = True
      message(&quot;Game is Paused. Press 'C' to continue or 'Q' to quit&quot;,white)
  
      # updates the screen
      pygame.display.update()
      while paused:
          for event in pygame.event.get():
              if event.type == pygame.QUIT:
                  print(&quot;here&quot;)
                  pygame.quit()
                  quit()
              if event.type == pygame.KEYDOWN:
                  if event.key == pygame.K_c:
                      paused = False
                  elif event.key == pygame.K_q:
                      pygame.quit()
                      quit()
  
          #gameDisplay.fill(white)
          clock.tick(5) 
  
  #defining gameloop
  def gameLoop():
  
      game_over = False
      game_close = False
      game_start = False
  
      #snake dimensions
      x1 = dis_width / 2
      y1 = dis_height / 2
   
      x1_change = 0
      y1_change = 0
  
      # direction
      direction = 'RIGHT'
      change_to = direction
  
      snake_List = []
      Length_of_snake = 1
  
  
      foodx = round(random.randrange(0, dis_width - snake_block) / 10.0) * 10.0
      foody = round(random.randrange(0, dis_height - snake_block) / 10.0) * 10.0
  
      while not game_over:
          change_direction = False
  
          while game_close == True:
              dis.fill(blue)
              #message(&quot;You Lost! Press C-Play Again or Q-Quit&quot;, red)
              value = score_font.render(&quot;Your Score: &quot; + str((Length_of_snake - 1) * 5), True, yellow)
              dis.blit(value, [dis_width / 6, dis_height / 3])
              value = score_font.render(&quot;You Lost! Press C-Play Again or Q-Quit&quot;, True, yellow)
              dis.blit(value, [(dis_width / 6), (dis_height / 3)+30])
              pygame.display.update()
              
              for event in pygame.event.get():
                  if event.type == pygame.KEYDOWN:
                      if event.key == pygame.K_q:
                          game_over = True
                          game_close = False
                      if event.key == pygame.K_c:
                          gameLoop()
   
          for event in pygame.event.get():
  
              #handling key events
              if event.type == pygame.KEYDOWN:
                  if event.key == pygame.K_UP:
                      change_to = 'UP'
                  if event.key == pygame.K_DOWN:
                      change_to = 'DOWN'
                  if event.key == pygame.K_LEFT:
                      change_to = 'LEFT'
                  if event.key == pygame.K_RIGHT:
                      change_to = 'RIGHT'
                  if event.key == pygame.K_p:
                      paused = True
                      pause()
                  if event.key == pygame.K_q:
                      sound_effect = pygame.mixer.Sound(game_over_sound)
                      sound_effect.play()
                      pygame.time.delay(1000)
                      pygame.quit()
                      quit()
              if event.type == pygame.QUIT:
                  game_over = True
  
          #Don't want snake to move in same direction simultaneously
          if change_to == 'UP' and direction != 'DOWN':
              direction = 'UP'
          if change_to == 'DOWN' and direction != 'UP':
              direction = 'DOWN'
          if change_to == 'LEFT' and direction != 'RIGHT':
              direction = 'LEFT'
          if change_to == 'RIGHT' and direction != 'LEFT':
              direction = 'RIGHT'
  
          #moving the snake
          if direction == 'UP':
              y1_change = -snake_block
              x1_change = 0
          if direction == 'DOWN':
              y1_change = snake_block
              x1_change = 0
          if direction == 'LEFT':
              x1_change = -snake_block
              y1_change = 0
          if direction == 'RIGHT':
              x1_change = snake_block
              y1_change = 0
  
  
          if x1 &gt;= dis_width or x1 &lt; 0 or y1 &gt;= dis_height or y1 &lt; 0:
              sound_effect = pygame.mixer.Sound(game_over_sound)
              sound_effect.play()
              pygame.time.delay(1000)
              game_close = True
              
          x1 += x1_change
          y1 += y1_change
          dis.fill(blue)
          pygame.draw.rect(dis, green, [foodx, foody, snake_block, snake_block])
          #dis.blit((foodx, foody))
          snake_Head = []
          snake_Head.append(x1)
          snake_Head.append(y1)
          snake_List.append(snake_Head)
          if len(snake_List) &gt; Length_of_snake:
              del snake_List[0]
   
          for x in snake_List[:-1]:
              if x == snake_Head:
                  game_close = True
          
          our_snake(snake_block, snake_List)
          Your_score(Length_of_snake - 1)
          
          pygame.display.update()
          #when snake eats the food
          #print(foodx, foody,snake_block,x1, y1 )
          if x1 == foodx and y1 == foody:
              foodx = round(random.randrange(0, dis_width - snake_block) / 10.0) * 10.0
              foody = round(random.randrange(0, dis_height - snake_block) / 10.0) * 10.0
              Length_of_snake += 1
              sound_effect = food_ate_sound.play()
              pygame.time.delay(100)
   
          clock.tick(snake_speed)
   
      pygame.quit()
      quit()
      
  def start_game():
      while True:
          dis.fill(red)
          value = score_font.render(&quot;Welcome to the Snake Game&quot;, True, yellow)
          dis.blit(value, [dis_width / 10, dis_height / 3])
          value = score_font.render(&quot;Game Rules are:&quot;, True, yellow)
          dis.blit(value, [dis_width / 10, (dis_height / 3)+30])
          value = score_font.render(&quot;Press 'S' to Start, 'C' to continue and 'P' to Pause&quot;, True, yellow)
          dis.blit(value, [dis_width / 10, (dis_height / 3)+60])
          value = score_font.render(&quot;Press left, right, up and down arrow keys to move left, right, up and down respectively&quot;, True, yellow)
          dis.blit(value, [dis_width / 10, (dis_height / 3)+90])
          value = score_font.render(&quot;Press 'Q' to quit&quot;, True, yellow)
          dis.blit(value, [dis_width / 10, (dis_height / 3)+120])
          
          for event in pygame.event.get():
              if event.type == pygame.KEYDOWN:
                  if event.key == pygame.K_s:
                      gameLoop()
                  '''elif event.key == pygame.K_q:
                      pygame.quit()
                      quit()
                  elif event.key == pygame.K_p:
                      paused = True
                      pause()'''
  
          pygame.display.update()
  
  start_game()
  #for event in pygame.event.get():
      #if event.key == 'S' or event.key == 's':
  #gameLoop()
  </code></pre>