PyGame Scrolling Shooter Game Beginner Tutorial in Python - PART 1 | Creating the Player
Вставка
- Опубліковано 29 вер 2024
- In this Python tutorial I code a Scrolling Shooter Game using the PyGame module. I'm going to cover the initial game setup and how to create the player
Code & assets on my website: codingwithruss....
Alternative link: github.com/rus...
Credits for assets used:
mtk.itch.io/gr...
gushh.net/blog/...
erayzesen.itch...
secrethideout....
soundbible.com...
soundimage.org...
Check out my other PyGame tutorials:
Space Invaders coding tutorial: • Pygame Space Invaders ...
Flappy Bird coding tutorial: • PyGame Flappy Bird Beg...
Thank you so much my Guy!! this is awesome. Imagine a project like this would cost thousands of dollars to learn in post secondary institutions, but here we are, the universe has blessed us a Man that willingly share his knowledge for FREE to idiots like me to potentially make it in life. THANK YOU.
Haha thanks! Glad it helped
Great video man. This is definitely the most educational pygame video i've ever seen. The way you explained OOP was perfect.
Thanks a lot! Glad you found it helpful
woah! this is by far the coolest and educational tutorials on pygame i've ever had! you're awesome! thanks a million!🤩😊
Thanks! Glad you liked it :)
y
Very cool tutorial. Thanks for sharing your knowledge! 👍
Thank you, glad it was useful!
Fantastic! I always believe anything can be explained, if its explained correctly and you sir have nailed it! You have talked OOP, that can be quite complex, and explained it in a way that can be understood. I agree with all the other comments here. This tut is one of the best I have seen and is worth a sub alone, so I have. Thank you. :)
Thanks Tony! Glad to hear it :)
You make it sound like magic, but the achievable kind. Thank you so much for the tutorial !
Thanks a lot :) Glad you like it
Awesome, love your tutorials. Cant wait to follow along with this one! Many thanks for sharing with us.
Glad you like them!
woah! this is by far the coolest and educational tutorials on pygame i've ever had! you're awesome! thanks a million!🤩😊
Thanks :) Glad you like it!
Why did you copied the comment ?
@@abhayagarwal5097 because all of them have copied so why I can't
Woah!!!!! One of the best tutorials ever on pygame THANK YOU VERY MUCH BROTHER ❤️
Thanks! Glad you liked it :)
you explain better than a person in a paid course
its help me learn pygame a lot
Glad to hear it!
wow this is so cool! How long did you spend making this set of videos?😃😃😃
Im so exited to make this thanks bro
Have fun! :)
This is amazing!
Thanks!
your explaination and the game is totally amazing🤩😊
can u give the link to download these images
or how to get these types of images
Thanks! Yes the images are on the github repo in the video description
Dw bro ADHD helps out so much with soft soft i find. day dreaming always gives new ideas so when i snap back i got that vision ready
i am being your fan.great video
Thanks, glad you like them
YOOOOOOOOOOO!!!!!!!!! AMAZING TUTORIALS AS ALWAYSS!!! 😎🤩😌
Glad you like them!
great job bro!!!!
Thank you!
Thank you Russ all your awesome content walking us thru such cool Pygame builds, Hey Russ let's build Mario World 3 one these days the game engine and the level editor I want that game on MacBook so much the music the music baby Yoshi, are we allowed to build that game on UA-cam w/o upsetting anyone?
very good!
Thanks!
Helped me alot thanks
Why my players picture dont want to show on screen, I checked code multiple Times and its correct
i can't connect images to my work. how do i fix it.
line 15, in that is what pop up
Hi! I had a question about the image. I think you need the image for the character to already be saved, so where would I find this?
Hello, the images are all available to download from my github. I've linked it in the video description
Bro can u tell how to add my own image where u add player
where do you got the img of player
time laspe 5.10
awesome tutorial. please how can we get access to these your images. thanks
Thats amazing👏🏻👍🏼👍🏼 Will it run in VS Code ......?
Thanks! Yes, it doesn't matter which editor you use.
I'm just a little confused with the order of properties, in the arguments x and y are at the beginning, and in property is last
That's OK, the order of arguments is important when you are creating an instance of the class so for example the line "player = Soldier(200, 200, 3)" matches the order of def __init__(self, x, y, scale).
But when you are using the variables inside the init() method, the order doesn't matter.
@@CodingWithRuss thx
i keep getting a error called No file 'img/player/Idle/0.png' found in working directory i have downloaded the github and textures and i restarted vscode and even copy and pasted the code and downloaded the assets any fix ( am using vscode )
Sometimes this happens if you are not running the program from the game folder. Go to File -> Open Folder and open the game folder, then try running it again and see if it works.
Where are the images
sir, in importing the png image I am getting the background small square boxes also. can you please tell how to eradicate it?
Can convert this game from py to exe to share it with my friends please answer
In the terminal you have to go to your's game folder (using "cd [folder locate]"), then you have to install pyinstaller using "pip install pyinstaller". After that you have to create the .exe while using de command "pyinstaller [yourfilename].py".
Now you must have a folder named 'dist' where it is the .exe . Open it and if it does not work you have to put the assets of your game in the folder dist. That's it 👍.
@@nicop496 thank you
You can also use AutoPy2exe which gives you a nice GUI for adding custom icons and such
@@nicop496 where is the the dist folder locate
@@t-gaming6689 If everything went good, dist and another folder named 'build' must have to be with your's game file
7:41
i cant open the images dont know
can you tell me where do i get the images
There's a link to the github repo in the video description where you can download all the assets
Mine is showing this if event.type == pygame.QUIT:
^
IndentationError: expected an indented block
why is my screen bigger than yours? i set the same screen width and height.
Depends on your monitor resolution
@@CodingWithRuss Oh, this explains a lot. Thanks!
where do you get the images.
I just search on google, but a lot of stuff I use comes from itch.io, there's lots of good open source assets there
where did you get those characters from?
I think I found them on itch.io. It should be linked in the video description.
@WithRuss oh ok thanks love your videos
I'm very sorry your videos are great, but I have a problem. after entering the soldiers class, the program gave this error TypeError Traceback (most recent call last)
in
83
84
---> 85 player = Soldier(200, 200, 2, 5)
86 enemy = Enemy(400, 200, 2, 5)
87
~\anaconda3\lib\site-packages\pygame\sprite.py in __init__(self, *groups)
114 self.__g = {} # The groups the sprite is in
115 if groups:
--> 116 self.add(*groups)
117
118 def add(self, *groups):
~\anaconda3\lib\site-packages\pygame\sprite.py in add(self, *groups)
132 self.add_internal(group)
133 else:
--> 134 self.add(*group)
135
136 def remove(self, *groups):
TypeError: add() argument after * must be an iterable, not int
I would be very grateful if you could help me understand what this means. thank you very much in advance
Part 2 uploaded, in which I add in keyboard controls to move the character: ua-cam.com/video/7WsE1Vy1Krg/v-deo.html
So I am not doing the exact same things as you right now, I am making my own project with help of this one. So one question, you scaled up the image at 9:41 however I want to scale down my image. I thought you could use decimals like 0.5 however, this makes my lengths float values. So how would I do it?
Yea you have to be careful with that. You could use int() to turn the floats into integers.
Following along with this series and adding my own ideas to my project as I go along. Already I can see that with the first video you are clear and concise when explaining difficult concepts, and you have really helped me so much. Thank you so much for posting quality content like this!
Thanks! I'm glad you're finding it useful. Hope to see a demo of your project when you finish it :)
Great tutorial. Ill be following this series to make my own but Ill add some of my own ideas to my game. You are good at explaining whats going on and that makes it easy to follow. Thanks
Thanks, glad you find them useful!
This helped me so much!!! had some problems with using classes but you cleared it for me! you went right to the point and it is explanied so good! best tutorial ever!
Thanks! Much appreciated. I'm glad the videos are helpful :)
Props to you for not only teaching people how to make an actually interesting game, but also taking an object-oriented approach right from the start. This really stands out from the crowd as a tutorial. I just hope the code isn't outdated by now with updates to python / pygame.
I'm having a problem in the code, it says
AttributeError: 'Soldier' object has no attribute 'draw'
please help me fix this problem,
thank you.
Never thought making a difficult game like that could be explained so easily, thanks a lot 😭♥️
Thanks! I'm glad it actually makes sense :D
Having problems getting the character files into the code. i have them all in a file called player and when I enter their specific name it will not input that image?
you need to edit the file player onto the programming language you use
@@eliasbegashaw1707 What do you mean by that Can you plss explain me in detail I have everytime I put full path of images it's shows an error plss help 🙏🙏🙏
is there any tutorial that teach how to import images cause i having problem with it
AMAZING! Thanks for the videos!!!
Glad you like them :)
Hello there! I am here to learn pygame and i just noticed that you don;t have an icon. To do that just put the next code:
icon = pygame.display.image.load("imagename.png")
pygame.display.set_icon(icon)
what did u use to import images and where did u put the images?
I'm gonna lose my mind, I've looked at hundreds of tutorials and explanations but I don't understand anything about the images one bit. Can you please explain to me how to do it. Thank you in advance!
when I import the file into pygame and use the pygame.image.load ('filename.png') it says "FileNotFoundError: No such file or directory" please help :)
@@ghettofilms2792 I think you need the file path ex. '/Users/user/Desktop/textures/png/Idle__001.png'
@@ghettofilms2792 listen you need to create a folder with your game script in python and in that folder you need to have your images and everything, after that before launching your game you need to type in the terminal cd "YOUR FOLDER PATH HERE" for example cd "assets/png.png" something like that. this will tell python to look at that folder
@@opst1x89 oh ok I’ll try that. Tysm :)
Did it work? If not, I always have my sprites in the same folder as my python file. This must work
it says FileNotFoundError: No such file or directory.
hey if someone could respond to this and help me out I would be so thankful, so every time I run this game my picture that i used doesn't show up until I click the exit button can anyone help?
Don't worry about it I found the problem I had my display update executing after the if statement so the screen wouldn't update until the spilt second of the window closing.
Really great tutorial but I have one problem, when I try to make a player 2 it ends up in the same X and Y position as player1.
Same, I was thinking where is the other player 😅
This is fantastic!😃Looking forward to follow along.
Thank you!
how do you get python
Great explanation, I understand all the small, big and hard concepts. This channel deserves more subscriber's. 😀
Thanks! Glad to hear it helped :)
Def:😁😁😁😁 class:💀💀💀💀💀💀
as someone who's spent the better part of a year coding to pep8 standards, your code annoys me
But otherwise, great video series. Loved following along and trying to keep up
Man I can't thank you enough for this tutorial series. I'm using the game logic as a foundation for my A level CS project but I've changed the player and enemy sprites and eventually when the enemy engages in a battle with enemies, im gonna make it so that the game loads up a CS Multiple choice question and some more jazz. I got 7 weeks left to code, document and submit it and this series is honestly gonna be a lifesaver. Thank you so very much.
howd it go mate
There are some parts that are not working and you do not address the problem
Because this tutorial is probably for people that are a bit experienced in python
Hi Russ! my name is Danil, and I have made a game use your video tutorials, can I write your name in credits like second programmer, I have added many chips like bosses enemy who summon other enemies, doors, results at the end of the level and double jump
and Fullscreen Mod
Hi Danil, that sounds really good! You've added so many features. Thanks for including me in the credits :)
@@CodingWithRussHello Russ, it's Danil. Again. How can I spawn the world in the random Y or player Y?
i think im finally getting it thanks man if u ever do decide to put out a course im interested
Thanks, glad to hear you found it useful! And funnily enough, I do have a course :). There's a demo of it on this video plus the first 6 or so parts are free to view as a demo: ua-cam.com/video/qSBmjSsscI4/v-deo.html
@@CodingWithRuss and again thank you
clips. I use a drum loop and afterwards I want to record a appguitar. What happens.. the drumloop starts to record again along the
Well looks like a found a new lil project to try!
Hope you like it!
million wows. great tutorial .
Thank you :D
Nice Video! Just one small problem. For line 15, I put in the same code (just with my own png), and it can't find the file. I also typed img = pygame.image.load('insert my png'), and it still can't find the png. Is there a way to troubleshoot?
you have to put all the images that you want to use in a file named 'img' , then you put that file into the projet file
@@andrewgilmore9181 Oh, now that makes sense :) Thanks!
bro can you please give me the skin link??cause i can't find any. by the way your tutorials are aweosome.
that needs more views
how do you gut THIS pygame I’ve looked everywhere I can’t find it
thanks mate tNice tutorials was a big help
No problem, glad it helped!
Can anyone tell me why my script not working i imported everything it said error on image idk why when i change images its same can anyone help me??
i love how you explain python basics like oop. i'm just getting started and the way you explain it and show how it works makes me understand it better than in my udemy course ^^
thanks and keep up the good work!
Thanks! Glad to hear it is making sense :)
Thanks 🙏
Welcome!
The way you explain everything. perfect. thank you!
Thanks, glad to hear it!
Yo how do I find the location of the file that I am inputting. Like the PNG image
don't give up!, there are more difficult programs then tNice tutorials one
When I type in the code, it tells me this.
File "C:\Users\home office\PycharmProjects\ZeldaStuff\main.py", line 24, in
player = Soldier(200, 200, 3)
File "C:\Users\home office\PycharmProjects\ZeldaStuff\main.py", line 15, in __init__
img = pygame.image.load('img/player/Idle/0.png')
FileNotFoundError: No file 'img/player/Idle/0.png' found in working directory 'C:\Users\home office\PycharmProjects\ZeldaStuff'.
Give a proper directory like this: 'C:/Users/(PC Name)/Downloads/2D Shooter files/img/player/Idle/0.png'
1) Go to 0.png file, right click on it and click copy as path
2) Open Pycharm, paste it on the needed place, replace all '\' with '/' and remove all "
uninstalled and then again reinstalled, do you know what might have happened to them ?!
What kind of python are you using? Is it shell or Idle python? I can't find it.
It's sublime text editor
This will not work on Linux or mac without modification because you do not use the path separator for Linux / Mac. In windows it is backslash (\) but in everything else it is forward slash (/). if you
import os
sep = os.path.sep
filespot = "directory" + sep + "directory2" + "file.txt"
this works on everything. ;)
Thanks for the tip! I didn't know about ".sep", pretty handy!
@@CodingWithRuss unfortunately, most people don't. Which is a real shame since one of the coolest things about python is if you write it properly, it runs on everything.
hey man i’m getting an error saying no avalible video device. I’m on mac. help
Thank you very much sir. Clearly understand.
Sir please make the playlist for Super Mario game
Thanks! Glad you liked it. Super Mario would be pretty interesting to remake for sure!
4:15
I'm a new student trying to learn, so I can become a programmer with python and I have a project on how to make a port scan.
So far I already make a port scan with Python3, and it scans fine, give a date and everything working good so far.
I see on your video tutorial, it is very good.
I would like to ask for your advice if you can and guide me on how I will add this 3
in a Python script, I have:
2. System should look for all the ports between the range of 1 to 1025
3. If the Ports is open, it should create a file and add an entry for port number
4. In case of any exception for instance “host is not available”, “host name could not be resolved” or
due to any other error, you need to write that exception into the same file.
Thank you and Merry Christmas.
Nice video, Thanks!
Neatly explained, like & subscribe from me.
Thanks Anton, glad you like it
i couldnt get the sprite to show up i even put the whole file name but it was just black
How do you get the player sprite?
It's on my github, you can download it from there. I originally got the sprite from itch.io
Bro You are the best! but still why is your popularity so low? 😐😐☹☹
far, and makes confident about using the DAW the first ti.
I may have missed it but where to I put an image for python to load it from? I've got a .bmp but i don't know where to save it for python to be able to load it (if that makes sense).
you can save it anewhere but you need to past the path in pygame.image.load()
I don't know how but I've failed 4 minutes in. I've copied your code verbatim but my window does not stay open. I'm guessing I've got the wrong version of...something installed?
Does it close out with an error? If the window pops up and closes without an error then the game (while) loop may be setup wrong. The code for this first part is in the video description so you can try running that and see if it works
What do I do with the assets
good work and thank you so much, Greetings from Egypt
Glad you liked it!
by far this is the most advance thing i coded but when you say it, it feels a lot easier
Glad to hear it's making sense. It's the most advanced thing I coded too 😅