Python Snake Game With Pygame - Create Your First Pygame Application

preview_player
Показать описание
Implement the famous Snake game in this beginner tutorial and learn how to get started with pygame. Build your first pygame application and learn how to implement the game loop, how to display objects with pygame, and how to implement the game logic. Along the way I also show some nice Python features like Enum and namedtuple.

🚀🚀 Get monthly Python and ML Tips:

🚀🚀 SUPPORT ME ON PATREON:

If you enjoyed this video, please subscribe to the channel!

You can find me here:

#Python

----------------------------------------------------------------------------------------------------------
* This is a sponsored or an affiliate link. By clicking on it you will not have any additional costs, instead you will support me and my project. Thank you so much for the support! 🙏
Рекомендации по теме
Комментарии
Автор

Oh my god dude. you cannot keep making quality content like this. You'll be the number one YouTuber at this rate and people are going to come after you! You deserve so many subs. I'm sharing your channel with my friends. Keep up the amazing work! I cant wait for the next one! Machine Learning sounds so exciting!

ciscoserrano
Автор

Here is some help if your first Python project like me.

At 1:26 Make a new folder on your desktop. With command prompt type cd with the location name of the file. Example: "cd C:\Users\admin\Desktop\Snake"

To use conda there is a tutorial link in video, but I did it different. I searched for "anaconda python 3.7" to get the same version as this video. Installed anaconda and then used their program to launch command prompt. Command Prompt has a lunch button on the home of their program. I then used my Example from above to use the file location from this command prompt, not command prompt from start menu.

At 2:47 add any type of file called snake_game in the folder you made. Just save as .py instead of original file type.

neilfosteronly
Автор

I think this is not completely beginner friendly as some of them didn't know many of the things used in the video.
🚨SUGGESTION : Patrick u could also take little more time to explain the necessary details of the Pygame Module 👍👍👍
Btw Loved the idea🔥🔥🌟

shivendrabhardwaj
Автор

I fucking love you, thank you so much.
You saved my school project .

vppinchin
Автор

Yay another video! I'm sure it's going to be amazing :)

srikarksv
Автор

Thank you, Patrick. I got so inspired by this video. I learned it and made my own enhancements. I posted a video about it on my channel. Thank you for inspiring me! Much love ♥

studyingasyouwere
Автор

Looking forward to the next video! Great stuff.

marcusmahring
Автор

Really nice, thanks for the video, I'm learning Python because of all the tutorials of ML

I have a suggestion, avoid the "implosion", if you are going RIGHT and then you press the LEFT key, it counts like a collision
Another problem.. sometimes if you press 2 keys very quick, like if I'm going RIGHT, and I press TOP+LEFT, it "implodes" too, so I add a break at the end, so 1 key is computed per play_step(clock.tick)

if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
if self.direction != Direction.RIGHT:
self.direction = Direction.LEFT
elif event.key == pygame.K_RIGHT:
if self.direction != Direction.LEFT:
self.direction = Direction.RIGHT
elif event.key == pygame.K_UP:
if self.direction != Direction.DOWN:
self.direction = Direction.UP
elif event.key == pygame.K_DOWN:
if self.direction != Direction.UP:
self.direction = Direction.DOWN
break

fmj.mytube
Автор

I like it! Looking forward to the video with reinforcement learning :)

AladdinPersson
Автор

2nd. param of a namedtuple is a sequence, could be a list or a string sequence separated by space or commas.

colamelody
Автор

when i change the window size the game logic stops working... the snake is not collecting the food or anything and the rects don't even overlap, no idea why :\

AcridDragoon
Автор

It's awesome!!Thanks your detailed tutorial.

oo
Автор

Super video bro...🔥🔥....bro will you use nn.Sequential() while initializing neural net in next video it make more simple

saurrav
Автор

how does the snakes body follow the head?
how does the body turn at the same spot as the head?
Which part of the code is that?

jeremiedsouza
Автор

Really liked the video, I would like to know which part of the code adds the additional block to the snake when it collects the food? and how?
Thanks

rmknan
Автор

if you have in course in udemy i will pay it ---thanks your are the best agin

midoooo
Автор

when the snake hits the boundary, shouldn't it be when self.head.x > self.w, not necessarily self.w-BLOCK_SIZE? I have a little bit of trouble trying to understand why we need to subtract the BLOCK_SIZE at 37:17.

juheehong
Автор

when a class has two methods and one of those methods is an __init__ it's not a class. Nice tutorial though. Maybe use functions next time to setup the game loop. It's a lot more readable

charliebrown
Автор

Why do you use an underscore before the place_food function?

progress_games
Автор

AttributeError: 'SnakeGame' object has no attribute 'play_setup'
how do i fix this

michaela
join shbcf.ru