Create a Simple Video Game with Pygame - Step by Step Tutorial for Python Beginners!
HTML-код
- Опубликовано: 11 июн 2024
- Today we will learn the basics of Pygame by creating a simple car game from scratch! 🚗
⭐ This video is brought to you by Anvil ⭐
Try it for free: anvil.works/pythonsimplified
📃 IMPORTANT NOTES 📃
This tutorial is a 100% beginner friendly! 💯💯💯
It's designed for folks with the most basic knowledge of Python (are you familiar with integers, lists, tuples, while loops, for loops and if statements? no need to be an expert, but as long as you have a basic understanding of these concepts - this tutorial is perfect for you! 😀)
So on today's menu, we will:
⭐ learn how to draw shapes in Pygame
⭐ learn how to work with images in Pygame
⭐ learn how to use relative coordinates
⭐ learn how to animate Pygame elements
⭐ learn how to create keyboard events
⭐ learn how to increase the game difficulty overtime
🐍 INSTALL PYGAME 🐍
____________________________________
FOR NEWER VERSIONS OF PYTHON
⭐ pip install pygame
FOR OLDER VERSIONS OF PYTHON (& ANACONDA)
⭐ conda install -c cogsci pygame
⚒️ RELATED TUTORIALS ⚒️
____________________________________
⭐ My ultimate guide to Anaconda:
• Anaconda Beginners Gui...
⭐ For Loops For Beginners:
• Python For Loops - Pro...
⭐ Convert Colours to Numbers:
• Convert Image into Mat...
⭐ My Simple Calculator App with Anvil:
• Simple Calculator with...
⏰ TIME STAMPS ⏰
____________________________
00:00 - intro
00:54 - create Pygame window
03:13 - run Pygame app with Anaconda
04:02 - set background colour
04:51 - set window title
05:27 - what is relative coordinates?
06:35 - draw rectangles with Pygame
07:24 - use coordinates in Pygame
11:22 - relative coordinates example
12:00 - use images in Pygame
15:50 - keyboard events in Pygame
18:48 - animation in Pygame
20:46 - random events in Pygame
23:07 - end game logic in Pygame
25:13 - game levels logic
25:58 - introduction to Anvil
26:44 - increase game difficulty over time
28:32 - thanks for watching!
🔗 IMPORTANT LINKS 🔗
____________________________
⭐ Complete Tutorial Code:
github.com/MariyaSha/SimpleCa...
⭐ Pygame Documentation:
www.pygame.org/docs/
⭐Vehicle Images by:
www.freepik.com/
😁 THANKS FOR WATCHING! 😁 - Наука
Dear Mariya, width // 1.6 and Int( width / 1.6 ) gives exactly the same result. Tested many times and I always use the first solution.
aha! you're using the floor division arithmetic operator, eh?? 😉
It's definitely an extra elegant alternative to my int() conversion, thank you so much for sharing the tip!! 😁😁😁
@@PythonSimplified no problem. I'm always here to help
so does it matter which one to use ? like can we use width/2 ? cuz it seems easy kind.
You can’t use width/2 because you need integer number and since width/2 returns floating point number you need to convert it to integer. Two ways to convert it is use int(width/2) or width//2
@@immadwolf4459 the operator "a/b" != "a//b" != "a%b" -- the subtleties of syntax of different "languages". In some syntax you have to use "ab" or "a NOT b".
Very nice tutorial! I love how thought through the process seems while still keeping it light and fun. I also like the fact that you actually create a working game before the sponsor ad is run as it keeps the flow and add bonus instead of making the video into a two part one like most of the creators seem to do. The only thing i would add in a beginners guide is a ToDo list commented into the code for easy progression and structured work flow.
You rock! I'm teaching python to my 9 y.o. I taught him Scratch when he was 7 y.o., and now it's time for him to learn a real programming language. But all the talk of strings and arrays are not at all interesting to a child. We tried a snake program, but it lacked line numbers and contained several errors. Then I found your channel and you're awakening the 9 y.o. within me, making coding fun again! 👍🙂👍
You really do a way better job teaching coding than other channels. Other tutorials are the same old scripts over and over never really explaining the syntax, just saying "type this" .. keep up the awesome work!
I really love your tutorials on Python. You make complex programming syntax look easy. Huge thumbs up.
Great tutorial. You’re covering what I’m doing with my school aged son, but you’re way quicker and more accurate. He’ld love it if he got to your level one day. You’re a great role model.
It was very interesting!
Thanks for another great guide!
Also I loved the shirt! 😁
Thanks for this tutorial Maria! I'm going to make some minor changes (add a motorcycle and sand instead of a second car and grass) and add it to an upcoming video I have for a podcast episode on the book 'Zen and the Art of Motorcycle Maintenance'. I will link back to this video for my viewers that are interested in creating games with Pygame. Nice t-shirt too by the way!
Mariya, thank you very much for you help with this tutorial. Your teaching style is very clear and concise. Much appreciated.
Kinda genius, I managed to complete the tutorial and got a lot out of it. Thank you!
I watched the entire thing, it's a great introduction and looks like pygame is the way to go for a little dice roll app I'm making.
很有意思的課程解說、謝謝分享😄
This step-by-step approach is excellent! Great teaching style. well done.
Yeah, it definitely helped Me.
dear mariya! you,re great i have learnt many things from your video.......keep it up and upload these type of videos😍😍😀😍👍
Great tutorial . I will follow more of Your tutorials.
great job.
Thank you from Nova Scotia
Mariya, sorry I had to leave the lesson earlier. I just finished watching it now and this helped me a toooon. Also, I checked your mic and looks awesome. I hope it sound as good as it looks. If you have questions about EQ your voice, don't hesitate to ask. Again, thank you for the lesson 😊
Thank you Mariya for the tutorial, much appreciate
Bon travail, félicitations Mariya.
I had no idea Pygame finally moved to Python 3. Like your other videos this is clear and straight to the point. Excellent work, and thank you!
Me too! It's actually available since Oct 2020 but not too many people heard about it! 🙃
I think the biggest holdback is that Anaconda still didn't update its package to the current version so you can only install Pygame 2 with "pip install pygame". I believe that's a big part of the problem!
With "conda install -c cogsci pygame" folks receive a message in the terminal that "Pygame only works with Python 2.7 - 3.5" but they don't realize it refers to Pygame 1 so it's a total Anaconda mess up! 🤪
And thank you so much for the lovely comment!! I'm really happy you like my tutorials! 😀😀😀
Wow awesome 😎 you make python programming more easier and enjoyable. Thanks for sharing.
Thank you so much. Just finished making the game. Took me like 4 hours but yeah. Progress. Haha
Thanks to your tutorial, Mariya, I've managed to draft my own version of River Raid, something I've been desiring to do for the last 30 years 🤪😇
Thank you .
Your video increased my confidence
Thanks for the tutorial, it's very helpful. I really like your contents.
Loved it thank you so much i found what i was missing
Very useful !!! 🏆🏆🏆Thank you so much !!!
thank you so much it really helped me out
Excellent Tutorials!!
Thanks for you info sister.😊😊😊😊
thank you soo much, I learned a lot!
Very understandable. I love t. Already subscribe
Omg this is awesome content. Thank you!
You explain stuff very well.
Great work you are doing it great👍 and I love your videos 😋 all are awesome. Can you make a video on tensorflow too.
Very well 👌🙌
first project done very happy
beautiful work and good luck 💙
I've been working on a game (in finger quotes) that also involves a stream of vehicles for what seems like a really long time. Some it's become really complex and doesn't work half the time. And yours seems to comparatively simple versus mine. I mean mine was made partially to help learn things like OOP. But it is jarring to seem something so simple do what I can only sometimes do in so few lines. So thanks for that.
tom & jerry :) another great video, thanks! if you run out of content ideas it would be neat to see a video using machine learning to give you advantage in a game (something like checkers, chess, starcraft, hearthstone, etc)
umm your pygame tutorials are pretty well-made keep it up
You understand very decent all the process while you are creating the video game.Also your English are very comprehensive!!
Tutorials like these are very interesting, if i see how many People need to develop a whole Game :D Currently i have a Side Project with python Ursina (Its a similar Game Engine like pygame) and i will create a Crash Bash and a normal Crash Bandicoot FAN Game with this Engine. The logical Part of Programming is in my Case not the Problem, later i must create some Animations, Textures and Models for this Game and make all that compatible with this Engine :-D
Looking forward to this very much !
Yey! I hope you found it helpful! 😀
Super, Great Video, Thank You !
So it’s always an exciting moment to learn with you ❤ I’m not a native English speaker but i understand easily when you explain something 🎉Be blessed
From 🇭🇹
great video your videos always motivate me to learn python further great videos ma'am love your videos
BBBIIIIGGGG THANKS 🙏 👍👋😀😃😄🤩🤩🙋♀️👍🎈🎉🎊
new subscriber here, thank you so much for this, as a beginner this is very good tutorial.
I never heard of Pygame before, I decided to attempt at cloning an old an atari 2600 and a speccy game on python. One thing I do know having to rewrite code due to duplication of the cars, moving charactors always must been drawn last. I sometimes think of it as CAD and how I drew the machinary for 1 of the swimming pools. I have followed this video to produce a little program that depicts a well on the old ET game.
How does the draw function work?
Having it redraw in the while loop does it write over the previous or just slap a new copy on top.
Would that eventually have memory leak issues?
You' re amazing... Thanks for sharing!!!
Thank you so much Michael! I'm happy to help! 😀
Great video, as usual.
I notice someone else commented on a new(?) microphone setup.
This might just be a "me" thing, but my subwoofer is very triggered by the typing in this video. 🥁
Hi Graydon, this video was filmed with the old mic 😀 it was still in shipping when I premiered this one (now I'm only waiting for the fancy arm which was supposed to arrive yesterday, but never happened 😨)
The new mic will be featured in the upcoming Numpy tutorial so hopefully you'll hear it this Thursday 😊
I got to level 2 in this game, then a police car blocked the road and took me to jail. Great work, Python Lady 👍
The game actually ends when you park in front of the Parliament in Ottawa on level 10... and then they also take you to jail 😅😅😅
(a reference that only Canadians or folks who follow independent media will understand 🤪)
THANK YOU!!! 😄😄😄😄😄😄😄😄😄😄😄😄😄
Thanks. Great tutorial. Now I can saw my son that if he learn python he will able to make games...maybe not Minecraft but still 🙂
Do u know about any python gui library that supports vulkan. Pyimgui does not have a vulkan backend
Congratulations again, may God bless you more and more. thanks for helping me train and learn Python.
"god" is just an imaginary friend that never helps, Evolution is True.
I've just made a similar app with the millennium falcon recently.. pygame is fun :)
Superb.
I only get a collision on the right hand side but not the left.
My image size was larger which ive accounted for but it just goes right through on the left hand side
Thanks for awesome Explanation
You're absolutely welcome! enjoy! 😊
very helpfull i like you so mutsh
Hello from Baku, great tutorial
Thanks so much for this!!!
Have been talking through the design phase of a game my 6 year daughter wants to create called Shark Catcher...
My office wall is covered in design notes and sketches she has been creating and it is time we started dev.
I code Python everyday but never Pygame so this tutorial / live coding example is a great framework for us to bootstrap from.
Especially happy that my daughter has such a well versed female tutor / role model who is able to communicate quite difficult principles in such a understandable way!
Will be sure to share our fork with you for you to review and play.
Personally I have been coding for over 20 years now but still learn at least one thing new in every one of your videos (sometime many and totally new new design patterns)
Please keep up the excellent work, it is very much appreciated!!!
Rob
That's awesome, Rob!! I can't wait to see Shark Catcher in action! 🤩🤩🤩
Creating software and learning coding at 6 is VERY impressive!! Sounds like you have a young Elona Musk at home! 😉
I hope to have an entire "Python for kids" series by the time she's old enough to independently study. I've been planning it for a while but still stuck on picking the best coding interface to use (I hope I won't need to build one 😅)
Super happy to hear you enjoy my tutorials! I have some really nice projects in the making:
Tkinter+SQLite Random Recipe Picker and comparing the exact same C++ app with a Python app, so definitely stay tuned! 🙂
Also, thank you so much for the incredible comment!
Best of luck with Shark Catcher! 😃😃😃
Wow this is so cool! haha
Congratulations! you increased the font, it was great I could see it from my smartphone, my kids will like it a lot, one question, will there be the end of the game?, because it looks like you didn't finish it, right?...
your videos always helped always taught me about some interesting and useful 🥰♥️ thanks Soo much I am your big fan
Thank you so much for the lovely comment Abdul! 😀😀😀 I'm super happy to help!
una duda: como haces un personaje que empuje un objeto pero al mismo tiempo colisione con el
Cool tutoriasls Mariya!!, Can you add some tut for PY and Mysql Crud? Thank you so much!
I hope this will help a little with your English...
These ( ) are not brackets, they are parentheses. There are two kinds of brackets... Curly Brackets { }, and Square Brackets [ ]. This one is Open parentheses (, and this one is closed Parentheses ). I hope this is helpful. 🙂 It's pronounced Pa Ren theh seas.
why are there double parenthesis for things like the pygame.display.set_mode expression?
Dear Mariya, thanks for all your amazing videos.. May I ask for a video that is sort of a composite of 2 videos you already made? Creating a exe file of a project that makes use of torch/torchvision since it is very difficult and there are tons of people online failing at it. Would be great.. thank you!
Sure, I'll look into it! It will take me some time to get there but it's officially on my "to do" list 😊
Thank you so much for the suggestion and for your lovely comment, Igor! 😃😃😃
so, as with many small projects like this a common error in using visual code is the dreaded "FileNotFound" error because the working directory doesn't synch with the actual directory where the images are stored. In my case, the default working dir is the root dir above the subdirectory i put this in. So, if others are having similar issues, just change the working dir in code. Add this at beginning after tge other import directives:
import os
os.chdir(os.path.dirname(os.path.abspath(__file__)))
My favorite channel
Yeeeeey!!! Thank you so much Amanual!!! 😁😁😁
Thank you ilove you 😘😘🙂😅
Great tutorial
Thank you! 😊
Nice
Hi! Where did you get the photos for the cars?
Hey Maria is there a way by which I can rum my pygame code along with kivymd login screen into an android app.
It generally shows an error ie, android only supports one window.
Is there a solution for it ....
I think you is 🔥🔥🔥 girl 😍, nice vid btw 👍🏼
Which editor I use for python
And my some programs wrong bcz latest version of python installed then also programs wrong I write in correct way then also show error like indentation
Finally gaming 🔥🔥
Beauty of Logic
and also you always respone and respect 🥰♥️
I did today the tkinter tutorial THX best timing for me 😍😍😍
That's awesome!! Super happy to hear that Arijan! 😁
I'll start working on a new Tkinter tutorial once I'm done covering Numpy (filming it tomorrow if my new fancy microphone arrives today) 😉 Still not sure what kind of application it would be... I'm aiming for something that has to do with sound and audio 😊
I learnt python but don't where to use for loop while
define classes objects and all other basic and advance things
because I want to create a app but how to change code into a gui
Hi, love your tutorials, sometimes, pls do a VR and AR,
Thank you so much Richee! 😀
VR and AR are quite a big topic jumps from what we currently cover on the channel. It involves a very large degree of graphics and 3D modelling in addition to code... It's not on my "to do" list but I also never say never! 😉
Hello i m interesting in learning python and want to know if there is a market especially in freelancing thnks
Great video. Hope you can create a video on how to create apk from pygame in the future. thanks in advance
I'm using Visual Studio Code in Debian Linux on Chromedome using Python 3.9.2 64-bit
Question:
I have pip3 installed pygame through the terminal inside VSCODE and it recognizes it. It doesn't recognize "event"
It gives me the option to import from tkinter. How should I import "event"? I apologize as im new to VSC coming from IDLE
Hello @PythonSimplified, I have a question. My enemy car is not moving as fast as yours and mine is also leaving a trail. How do I fix that?
Thank you for your amazing content as usual. Have an amazing day!
You are doing such a great work teaching and explaining 👏 😊
Thank you so much for all the knowledge you are passing on ❤️
Thank you so much Or, I'm super happy to help! 😁
Nyc
I suggest you to also cover Godot Engine, the language GDScript is close to Python and it has a lot of built-in nodes/classes to help create 2d and 3d games but also interfaces (the software interface is made by his own nodes).
I respect it but this channel is totally dedicated to python and GDScript's syntax is mostly derived from Python, but it doesn't support all of the language features that Python does 😊
I guess the point here is to learn pygame basics as a convenient input/visualization interface that can be used for many purposes by python users. Someone who is really looking to make and publish a 2D game would not use pygame in the first place, but something like Unity or Godot.
I know it's first command, but I'm having trouble with vscode recognizing import pygame. Any helps?
Ive done dozens of games and never imported locals, initiated pygame or used .quit() pygame, what are those for?
Can I automate this car, like when a car comes from opposite side it will change it's position automatically??
Hi Mariya! How are you 🙂🙂
Was never interested in games but going to watch this whole tutorial haha
Hi Ali, great to see ya! 😀😀😀
You can actually implement a very fancy UI with Pygame, not only games!
I just had this game stuck in my head as I was playing it as a kid on my Tetris console... I had to implement it before I cover anything else that this library has to offer! 😊
@@PythonSimplified you can't be happier than me when I see you haha!
Mariya, aren't u focused on AI stuff nowadays?
(Well I would happily learn anything you teach. You can try something like cooking as well 😁)