Vigyata.AI
Is this your channel?

CODE WITH ME | Python Snake Game

183.7K views· 6,310 likes· 15:36· Feb 1, 2024

🛍️ Products Mentioned (2)

Hope you enjoy this *chaotic* coding video :) get 15% off with code *CSJackie15* and apply today to Code Chrysalis’s Immersive Coding School in Tokyo: https://bit.ly/CSJackieCodeChrysalis 🤓 about I’m a software engineer based in London with a background in mechanical and aerospace engineering. Most of my time is spent reading, coding and drinking too much coffee. I got into coding by automating simulation workflows and building EdgeSheet.com, and now I’m documenting my life as an engineer on the internet. Thanks for watching! :) 📝 chapters 0:00 intro 0:34 pygame 1:45 data structures 3:02 creating the playground & snake 4:58 code chrysalis 5:58 creating the target 7:12 coding the snake movement 10:27 coding the snake and target interaction 13:11 boundary conditions 15:00 outro 📝 contact info@csjackie.com 🎵 music the music in my videos comes from: https://share.epidemicsound.com/5swi7a 👀 disclaimer Views and opinions are my own and do not represent or reflect the opinions of my current or past employer(s). This video is sponsored by Code Chrysalis. 🏷 hashtags & video content Software engineer, snake game, python snake game, pygame, code with me, coding vlog, coding video, programming, software engineering, developing software, pandas, data structures and algorithms #codewithme #pythonprogramming #softwareengineer

About This Video

When you work a full-time software engineering job, sometimes the last thing you want to do after work is… more coding. But lately I’ve been trying to make coding fun again, so in this (slightly chaotic) Saturday evening “code with me”, I build a classic Python Snake Game — yes, the Nokia 3310 one — using pygame. I start from a basic pygame template (we love a purple window moment… until I immediately change it to black because who is gaming on purple), then I talk through the data structures I’m using: a rectangle “playground”, a target/food pixel with an (x, y) tuple, and a snake that’s basically a list of pixels that grows as it eats. From there I implement movement with WASD, learn the difference between move vs move_ip (in-place), and debug a bunch of very real problems: random spawns appearing off-screen, my width/height logic being wrong (I literally just make the screen a square to stop overcomplicating it), and the classic “I’m moving a snake that I’m not drawing” bug. Then I code the interaction logic so the snake grows when it hits the target and the target respawns, and I add boundary conditions to reset the game when you hit the edge (including remembering to reset snake length). It’s not fully finished — self-collision is an edge case — but I upload the code to GitHub so you can clone it and play around.

Frequently Asked Questions

🎬 More from CS Jackie