PyGame Tile Based Platformer Game Beginner Tutorial in Python - PART 1 | Creating the World
Вставка
- Опубліковано 30 вер 2024
- In this Python tutorial I code a Tile Based Platformer Game using the PyGame module. I'm going to cover the initial game setup and how to create the map
Code & assets on my website: codingwithruss....
Alternative link: github.com/rus...
Code for level editor: github.com/rus...
Note, sprites and sounds are open source:
Sprites: kenney.nl/asse...
Sounds: freesound.org/
Check out my other PyGame tutorials:
Space Invaders coding tutorial: • Pygame Space Invaders ...
Flappy Bird coding tutorial: • PyGame Flappy Bird Beg...
Hi Folks, hope you found this tutorial useful. The code and images for the video are in the video description above.
Let me know what you think! And don't forget to like and subscribe 😀
Is this plarform game suitable for class12 final practical project please reply quickly it's urgent
And how many part this have
Thanks a lot but how would you implement a camera cause before when I made platforms manually I would just change positions, but it’s harder with this, if you you read this pls help
Don’t worry after some playing around I got if you work
@@becauseimtobyfilms3559 Glad you got it working!
It was a really good explanation, i really loved it, i hope you will keep making tutorials cause both your voice and explanation skills are epic!
As a novice this is fantastic. I will dissect each video and learn the concepts at my own pace. You have a very clear, logical approach that is so helpful. Thank you for all your hard work. You have something special here!
Thanks, glad to hear it!
20:35 list in the description 🙂.Thanks for tutorial, it is the best.
Oops! This video has been up for a year like this and I never noticed! Oh well, I've since added the github link to the code which has that list for people to copy :)
@@CodingWithRuss ok thanks
I am not able to make the backround show up and the sun how do i do that?
thanks
You're welcome!
Hi a question. The level files (level0_data for example) with which program can I open them to modify them?
And then another thing. I changed the resolution 800 * 800 only that you see everything cut out. How can I solve?
could someone please tell me how he uses the level editor code in the game
When I add a image, the window disappears. Please reply me because this problem has been going on for a year now، Sorry I use Google Translate because I am from Arab and my English is not good
For those asking which editor I am using - it is called "Sublime Text"
This is totally the best video on game coding I've ever come across. Explains everything in detail while providing will to do something alike in the future, keep it up!
Thank you, glad you find these tutorials useful!
@@CodingWithRuss YOU ARE AWESOME!
Your Videos are cool but I have a problem and idk what i have to do :ModuleNotFoundError: No module named 'pygame'
Hi, you have to make sure you have pygame installed first. Check out pygame.org
how do you put the picture into pygame which directory does it have to go in files i am using pycharm
If you are having an error that says "FileNotFoundError: No such file or directory", make sure you have downloaded the assets (images & sounds) from the link in the description and put them into a folder called "img"
That's ok but if you are creating a folder so it must be saved in a location like in the PC's, documents, but how do you set the location of images without any location like this
Can you please help me, where do i put my folder cause i saved the pictures you uploaded in the links into a folder called img but it still says error
@@rohithmatthewsgiji9206 me too same error
@@rohithmatthewsgiji9206 make sure it is in the same directory as your current working directory, else it will not find it
wich sofware you are using, plz tell
is this sublime text ?
Yes
Keeping grinding brother love from India ❤
Thank you :)
thanks for the 10/10 awesome tutorial. the only reason im passing computer science atm
Glad you're finding it useful!
Also I'm making my own textures what do you recommend for the height and width? And whenever I do this code, the ground spawns at the top instead of around the whole screen.
EDIT: I found my issue and fixed it!
9:18
: :
just press "ctrl +D" to copy the content directly to next line :D
where do you get the "sky" and "sun" image from? They are not in the folders I downloaded
Same problem for me
me too!
Me three
Found it here: github.com/russs123/Platformer/tree/master/img
how to solve this quary
Traceback (most recent call last):
File "C:\Users\Admin\Downloads\Platformer-master\Part_13-Moving_Platform_Collision\platformer_tut13.py", line 408, in
world = World(world_data)
NameError: name 'world_data' is not defined
in part_13
Sounds like you've made a mistake somewhere. Check the video again and compare the code in the description to see what's gone wrong.
I saved the sun and sky images, but I could not load them. Do I have to save the images in a specific folder? Thanks.
Yes, you should create a folder called "img" in the same location as your code. You will then put all the images and sounds into that folder
@@CodingWithRuss where are the cloud and sun images?
You uploud this Video on my Birthday
upload*
It is a really helpful, good and perfect masterpiece good work keep it on.I guess your channel will go ahead
Thanks a lot 😊
wich sofware you are using, plz tell
@@CodingWithRuss wich sofware you are using, plz tell
i will do this even do i dont know anything nabout pygame and i make 1000000 errors using it
thanks love it
Sorry to bother you but I can not seem to have the tiles loaded in if you can please tell me what is wrong with my code I am around 17 min in the video and I used my own images here is my code:
import pygame
from pygame.locals import *
pygame.init()
# The screen vars and everthing screen
screen_width = 1000
screen_height = 800
screen = pygame.display.set_mode((screen_width, screen_height))
pygame.display.set_caption('A game?')
#loading images
back_img = pygame.image.load('img/background for platformer.png')
#define main variables
tile_size = 200
class World :
def __init__(self,data):
self.tile_list = []
#load more images
stone_img = pygame.image.load('img/stone.png')
row_count = 0
for row in data:
col_count = 0
for tile in row:
if tile == 1:
img = pygame.transform.scale(stone_img,(tile_size,tile_size))
img_rect = img.get_rect()
img_rect.x = col_count * tile_size
img_rect.y = row_count * tile_size
tile = (img, img_rect)
self.tile_list.append(tile)
col_count +=1
row_count +=1
def draw(self):
for tile in self.tile_list:
screen.blit(tile[0],tile[1])
world_data =[
1,1,1,1,1,
1,0,0,0,1,
1,0,0,0,1,
1,1,1,1,1
]
world = World(world_data)
#the main loop
run = True
while run:
screen.blit(back_img,(0,0))
world.draw()
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
pygame.init()
pygame.display.update()
pygame.quit()
I figued it out no problem
Can use android in mobile the typing make easy
Thanks a lot Russ you made my day by making a course worth 1000s available for free . Thanks a lot once again may god bless you and your channel get 1 M subs soon
Thanks for the kind words, I'm glad you found the tutorial helpful :)
The tutorail is really good but for me
planine_img = pygame.image.load("Za igricu/planine.jpg")
Does not work. The name of the folder is "Za igricu" and the name of the picture in that folder is "planine.jpg" and it says that such a fail does not exist.
Does someone knows what's the problem?
Space in the folder name. Replace the space with a _
@@QX3R01 It still does not work
Actually I have a problem... My pygame window becomes black
Exactly whats happening to me. Are you using replit.com too? Cuz maybe thats the problem
sprites link is not work
Amazing vid, just how do you actually put in the image files? I'm a bit confused how you format it.
Never mind I figured it out.
run = False
^
IndentationError: expected an indented block
how to fix it?
idk
not sure
Make sure it is like this:-
if event.type == pygame.QUIT:
running = False
the indentation matters it's basically like when the action happens i.e. quit it will stop running which is decided by the indentation.
@@smritiroy6526 okeyyy thanks bro
@@smritiroy6526 but i have another problem with world=(world(worl_data)
Indentation eror
ing, plz tell
Hi Russ I love Ur vids
Hey I made ur game using the Tutorial u make
Its on FaceBook
That sounds cool!
Do you have a discord account or any server so that I can ask some questions?
What python on you using I’m trying it on 3.7 idle and it’s not working
I used sublime text editor. Not sure the version of python at the time but it is 3.x so you should be able to run it
always amazing videos youtube algorithms ignores them
Thanks, glad you liked them!
I got lost add the images part lmao. How to I import images on my pycharm
hi.can i make this game on PYTHON IDLE ??
I'd recommend using a decent IDE. I use sublime text editor which you can try for free
X = 'Thank u so much'
I = 0
While I =< 1:
print(X)
print('You're Welcome!') :)
Can someone please tell me if I can follow this tutorial even if I know nothing about Pygame? I'm pretty decent in Python but that's about the only thing I know 👀
It's a beginner friendly tutorial and I explain everything step by step in it so if you are already familiar with python then this should be fine. :)
@@CodingWithRuss Ahhh I'm glad to hear that :D Thanks a lot of replying man, I'll be sure to check out your playlist!
I knew it would be a great tutorial from the beginning, thanks a lot😀😃😃😄😁👍👏👏👍
Thanks a lot :) Glad you liked it
Very good tutorial! Just finished the first part and everything is explained very well and at a good pace! Looking forward to the following parts
Thanks, glad it was helpful!
i type code in pycharm and it show me next wrong:
unused import statement 'from pygame.locals import *' :2
.
but generally code readable
thanks for your awesome guides!
Thank you! That's fine, I import them in the first video but they are used later on, so this message will disappear :)
Your video is very good. Please help me with something. My screen is showing the height and width as very large. How can I reduce it
😭😭😭😭😭😭😭😭😭
Part 2 - "Creating the player" now uploaded: ua-cam.com/video/W_JRd3ntyBg/v-deo.html
Can you make a video about how to animate sprite sheets?
Hi, I've just uploaded the 3rd video for this platformer, which shows how to do animation: ua-cam.com/video/gaGh-zlkrtE/v-deo.html
How do I implement the pack into my pycharm?
Hi bro...Thank you so much. I finished my project successfully with 10 levels because of you. And I need one more help from you. I don't know how to convert my file to .exe file???please bro help me
Hi, yes sure, I have a video on that here: ua-cam.com/video/2X9rxzZbYqg/v-deo.html
Thank you Russ...You are a Teacher. You don't know how its helped me. Now I converted .py file to .exe file. An amazing video. Once again Thank you Man!!!🤩🤝🙏
@@kannappankannappan4279 No problem :)
Pls can you tell me the best editor to use for games
Bro you should be getting way more subscribers from this!!! So i'll subscribe
Thanks! :)
because of this video now i know how to add pictures in python THANK YOU!
Awesome, glad it was helpful!
so ive got the sky and sun downloaded into the img file and its all running smoothly now but because screen height and width wasnt at 1000 cause it was to big for my screen the sky img isnt fitting correctly. is their anyway i can somehow zoom out of the image on my window? i cant get all four clouds to be inside my window screen.. someone please help
I KEEP GETTING NO SUCH FIILE OR DIRECTORYY ERROR WHEN I TRY AND ADD IMAGES, shit is so stupid
Traceback (most recent call last):
File "C:\Users\\OneDrive\Documents\python\Platformer.py", line 32, in
for row in data:
NameError: name 'data' is not defined
help please, I copied everything exactly
Cool, but prefer Unix system V and BSD, for example freebsd with C/C++ and pascal.
Cool demoscene.
can you tell me what width and height should i keep for my 15.6 Hd displlay pc pls
It depends on your screen resolution. You could try 800 x 800. But you have to adjust the size of the other items to match.
@Coding With Russ thank you to are very genuine and kind. I am currently working on the shooter that you made. I am a complete
Noob in coding if u don't mind will u help me please.
Have 46 years but 19 years make game how this.
Prefer freebsd Unix and openbsd, and aix, all with C/C++.
More 24 computers in my laboratory.
For the path do I put the full path or just what is after the user name? When I put the full path or the part after the user it gives an error and the window just opens and closes quickly.
My images and screen width and screen height is over the screen
I have big screen pc
I do not know what is the error
I made this game a bit too big. You can make it smaller by changing the screen_width and screen_height variables, then adjusting tile_size so it equal to screen_width / 20.
@@CodingWithRuss I got it.
Thanks for replying 😁😁
Bro im facing a problem with 17th line its ,sun_img = pygame.image.load('img/sun.png')
FileNotFoundError: No such file or directory.
And i also downloaded the sun.png... please help me
Make sure the sun.png and the program are in the same file. If it still doesn't work, try deleting the img/ part. Mine is just ("sun.png") and it works fine.
This video is awesome!! Thank you for the awesome explanation 😊
Thanks! Glad you found it useful :)
My personal Tip is: Don´t make games in Python, this tutorial seems to be good, but python sucks for this stuff. Try scratch, GameMaker, Unity, Godot, depending on your level and preferences
Xbill was make programmer in C/C++, have someone code python.
Whois of Unix need perl.
Ummm
I did everything the same but it says ModuleNotFoundError: No module named 'pygame'
Hey! great video. Any idea why my screen is longer (height) than my settings? My png display isnt filling the black space. help please 😅
bro what's the size of your background image? mine is 100 x 100 mm but still the full image isn't coming..
I'm using Visual Studio Code for this. Will it still work? My screen isn't appearing when I run the file so I'm just wondering
sun_img = pygame.image.load('img/sun.png')
it is not running . There is a mistake maybe!
do you understand why?
@@zapor7209 I don't know, maybe it's about python 3 or else
@@zapor7209 ohh i already forgot it.Sorry but can you find the correct answer yourself?
May I ask how to add the files given by you to my project? I tried opening the file in PyCharm but unsuccessful. Thanks!
I haven't used pycharm much, I use sublime text editor but it should work in the same way. Save the files on your pc and run the code
i have a problem where can i get those character
The code and assets are linked in the video description
I don't like how he basically said to stop copying part way through the episode, but then starts the next one acting as if you have copied it already.
Also, just ignore the magic function? Not going to explain what it does or how it works? I mean, if they are going to explain it later, I still think they should give a reassurance and explain that they will explain it later.
Other than that, the first half was good.
thank you very very very much, you help me a lot
Glad you liked it
can u help me past this error
TypeError: draw() missing 1 required positional argument: 'self'
I do have another question, how do you adjust the sizes to fit the page?
i think it depends on your screen width and height, and you can adjust the 'tile_size' variable to align it with the dimensions of your game. Another method to do this is to use some simple math. Im not sure if this works when screen width and height are different values but here is what i did:
1. multiply screen width by height(for me it was 460 x 460 = 211,600)
2. divide your result by the number of tiles.(in my case i have 16 tiles so 211,600/16 = 13,225)
3. take the sqaure root of your number and assign it to the 'tile_size' variable(in my case the sqrt of 13225 is 115 so tile_size = 115)
hopefully this helps to align the grid with your screen
HEY Russ, i cant open the assets link. And where can I dowland the blocks and stuff like that?
🙄😖🥺🥺🥺🥺i cannot get it its tough
how did you learn coding plz tell
Maybe it's just me but he's going too Fast, just wanted to say and it's really hard for me to understand.
You sound like Griffpatch... you wouldn't who that is :|
W tutorial
Thanks
This was a really good tutorial. I'm just getting into OOP and this was very helpful.
Glad it was helpful!
I have a question What is OOP
@@Prangshu12 Object Oriented Programming
god thank you i found this vid
HI,I can't find the image for this .Can someone please tell me how after I download the zip file
can u please tell me that is this python software
Yea its python using the pygame module. I code using sublime text editor in these videos
You are seriously underrated. You need to get 1 million subs by now!!!
Thanks :)
@@CodingWithRuss I just said the truth bruh
anyways pls make a tutorial video of how to make minecraft using pygame
i don't get the part where you do sky_img and bg_img I did it and when I tried It Appeared for a second and then disappeared
hey, so great tutorial, but could someone tell me what is it saying at the end of the lines in def draw_grid(): the time is 7:13
U r osm..❤️❤️❤️bro U make a Lots OG games..For.Giving Us best Experience
Thanks :) Glad you like it
how do u run this, means what shotcut key you use to run the game or run the cmmand plz anyne tell
Did you figure it out? on sublime text editor the shortcut is ctrl+B. if you are using a different editor you need to look up how to run the code
@@CodingWithRuss i press that but no game screen comes
Awesome. Thank you for sharing this with the rest of the world. Be Blessed. Salutations from France.
Glad you enjoyed it!
i did the whole code but the problem was that the game window opened was black and lefted straight away
Je n'ai pas vu quand il a été créé if self.map == 'world' and self.player.feet.colliderect(self.enter_house_rect):
self.switch_house()
self.map = 'house'
the sun.img not found in the assets folder can you help me with this
Please help it is saying no image found in work directory of my game location
Whenever i write the loop to keep it running it just comes up with problems and does not work
not working the sun and sky don't work
it will if you import it from your asset folder (not the same folder as shown in the video as yoou probably have a different path to the images? try something like ('./assets/sun.png') if you use a folder called assets
Hey, that game over sound is from brawl of the objects
I don't have Sublime text 3. What would I use?
when i try to run after i set the images it gives me an error whit something that says like its not in the dictionary or something like that do u know how to fix it?
Hello, Your videos are amazing I have been watching for 1 and a half year now. Though I had a problem when I was doing this at part 13 and finished whenever I tried to run it, it wouldn't recognize the images, it was saying that they didn't exist.
Hi, thank you! It means the images are not where it things they are. So make sure you download them all and put the correct file location into the code
@@CodingWithRuss Could you please explain more about that, and please tell me where to put them, because I moved them to a specific folder on the desktop where I saved all my code and it still wouldn't work. please help!
@@rudranilagiri4571 Did you solve the problem?because I am having the same problem
I've go the same problem too