0

So i thought of this algorithm that consists of creating a counter that adds to itself the block size of a rect object + 1 and then draws another rect using the lead_x + counter. What this would do is that it would constantly add another block to the outermost side of the snake. But for some reason it's not working. Any explanation as to why and how I can make it work would leave me extremely grateful. Best of wishes.

if rectangle.colliderect(rectangle2):
    counter += block_size + 1
    lead_x2 = randint(100, 700)
    lead_y2 = randint(100, 500)
    velocity += 0.000002

    pygame.draw.rect(gameDisplay, black, [lead_x + counter, lead_y, block_size, block_size])
    pygame.draw.rect(gameDisplay, red, [lead_x2, lead_y2, block_size, block_size])

    message_to_screen("You ate an apple.", red)
skrx
  • 19,980
  • 5
  • 34
  • 48
Lol Lol
  • 155
  • 1
  • 9
  • 2
    It's not really clear what you want to achieve. Please describe your goals and issues in detail. Perhaps an image would help. – skrx Aug 30 '18 at 06:19
  • 1
    The problem is that you don't need to *add* a block, you just need to *not* remove one when moving. When the snake moves what you do is removing the last block (a piece of the "tail") and add one at the head in the direction of the last keypress. If you just add one at the head without removing it from the tail, you'll have a longer snake. – ChatterOne Aug 30 '18 at 14:49
  • Check out this answer on GameDev SE https://gamedev.stackexchange.com/a/33789/104257 Pretty much any game development question you need to ask will be there. – mustachioed Aug 30 '18 at 20:38

0 Answers0