How to Program a Game! (in Python)

preview_player
Показать описание
Learn data skills with hands-on exercises & tutorials at Datacamp!

In this video we walk through building a simple game using the python programming language. This is a great exercise to apply your python skills in a fun way. We use the pygame library in this video. A video outline will be posted in the comment section. If you want to review any of the topics covered in this video, there are links below to all of my python tutorial videos.

If you are curious about implementing additional features to this game, leave a comment down below!

Make sure to SUBSCRIBE if you enjoyed this video, it encourages me to keep making them.

Have fun with your games!!! :)

Source code!

Check out the follow-up video where we refactor the code and add additional features!

---------------------------------------------

PYTHON TUTORIAL SERIES:

---------------------------------------------
Follow me on social media!

---------------------------------------------
Video outline!
0:00 - Introduction
1:10 - Pygame Installation
2:57 - Creating a blank screen
4:40 - Making the game loop (+handling quit event)
7:46 - Drawing a rectangle
13:57 - Moving the rectangle with keypresses
20:10 - Blocks dropping from the sky
27:59 - Setting the frames per second rate (FPS)/Controlling speed of falling blocks
31:14 - Detecting Collisions
41:13 - Multiple enemies falling from sky (lists)
54:10 - Adding additional features (score, increasing difficulty, background/player colors)

-------------------------
Follow me on social media!

-------------------------

*I use affiliate links on the products that I recommend. I may earn a purchase commission or a referral bonus from the usage of these links.
Рекомендации по теме
Комментарии
Автор


In it we refactor our code to use classes, fix the glitch where you can move off the screen, and add images to the enemy blocks falling down :).

KeithGalli
Автор

In year 1991 I was 10 years old and I programmed my first shooter game with spaceships and crafts using "Basic" programming language on 8-bit computer including some puzzle games, also hacked few other games. Unfortunately my parents were keep saying that the computers will bring me nothing in my life and they will never support me. That was the reality in a soviet republic. Our childhood was ruined by fake preceptions of what we should become in life and what they were telling us at school. At the end of the days that turned me into rebellion, punk, electronic musician and I missed how this technology was developed it time, but I was really into the games and computer programming. Growed up with illigally imported Atari ( that game was forbidden in our country) present from my auntie since I was at the kindergarten. I'm sure that there is kids at same situation still somewhere...

ogonek
Автор

Video outline!
1:10 - Pygame Installation
2:57 - Creating a blank screen
4:40 - Making the game loop (+handling quit event)
7:46 - Drawing a rectangle
13:57 - Moving the rectangle with keypresses
20:10 - Blocks dropping from the sky
27:59 - Setting the frames per second rate (FPS)/Controlling speed of falling blocks
31:14 - Detecting Collisions
41:13 - Multiple enemies falling from sky (lists)
54:10 - Adding additional features (score, increasing difficulty, background/player colors)

Also, remember to subscribe if you enjoyed the video! :)

KeithGalli
Автор

You are an extremely natural teacher. I appreciate how you consider the mistakes someone coding this for the first time would come across and "fall into" those errors as a chance for us viewers to correct our own understanding as we watch. Thank you for the video!

bensname
Автор

by far the most helpful tutorial on python I've found. I was having trouble finding this 'real world' application. Watching the code written outside does worlds better then memorizing mysterious pieces of information. This makes so much more sense!

mapplemoore
Автор

Man you're awesome! I did everything! It took me about 6 hours to finish and learn, and I liked every second of it

ginocarlo
Автор

I am only 12 years old and your tutorial helped me so much to learn python!
Thank you so much for the tutorial <3

youssefadel
Автор

this guy's camera is actually amazing

extremetitan
Автор

To make the enemies move smoother, you could:

...
screen.fill(BG_COLOR)
if enemy_pos[1] >= 0 and enemy_pos[1] < HEIGHT:
enemy_pos[1] += 1
...

clock.tick(100*SPEED)

This would make enemies fall down smoother, improving gameplay.
:)

matthewtam
Автор

OMG Thank you i am 11 years old and wait to make coding for a living and be an IT this has helped me so much and now my friends are playing it and staring it around

kngklulzyz
Автор

This was a great tutorial! I even was able to add some stuff like smooth movement where you just hold down the key!

colbablast
Автор

You teached me the most importand thing in coding!!!! USE THE thank you soo much!

Автор

Thanks for a such a great tutorial. I show this game to my mom and she was delighted while playing. That was the best part of it.

rakeshkumarkuwar
Автор

KEITH you deserve NOBEL PRIZE OF MAKING PYTHON FRIENDLY TO SENIORS like me. Last sunday I spent four hours learning about lists, watching at your video and practising and making new solutions of your explanations. I am really grateful, pal, best wishes from Guatemala, I will try to record something and send you the link of video. I am old programming stuff, and sought after Python but never was so interested, because some of the folks are kind of .... less didactic.

Автор

WOW man, really loved the way you took us to the whole tutorial. amazing speech delivery and I understood each and everything which you stated. Whenever you added a new piece of code, I used to delete the whole file and write from my own understanding and as a result, it makes it easy for me to understand the whole code. Thanks a lot, man. Really a very very helpful video for anyone. Please upload more videos regarding python and gaming. Please... Thumbs up from my side. Salute to you.

asishraz
Автор

with your help, I am able to build my first ever game in python. kudos to you.

adamansbah
Автор

keep up the good work bro! i learned a lot, subscribed with notifications turned on! cant miss any of your content tbh! THANK YOU

bde
Автор

Im watching this during a middle school game jam basically and I'm new to coding so this is helpful its better than stealing code which I was doing.

xanderthedragon
Автор

Done with the course! Nice, clear, and comprehensive guide and clear voice! Big thumbs up! :D

javier
Автор

One of the best tutorials out there, keep it up!

Herculuke
visit shbcf.ru