OOP with Pygame - Object Oriented Programming Exercise

preview_player
Показать описание
Welcome to another Python Object Oriented Programming exercise! Where we will practice classes, objects, attributes, methods, and inheritance using Pygame 🐍🐍🐍
We will take an image of a car, turn it into an object, and use it to generate trucks, police vehicles, and all kinds of sedans. The purpose of this tutorial is to help you understand the different aspects of OOP and show you why it's such an important programming concept.
Even though this video begins with a quick refresher, it is recommended for folks who already have a basic background with Python classes. If you are an absolute beginner, please refer to the two tutorial recommendations on the screen and in the links below.

📺 Related Videos 📺
----------------------------------------------------------------
⭐ Anaconda for beginners:
⭐ OOP Methods and Attributes for beginners:
⭐ OOP Class Inheritance Super Init for beginners:
⭐ OOP Exercise with OpenCV - Draw a Forest of Random Objects:
⭐ Pygame Car Game for Beginners:

⏰ Timestamps ⏰
----------------------------------------------------------------
00:00 - intro
00:36 - Pygame starter code
01:04 - setup Pygame environment
02:07 - class attributes and init
04:31 - class methods
04:16 - self parameter tips and tricks
04:59 - draw object with Pygame
06:48 - why using OOP?
07:22 - keyword arguments
08:04 - create multiple objects with one class using random values
10:17 - inherit methods and attributes from parent class
10:57 - super function
11:19 - super init
11:19 - super init keyword arguments
13:00 - override attributes of child class
13:56 - child class keyword arguments
14:47 - advanced OOP example
18:22 - thanks for watching! :)

💻 Github Repo 💻
----------------------------------------------------------------

🤝 Connect with me 🤝
----------------------------------------------------------------
🔗 Github:
🔗 Discord:
🔗 LinkedIn:
🔗 Twitter:
🔗 Blog:

💳 Credits 💳
----------------------------------------------------------------
⭐ Beautiful titles, transitions, sound FX:
⭐ Beautiful icons:
⭐ Beautiful graphics and dog meme:

#python #pythonprogramming #pythontutorial #oop #objectorientedprogramming #classes #objects #coding #programming #attributes #methods #functions #inheritance #learnpython
Рекомендации по теме
Комментарии
Автор

You are declaring instance attributes outside of the __init__ method, which is not ideal. You can just create them with a value of None, and then set them in the draw method. If you never call the draw method, that means the attributes will never be initialized (set) and thus, do not exist.

Qlii
Автор

Thank you so much. That replacing "self" with "vehicle" really cleared a lot of things

awelege
Автор

Visuals are very important when learning, for a lot of people. This was a great way to show off classes and although I have been using Python a while, I feel a lot more comfortable with some things I did not know before (like the super required in inheritance!) Fantastic video!

VinnyRN
Автор

Thank you! You're a great explainer! You seem like you test your tutorials ahead, so you don't get tripped up on small details like many do when doing tutorials.

kjlw
Автор

You are such a perfect teacher. So easy to understand you. Even though I am more of a Java, c and c++ developer.

MichaelSwartout
Автор

Good morning! I'm enjoying learning from such a skilled little snake charmer. Please feel free to keep sending those homework assignments my way - practice makes python! Thank you Mariya! 😊😃😛😉

paulocoelho
Автор

Спасибо, Маша! Отлично обхяснила. Даже я что-то понял из ООП. Пожалуй вернусь к этому упражнению после прохождения курса по ООП на степике!

ivansmirnov
Автор

This is great! Going to rewatch later when I get on my computer...

AwesomeCameras
Автор

Woow best OOP lesson that i have ever seen. 🥰

mecrayavcin
Автор

I really love your content- you have a gift for teaching thank you for sharing

AirzGamingTTV
Автор

Thank you for continued content. Would love a video that goes over how how to self-learn new python modules! Ideas would include how to get used to reading python module documentation, what to google, how to find examples etc.., how to start playing with a new module etc..

Hope you respond whether you think this is a good or bad idea/or any thoughts in general. Thanks!

hodoros
Автор

In pygame or python ursina or cave engine it is more effective to write the classes like "class MY_CLASS(WHAT_MY_IS):". The reason: Game engines like Ursina, PyGame or Cave call predefined instances such as “Entity”, “Text”, “Animation” or simple “Scene”. This means that if you write larger code, sooner or later type problems will arise when recognizing and reading the instances if this is not stated directly. At the same time, these are able to use the update definition with the delta time and update themselves. If you don't specify anything there, the update function will only work to a limited extent there or at least only if you integrate it somewhere else, which will end up eating up a lot of performance and Python is a bit slower in gaming anyway. It would also make the code easier to understand and read if you use variables or values ​​that are as short as possible than the actual string or value itself. Example: instead of

xEndless
Автор

I know it's a tutorial (a very good one to say), but as an OOP Coder I don't feel good with deep inheritances and something that may break the Liskov substitution principle. So to create a "class DrawableItem" and inherit from this would make more sense in practice than to create a class Car/Vehicle and class Truck(Vehicle). In practice it would make more sense most of the time to use composition instead of inheritance.

christianmontagx
Автор

You are seriously one of the greatest teachers I've ever seen for programming languages. Thank you so much.

tangled
Автор

You down with OOP? Yea, you inherit me!

chrisray
Автор

I personally couldn't have made it a better explanation Maryia

edupgarciati
Автор

Thank you Mariya for another great content!!!

felipegaeteroman
Автор

I think I found the channel I'll be using to research Python 👀suddenly it's far easier to pay attention and learn

cram
Автор

i miss you so much ❤️
please stay active 🙏 we love your content 😍

mrpro
Автор

Thanks Maria, i think i have to go over again.
Keep it up🙂

tokenizedgameplay