Creating Space Invaders in Pygame/Python

  Рет қаралды 124,727

Clear Code

Clear Code

Күн бұрын

Пікірлер: 143
@ClearCode
@ClearCode 3 жыл бұрын
check out my twitter for more videos on the platformer twitter.com/clear_coder
@1.000M-p7s
@1.000M-p7s 3 жыл бұрын
Could you please make some cute game which is friendly for girls? Thank you 🙏
@charg1nmalaz0r51
@charg1nmalaz0r51 Жыл бұрын
What i would like to see is a nice little rts game, or a simulation type game or something like settlers. Be interesting to watch if you ever need ideas
@axermaster_yt
@axermaster_yt Жыл бұрын
keep doing your pygame games tutorials, they are awsome!
@janu3d
@janu3d 3 жыл бұрын
This is the best programming channel on youtube.
@vasarolnik
@vasarolnik 3 жыл бұрын
Thank you VERY much for this quality content! I learned a lot! Looking forward for the platformer and everything that comes next! Thank you!!
@somebody6837
@somebody6837 3 жыл бұрын
I'm already hyped for the platformer tutorial, loving the tutorials as well. Keep it up Clear Code and to those who are just learning like me :)
@juniorMr
@juniorMr 2 жыл бұрын
Man ,you don't have a clue how much you have been helped me with your videos tutorial. I am watching you from Mozambique and am super grateful for your work.
@sniper_hd
@sniper_hd 3 жыл бұрын
Bro you're amazing. I made flappy bird game from you and I learned so much. You have the best tutorials on this platform. Also I can't believe these are free too. Amazing job mate, keep up the good work.
@CodeWithMilk
@CodeWithMilk Жыл бұрын
Dude, I am studying Python and I found your channel... it's amazing!!! I'm in love with your videos and with the way you teach. I am from Brazil and I wish we could have videos like yours. So I decided to start a channel about python and pygame! Maybe I'm gonna do it tomorrow haha but I am very excited to share it with people (in English, sharing your videos for my friends and in Brazilian Portuguese making my own videos). Thank you so much and keep doing a great job!
@Errlyriser
@Errlyriser 9 ай бұрын
Dude - You do have videos like this. It's called KZbin and you watched this lol
@chalkypj
@chalkypj 3 жыл бұрын
Awesome as usual. I learn so much from your tutorials. Thank you
@random_guy_on_youtube
@random_guy_on_youtube 3 жыл бұрын
Nice! I love your vids. They are so quality
@calitts4708
@calitts4708 3 жыл бұрын
New logo! I think it will take a while for me to get used to this one. I loved the C logo!
@ClearCode
@ClearCode 3 жыл бұрын
I had too many people being confused and expecting videos about C/C+/C# and it was getting annoying :)
@mixlaproduction
@mixlaproduction 3 жыл бұрын
Agree. This one could look better as the bottom part of the C shape being white to be distinctive from the background.
@Seio0987
@Seio0987 2 жыл бұрын
Great guide, as always. I changed a small thing that bugged me about the live-system. First, I created a new Function for self.live_x_start_pos: def update_lives(self): self.live_x_start_pos = screen_width - (self.live_surf.get_size()[0] * (self.lives - 1) + (10 * self.lives)) For this function, I changed the 2 for (self.lives - 1) and the 20 for (10 * self.lives). Now I called this function in the place of the original line as well as in the player collision, right after reducing the lives per one. Reason being that 1st: now the positioning looks way better with more then two Extra-lives and 2nd: if you lose a live, you'll now lose the left-most icon instead of the right-most icon.
@klausbrier6307
@klausbrier6307 2 жыл бұрын
I like this Clear-Code-Videos. Such a good explanation, a good structure
@deathshot9310
@deathshot9310 3 жыл бұрын
Great tutorial! Thankfully I didn't get jump scared this time :)
@ShaizeOn1
@ShaizeOn1 3 жыл бұрын
cant wait to try it myself, thx a lot!
@maxrg8912
@maxrg8912 3 жыл бұрын
Man we love your toturials please try to teach us how to make shooter or platform game with pygame
@ClearCode
@ClearCode 3 жыл бұрын
those are literally the next 2 planned ones :P
@maxrg8912
@maxrg8912 3 жыл бұрын
@@ClearCode I am so excited !
@JustinLiftz
@JustinLiftz 3 жыл бұрын
The goat has returned
@mesquitesmoked7274
@mesquitesmoked7274 Жыл бұрын
This was a great tutorial. Thank you so much for the upload.
@stephencain5448
@stephencain5448 3 жыл бұрын
Thank you for a great set of tutorials that you are putting out most useful.
@Hyvexx
@Hyvexx 3 жыл бұрын
This looks so good!
@eternl_sunshine22
@eternl_sunshine22 Жыл бұрын
wow this is very different from the basics to pygame that we built, but really good
@cliffordwilliam3714
@cliffordwilliam3714 3 жыл бұрын
Subbed! I can't wait for the platformed tutorial. Would also love it if you cover on using state machine to control character movements! I've been having a hard time trying to accomplish that..
@ClearCode
@ClearCode 3 жыл бұрын
that's gonna come this weekend!
@cliffordwilliam3714
@cliffordwilliam3714 3 жыл бұрын
@@ClearCode Oh yesss!
@fcobermudez3655
@fcobermudez3655 3 жыл бұрын
Thank you very much for your work, so that we can learn. I'm testing PyScripter and it seems to me a very good ide.
@angadsingh6478
@angadsingh6478 3 жыл бұрын
I am eagerly waiting for your Mario style game💖
@hyp3rb3ast41
@hyp3rb3ast41 2 жыл бұрын
thank you so much you helped me a lot, and because of you I learned so much and from the pygame module, it was a blast keep up your great work!!!
@EMRAN994
@EMRAN994 Жыл бұрын
bro this is amazing, i learn so much from you, thank you
@jgarale
@jgarale 2 жыл бұрын
Wow!!!! Súper cool!!!, the sound is awesome!!!
@xtopy9145
@xtopy9145 2 жыл бұрын
I never knew I needed this, thanks!
@CodePhiles
@CodePhiles 2 жыл бұрын
that was really brilliant, I enjoyed watching the tutorial till the end, hope to work on levels and adding more laser shoots at once for the player...and what are the challenges that we could face if we wanted to user higher resolutions graphic??
@javiervill2496
@javiervill2496 2 жыл бұрын
Fantastic video!! Thank you very much for this content.
@A_choosen0ne
@A_choosen0ne Жыл бұрын
WOW!!!!! this is impressive really good job.
@leonidas14775
@leonidas14775 5 ай бұрын
Nice tutorial! It is better practice to use import os file_path = os.path.join('graphics',color+'png') since slashes in file paths aren't the same on all operating systems.
@philtoa334
@philtoa334 3 жыл бұрын
So good.
@Derpy999
@Derpy999 3 жыл бұрын
Damn bro you’re crazy!
@gametimewitharyan6665
@gametimewitharyan6665 3 жыл бұрын
It will be very helpful if you can offer a multiplayer version of any game that you made with server and client because the multiplayer side of it is pretty hard for beginners to grasp these hard topics, and if you will teach them I am 100% Sure that everything will be crystal clear
@Ashok-qx4kr
@Ashok-qx4kr 3 жыл бұрын
Hey man, I really like your videos and your explanation is to the point. Thank you for doing this. Can you talk about moving objects in a sequence with some gap like vehicles in traffic in your next videos or can you suggest any sources for that?
@johnwall6585
@johnwall6585 2 жыл бұрын
Some great techniques here, I always get confused with game programming - but find other programming ok
@jamesbondisamonkey
@jamesbondisamonkey Жыл бұрын
I think you can get the right x offset for the obstacle creation, each of those blocks has a string of size 10, maximum of 60 because you set each one to 6... So then you can offset it by 30 and I think that it puts it then directly in the middle
@charg1nmalaz0r51
@charg1nmalaz0r51 Жыл бұрын
yeah what i did was take the position of the last obstacle and and added its width which i got from its (row count * size) then took this from the screen width to get the space on the right then divided that by two to get the start x obstacle_x_offsets = [num * (self.SCREEN_WIDTH/amount) for num in range(amount)] end_x = obstacle_x_offsets[len(obstacle_x_offsets)-1] start_x = (self.SCREEN_WIDTH - (end_x + (Obstacle.width * size))) / 2
@jamesbondisamonkey
@jamesbondisamonkey Жыл бұрын
same thing with the alien offset. You can do (width of the screen - (alien size + space_in_betweeen_each_alien) * number of columns of aliens))/2... and that should number can be the buffer you use to start positioning the x coordinates of the aliens, which will even out the space on the left and right of screen, if you care...
@charg1nmalaz0r51
@charg1nmalaz0r51 Жыл бұрын
dont suppose you have a better solution for moving the aliens and switching directions. I found his code breaks if you slow the aliens down because more than one hits the wall and if you arent fast enough to swap directions it goes haywire. I found it out by replicating the clastic alien movement and realised how lucky his stats were to switch direction before it breaks lol. in my head a better solution is to have each alien know its position relative to the edge and switch when it reaches that offset and have the aliens move themselves. but my maths skills are shite
@spaidory874
@spaidory874 2 жыл бұрын
Thank you but you forgot to include when you added the player laser sound (I ended up doing this by myself no problem though)
@bcgamer2
@bcgamer2 Жыл бұрын
You use the word "and" an awful lot and do not hide your accent. Also, you use words native speakers would not use in a presentation (e.g., center vs. middle). But thanks a lot for an easy-to-follow tutorial. I have learned a lot and will start developing a game for my son based on it. Greetings from a Canadian
@Astrogator1
@Astrogator1 2 ай бұрын
what is wrong with his use of 'and' and why should he hide his accent. I am native level English speaker but still have an accent, I have spent many hours talking to people in English and some have mentioned my accent but no one has ever raised an issue with it with me. The people who do say anything have been positive. I am not sure why you needed t o raise this ? Greetings from Spain
@bcgamer2
@bcgamer2 2 ай бұрын
@@Astrogator1 it is just the typical atrocious German accent that sghows and that is not being liked all around the World. I am Canadianand consider myself native level English speaking as well. I detest such German accents having been raised in Germany myself...
@godcanonen2634
@godcanonen2634 3 ай бұрын
you are the best bro!
@Pogomeister
@Pogomeister 2 жыл бұрын
I have a question about the alien_position_checker(). I want to point out that I do not expect you as the creator of the video to answer my question. If you do, very cool, but no expectations here. You do such great work and I am very grateful for it, thanks. 🙂 Maybe someone else is also able to answer it. at 1:02:00 why do you create a new list named all_aliens in which you put the sprites with the sprites() method. I just looped through self.aliens itself like this: def alien_position_checker(self): for alien in self.aliens: if alien.rect.right >= screen_width: self.alien_direction = -abs(self.alien_direction) elif alien.rect.left
@arnoldshavings7326
@arnoldshavings7326 Жыл бұрын
works, great tutorial
@pagalump3529
@pagalump3529 3 жыл бұрын
Thanks bro
@edwardwright695
@edwardwright695 9 күн бұрын
I am not getting the obstacles on my screen . Please help
@Skz1337
@Skz1337 Жыл бұрын
Amazing tutorial
@gabizehE
@gabizehE 3 жыл бұрын
I couldn't done the code of this game, because everytime I import Player and set his position, as player_sprite = Player((300,300)), pygame tells me that I've used 2 posicional arguments instead of 1 , considering that a error. What should I do? Oh! I almost forgot that I have a Windows 7 computer and my python version is Python 3.7.0. This information must be important somehow.
@guntbert9709
@guntbert9709 3 жыл бұрын
Thx for the educating video - I am just wondering why you don't use f-strings for constructing file_path (at about 50:30)?
@DoomsdayDatabase
@DoomsdayDatabase 2 жыл бұрын
This is the error I am getting FileNotFoundError: No file '../graphics/player.png' found in working directory
@spaidory874
@spaidory874 2 жыл бұрын
try to just have 'graphics/player.png' ,since you prolly didn't make a file for the code (which is what clear code did)
@DeltaNrOne
@DeltaNrOne 2 жыл бұрын
There is 1 thing very small nitpicky thing in the very last part of the video and i am not even sure if it is better or not. When adding the sound for the laser for the player instead of loading the sound in again. would it not be better to pass the sound along to the player? I know that disk operations can be quite slow and passing it along is as fast as your game can run. for sure it wont have any performance issues with just one file in simple game like this but if you do this over and over again it might get heavy? great video learned a lot. and gonna give it some of my own features!
@paren7274
@paren7274 Жыл бұрын
Thank You For your videos!!!
@tonytian7994
@tonytian7994 2 жыл бұрын
Thank you so much David, followed through a few videos, very educational, wish you could create a tower defense game from the scratch, that would be my dream come true :-)
@paren7274
@paren7274 Жыл бұрын
Thank you vary much! Your video so good!
@mattiasbrodendal9763
@mattiasbrodendal9763 Жыл бұрын
Thank you for this video. Would it be possible to make a add on to this video where there is a loose-massage and a where the game restarts by pressing a key? Same with at the victory-message, press a key to restart? Thank you!
@Erdbeerbowle
@Erdbeerbowle 3 жыл бұрын
Hello, I'm following along, and I'm having some trouble with the self.image.fill('white') code at the 21:21 mark. When I run the code, I get a "TypeError: invalid color argument" statement, and the program crashes. When I delete the self.image.fill('white') code however, it runs fine, with the exception that I now have a "black" laser. Do you know what I'm doing wrong? Thanks!!
@sjacobson42
@sjacobson42 3 жыл бұрын
My kingdom for a portable Python with pygame and editor IDE!!! Just all ready to go, like GODOT 😔
@venugopalbedar4550
@venugopalbedar4550 3 жыл бұрын
First view First like First comment
@dennys.1880
@dennys.1880 2 жыл бұрын
Where can i add a starting screen in the code ? And how should i do it?
@HappyLicker
@HappyLicker 2 жыл бұрын
Love this channel :D
@mike_jay
@mike_jay Жыл бұрын
I love yr channel, keep it up please. A suggestion for a game that I think would be suitable…..civilisation one, or six if yr brave. Civ1 would be a great demo.
@bujacoding
@bujacoding 2 жыл бұрын
best of the best
@robbo4542
@robbo4542 9 ай бұрын
at 24:33 my lasers.draw command under def run(self) isnt defined and i dont see him do it in the video
@thesilverpen
@thesilverpen 2 жыл бұрын
excellent instruction, lots of cool references materials. I cannot get my code to correctly acknowledge the image file for the player. I even cut/pasted the reference code to test it..still same. Checking my pygame install for errors and also will try to rewrite using another source for the image. With this great tutorial, I am confident it will get fixed as I go through it.
@RiyadIsgandarov
@RiyadIsgandarov Жыл бұрын
hey, sorry for dumb question but how u clossing thar function and then opening them by pressing yellow bottom ? \
@Vad1mah
@Vad1mah Жыл бұрын
Why don't we do groupcollide instead of spritecollide?
@johnniegilkerson4724
@johnniegilkerson4724 Жыл бұрын
@8:23 in video my code is the same as yours, In get an error Traceback (most recent call last): File "C:\Users\johnn\PycharmProject\Invader\main.py", line 30, in game.run() File "C:\Users\johnn\PycharmProject\Invader\main.py", line 12, in run self.player.draw(screen) AttributeError: 'Game' object has no attribute 'player'
@testechnews
@testechnews 3 жыл бұрын
Your video are awesome for python lovers and coding, can you clear one thing ,how to clear sprites for again restart the game. Please answer or share some ideas so I clear how clear sprites clean and restart game.
@potatocat6855
@potatocat6855 2 жыл бұрын
The best , keep it up
@smajin28
@smajin28 8 ай бұрын
It's not drawing the obstacle in the top left corner for me. The code is the exact same. I don't know what's wrong.
@charg1nmalaz0r51
@charg1nmalaz0r51 Жыл бұрын
Love the game but i just wanted to point out your aliens do not move right, in the original they slowly jerked to the left and right, there was a little delay between each move and the less aliens the more they sped up edit - follow up, when you play about with speeds the direction switch and drop amount breaks because the if statements trigger for more than 1 alien
@fnxbcn369
@fnxbcn369 3 жыл бұрын
Big thanks!
@ИгорьСорочак-о6ш
@ИгорьСорочак-о6ш 10 ай бұрын
how to implement this to play with phone? is it possible?
@cccornel5965
@cccornel5965 Жыл бұрын
too bad i can't give you more likes for the way you explained how to get the index in create_obstacle functions, but i can leave a comment and thank you for the clear explanation
@lalitkumarsingh7225
@lalitkumarsingh7225 3 жыл бұрын
Hey Man! This Was Awesome After watching this I feel very comfortable with pygame but I do have one Question and then I will be ready for future projects. How Do I manage states in this game like I wanna Maintain a game_over variable which can be influenced by Our Game Class So that I can stop game.run() Function In my while Loop ?? Other than that I got everything Thanks Again For Such an Awesome Video For Free !
@ClearCode
@ClearCode 3 жыл бұрын
Hey, I will talk about this more in detail next week (probably) in a tutorial about an overworld. Essentially, here is what you want to do: You keep the game class as it is (maybe rename it) and put it inside of another class, and that class will manage the state. That way you can switch them fairly easily.
@lalitkumarsingh7225
@lalitkumarsingh7225 3 жыл бұрын
@@ClearCode Lookin Forward For Your Tutorial. It's Kinda Hard For me to understand it in words. Thanks For Your Time Though ! But I came up with an Idea :-) It was to return True/False From my game.run() method ,whenever there is collision (collision method will itself return True/False in game.run() method). Is this method Acceptable ?
@Pogomeister
@Pogomeister 2 жыл бұрын
I am still at the beginning of the tutorial. The exercise about constraining the player to the window at 11:30 I solved differently. I did not create a constrain function. Instead I modified get_input like this: if keys[pygame.K_RIGHT] and self.rect.right < self.max_x_constraint: self.rect.x += self.speed elif keys[pygame.K_LEFT] and self.rect.left > 0: self.rect.x -= self.speed This also worked at that stage of the game. Is it also a good solution to stick with? Or will there be some issues later on which makes it better to use the constrain function? If the constraint function is not used for anything else later on, the version above should be better just because it is less code, right? I hopefully will get an answer to my question by just continuing the tutorial. But for the case that it will not get answered automically during the video I wanted to post the question already. :-)
@charg1nmalaz0r51
@charg1nmalaz0r51 Жыл бұрын
Theres always multiple ways to do something, just do what you feel is best for your sanity and if problems crop up later modify it, otherwise you are good to go
@quangdungtran2005
@quangdungtran2005 Жыл бұрын
❤❤❤❤❤❤👍👍👍👍👍👍 but I don't know how to reset all the enemies when you want to play again??? 🤔🤔🤔🤔
@eternl_sunshine22
@eternl_sunshine22 Жыл бұрын
im reallly struggling with understanding the create obstacle loops....
@goldenmonkey515
@goldenmonkey515 Жыл бұрын
how to change background
@honeyd5550
@honeyd5550 Жыл бұрын
Can you please do a video on how to make dots and boxes ???
@kulagintimofei7689
@kulagintimofei7689 3 жыл бұрын
Thaaaaank you
@sohamtaparia5691
@sohamtaparia5691 3 жыл бұрын
Well it helped me .. Thanku
@axetogrind
@axetogrind 2 жыл бұрын
problem I am having is with you switch between files, Your youtube screen the file folders are tiny names. You do not clearly announce when you are moving to another file. Solve this just make your file tab readable on VS
@detree
@detree 6 ай бұрын
anyone elses player not continuously moving when your holding down the left or right arrow keys. like i only move space if that makes sense
@for3v3rbuzzstudios448
@for3v3rbuzzstudios448 2 жыл бұрын
Hello, i am have a bit of a problem in my code when i run it in 22:52 of the video , here's the error- File "/Users/user/Documents/Programming/Python/space/laser.py", line 8, in __init__ self.image.fill('white') TypeError: invalid color argument pleas help me
@for3v3rbuzzstudios448
@for3v3rbuzzstudios448 2 жыл бұрын
please reply as soon as possible so that I can go on with my Code
@charg1nmalaz0r51
@charg1nmalaz0r51 Жыл бұрын
@@for3v3rbuzzstudios448 i know its a year later but that code should be fine, its probably something else.
@axetogrind
@axetogrind 2 жыл бұрын
I keep getting file not found error I can't check my entering code
@ceya_96
@ceya_96 2 жыл бұрын
One question: why pygame.display.flip and not display.update () To actualize the display
@asadqureshi126
@asadqureshi126 2 жыл бұрын
I think they have same effect. Both will work.
@priyamittal444
@priyamittal444 Жыл бұрын
Can u make a video on how to add levels in this game
@venugopalbedar4550
@venugopalbedar4550 3 жыл бұрын
First bro
@johnstarfire
@johnstarfire 3 жыл бұрын
I think there are some missing files in the repository, or am I wrong?
@ClearCode
@ClearCode 3 жыл бұрын
do you get an error message? I think there are all there but I am a bit cursed on github :)
@johnstarfire
@johnstarfire 3 жыл бұрын
@@ClearCode sorry, it is my fault, I thought the main.py file should be in the root, instead it’s in the code folder, it works, great job
@RATANAGARWALITINFORMER
@RATANAGARWALITINFORMER 3 жыл бұрын
wow
@rat3735
@rat3735 2 жыл бұрын
Me using Visual Studio Code and this error reportMissingImports
@JaedonHelbig
@JaedonHelbig 5 ай бұрын
gooooooooooooooooooooooooooooooood viddddddddddddddddddddddddd
@cromebuk2958
@cromebuk2958 2 жыл бұрын
❤👍
@kshawn2579
@kshawn2579 11 ай бұрын
Bro what is the code editor name?
@ClearCode
@ClearCode 11 ай бұрын
sublime text
@kshawn2579
@kshawn2579 11 ай бұрын
@@ClearCode thanks
@spaidory874
@spaidory874 2 жыл бұрын
1:31:22 fo rme
@TTTTTT-wn8kl
@TTTTTT-wn8kl Жыл бұрын
1:03:48
@lemagenoob0001
@lemagenoob0001 3 жыл бұрын
hello sir
@salouhimohammed1030
@salouhimohammed1030 2 жыл бұрын
i added and played the laser sound directly in the laser __init__()
@VeLoc1ty_
@VeLoc1ty_ 2 жыл бұрын
48:20 its 42
@spaidory874
@spaidory874 2 жыл бұрын
48:50 for me :)
Breakout in python
3:21:21
Clear Code
Рет қаралды 64 М.
The ultimate introduction to Pygame
3:47:58
Clear Code
Рет қаралды 2,8 МЛН
The joker favorite#joker  #shorts
00:15
Untitled Joker
Рет қаралды 26 МЛН
when you have plan B 😂
00:11
Andrey Grechka
Рет қаралды 65 МЛН
I made Games with Python for 10 Years...
28:52
DaFluffyPotato
Рет қаралды 336 М.
AI Plays Minecraft Forever (and dies)
23:22
Emergent Garden
Рет қаралды 282 М.
2 YEARS of PYTHON Game Development in 5 Minutes!
4:54
Coding With Russ
Рет қаралды 923 М.
Errichto Stream, POI 22/1
3:55:08
Errichto Algorithms
Рет қаралды 157 М.
How to Use Pygame Masks for Pixel Perfect Collision
10:28
Coding With Russ
Рет қаралды 37 М.
Making a Game in Python with No Experience
5:57
Goodgis
Рет қаралды 1,7 МЛН
Flutter Engage
3:58:21
Flutter
Рет қаралды 1,8 МЛН
CODE WITH ME | Python Snake Game
15:36
CS Jackie
Рет қаралды 177 М.
NEVER DO this on SCRATCH ! | EP 3
10:55
SL Smart Mind
Рет қаралды 1,3 МЛН
The joker favorite#joker  #shorts
00:15
Untitled Joker
Рет қаралды 26 МЛН