Snake Game Python Tutorial



Learn to code a snake game using Python and Pygame.

This is suited for intermediate level programmers with some experience but anyone is welcome to follow along.

If you are unsure about how to install/download pygame checkout this link: https://www.youtube.com/watch?v=AdUZArA-kZw

Download the code: https://pastebin.com/embed_js/jB6k06hG

Tutorial from Tech With Tim.
Check out Tim’s channel: https://www.youtube.com/channel/UC4JX40jDee_tINbkjycV4Sg

Learn to code for free and get a developer job: https://www.freecodecamp.org

Read hundreds of articles on programming: https://medium.freecodecamp.org

And subscribe for new videos on technology every day: https://youtube.com/subscription_center?add_user=freecodecamp

source

This Post Has 29 Comments

  1. Faiq Ali

    Can anyone tell me which algorithms are used in this CSP snake game??????? Urgent

  2. Tyler Martin

    I have the same code but my window won’t open on pycharm. No errors, does anyone know why the window won’t open?

  3. David Hearn

    34:24: When I tried to run it, the snake would move toward the right, but as soon as I hit an arrow key, it displays this error:

    self.turns[self.head.pos[:]] = [self.dirnx, self.dirny]
    TypeError: 'tuple' object does not support item assignment

    I gained an understanding of most of the tutorial by giving verbose, meaningful names to all of the variables, but that error seems to be a show-stopper.

  4. hiedral

    9:57
    sorry this not anything important just a reference for me.

  5. Nouman Abidi

    in drawGrid() why are we using 'w', instead of 'width'

  6. jessicalin85

    I have trouble downloading Pygame… I tried all the ways online to download it, but there is no way…

  7. Tamara Savadyan

    Hey, Tim! I love your tutorials, but it's realy hard to understand what's going on, when u don't have HALF of code(
    When you don't have cube class and all it's functions, but still using them
    It made me cry, please don't make me cry next time!
    I'll appreciate it

  8. Arenite

    raceback (most recent call last):

    line 5, in <module>

    import pygame

    ModuleNotFoundError: No module named 'pygame'

  9. Teresa Lima

    hey! so I've tried to recreate and follow your video but when I try to run it, the game window doesn't show up to me. Is there any possibility for you to help me? Thanks!

  10. ethan ungerboeck

    very nice keyboard 🙂 love mechanical shiz, it doesnt sound lubed tho and its 2 years after post remember to lube 🙂

  11. Pedro Gamer

    this is literally the only tutorial on the internet that works

  12. MistralKriss

    Ok first time doing Python for me. TBH I didnt understand at all how movement is handled. Yes it works but really I dont like much the explanations. (saying hum yea that's how i's done, is not a valid explanation imo)

  13. Natalie :3

    In the code in the def main(): section it keeps saying while is a syntax error. Plus someone help me

  14. Jhayda Johnson

    My pygame doesn't work on my laptop and I can't run the game to see if I'm following along correctly

Leave a Reply