Pygame Platformer Tutorial - Full Course
Ғылым және технология
Making a platformer with Pygame is a fun way to learn both game development and software engineering. This tutorial covers a variety topics including tiles, physics, entities, particles, sparks, camera, parallax, enemies, AI, combat, level editing, level transitions, making executables, and more!
Project Reference Resources:
dafluffypotato.com/assets/pg_...
Wishlist Yawnoc (Made with Pygame):
store.steampowered.com/app/28...
My Discord (ask questions here):
/ discord
Old Pygame Tutorial Series (without OOP):
• Pygame Tutorial Series...
Amateur and Advanced Pygame Tutorials:
• Pygame Tutorial Series...
• Pygame Tutorial Series...
Pygame CE Video:
• Pygame CE - Better & F...
Pygame's Performance Video:
• Pygame's Performance -...
Physics Explanation Video:
• In-depth Pygame Physic...
Timestamps:
0:00:00 - Introduction & Tips
0:03:55 - Installing Pygame
0:07:04 - Creating a Window
0:16:42 - Images, Input, & Collisions
0:33:07 - Player, Tiles, & Physics
1:27:49 - Camera & Sky
1:46:43 - Optimization
1:57:51 - Animation
2:22:25 - Level Editor
3:13:26 - Particles
3:35:03 - Jump & Slide
3:50:45 - Dash Attack
4:10:07 - Enemies, Guns, Death, & Sparks
5:11:33 - Screenshake
5:15:21 - Level Transitions
5:26:11 - Outlines
5:37:40 - Audio
5:45:57 - Making an Executable
6:02:20 - Next Steps
Patreon:
/ dafluffypotato
My Website (links to games):
dafluffypotato.com
Potato Tier Patrons:
Agent Effe
Eivind Teig
fatcake
RyDawgE
Sam Cork
GaryTMSFruitcake
Dale Topley
Jb mandri
tbf135
#python #pygame #gamedev
Пікірлер: 417
Here's a tip: VSCode shows the current object and function I'm editing right under the file tabs, which can help you keep track of where I am at all times. Clarification: If you have larger entities, they need to look up a larger area of tiles around them for physics. I used a 3x3 table in the tutorial, but you may need a larger one for large entities. A 5x5 table would be every pair of numbers between -2 and 2. (3x3 is -1 to 1) As of the release of this tutorial, I'm still using Pygame CE. They've actually released another update since I started working on this video as well!
@rubendriezen7177
10 ай бұрын
I made my own programming language in python!
@herikgiammaria9961
10 ай бұрын
I love your work!! I love love love it, I study pygame for your videos and I try to improve every day! Could you put subtitles in this video of yours? I'm Brazilian and I don't understand your videos very well when they don't have subtitles
@DaFluffyPotato
10 ай бұрын
@@herikgiammaria9961 I think KZread may still be processing the automatic subtitles. There's no way I could write up manual subtitles for a 6 hour video though. I just do manual English ones for my scripted videos now since I can just put in the script. Also, I'm impressed that the automatic ones are useful since it often doesn't understand what I'm saying.
@herikgiammaria9961
10 ай бұрын
@@DaFluffyPotato Thank you very much!!!! I thought so haha, after all it's a 6 hour video! KZread must be processing, I'll come back to watch it later! MT thanks for helping this community to grow, I appreciate you and your work, hugs
@AndrewHTR
10 ай бұрын
@@herikgiammaria9961 salve herik
You are a wizard of using Pygame, your previous tutorials were amazing, and the amount you've been able to build up around the library is immensely impressive. Thank you for sharing your experience and insight to everyone
wow i remember a few years ago following your platformer tutorial, very glad to see you continuing the series :D
Thanks so much for the great tutorials! It’s awesome to see your thought processes and see how you make such high quality experiences using python!
Just finished this amazing tutorial, took me about 4 days though spent about 18hours on it. But it was worth every second! This is the first time I actually worked with Pygame, and after your tutorial, I definitely have quite a few ideas of what I can do on my own. Will be checking out your other tutorials as well. Thanks for some amazing content !
This is actually the best video i've ever seen that explains things very easily for a beginner and helped me understand the "WHY" behind every code. Thank you so much, subbed!
this is crazy. a tutorial from the actual best, i can't wait to do this.
So happy this was uploaded, couldn't find a better person to explain pygame then this legend, Well done Potato keep killing it
this has helped me so much now im hooked on your videos :) also remade my platformer im working on thanks to so many of your techniques. and joined the discord and there are so many helping people there! looking forward of what your'e gonna do next! 😊
I was literally following your old pygame tuts and if they werent alr a blessing we got this :) thanks man
It's great seeing your tutorials, can't wait to try this myself!
This is the best pygame platformer tutorial I've ever seen! Thank you!
on 2020 you totally saved my butt on my programming project with your first tutorial, I'm really glad that you keep posting this tutorials, greeting from Colombia!
This smooth camera movement trick is fucking amazing. I had to go over the geometry of it a couple of times, but once it clicks, holy shit, it makes so much sense.
Thank you so much for this, it’s so cool that you « remade » your old tutorial séries and improved it!! Thx
What a great tutorial! Clear, concise, and not tiring to watch :) feel like i got a lot from this, thanks
Around 32:34 a good practice is to stop and try to code in left and right movement, then add a collision box on each side at equal distances. Helped me understand the code and get a better grasp for placing things in relation to the resolution
@sc2sperwerfy249
4 ай бұрын
hey, do you know witch event i have to use for the key right and key left? I cant find them in python. thanks
@kuba.9108
3 ай бұрын
@@sc2sperwerfy249just normal eventtype K_UP or K_DOWN i belive
thank you for the great tutorial :D, will be watching it over the coming days!
Amazing tutorial. I've tried a few others, but this one is just what I needed. I do deviate here and there from your code. I added vsync to the window. But vsync only works with the flag pygame.SCALED. So I removed your method of scaling (drawing a 320*240 surface and then upscale it in the main window). The amount of experience and information you give is really impressive. Thank you so much👍
This is amazing, brilliant work!
I did not expect a banger like this from you, I went from "oh new 10 minute video of his old tutorial" to "course? So 1 hour? That's unexpected" to "bros brain turned to mash patatos of he done this"
This comment is the equivalent to 1 million likes, at least for my heart.
@FrankieDev
3 ай бұрын
each like on this is another million so you have provided 63 million likes so far now
@LawrenceAaronLuther
2 ай бұрын
You said it. What a wonderful gift this video is
@goodlookinouthomie1757
Ай бұрын
Well I'm not writing a sonnet about it but I agree is was an awesome tutorial.
@agentnull5242
Ай бұрын
100 million likes.
It took me several days to finish it and i really learned a lot, thanks!
Oh my god!!! its soooo perfect!!! I'll take this tutorial this Saturday!!!
Thanks a lot for this, the tutorial is a great, comprehensive intro to pygame!
Your graphics are AMAZING!! ❤❤
Hi @DaFluffyPotato, I ran into a problem where im not able to locate the png's in the player, tiles and physics part. Is there a way to fix this?
It's another great tutorial, Fluffy. Thank you
Finally, a good tutorial on pygame! Thanks so much
This is a great tutorial. Some things I would like to see is a tutorial on a way to implement 3d isometric levels(editor and player) and menus and sprite sheets as assets. Thank you for all of your help.
i just migrated to pygame from html and js canvas, am skimming through this tutorial and it's very fun. Learning OOP for games is really worth it🙂
After the optimizations around 1:52:15 I adjusted the tilemap __init__ to add a million tiles in each direction instead of just 10. it took a while for the project to start but even with 2 million tiles loaded into the tilemap it was still buttery smooth once it got going! (Using python 3.12 and pygame ce as of 11/9/2023)
@DaFluffyPotato
6 ай бұрын
Yep, that's expected. You can have some pretty massive worlds. Often times RAM will become an issue before CPU usage in those cases (provided you don't have too much on the screen at once).
@lucaivaldi4520
Ай бұрын
@@DaFluffyPotato I wonder if the optimization is more about not having to query the whole dict more than queuing a lot of draw calls. Of course premature optimization is the root of all evil and we should always benchmark before trying to optimize. I think the SDL library (and the backend it uses, Opengl, Metal, Vulkan..) will be more than happy to discard any draw call that draws off the screen, but there is the cost of querying the whole dictionary anyway, so your solution could cut the time spent there. Anyway, I'm not sure how much of an issue that could be. Anyway, this is only something I'm asking myself and your videos are super, thank you!
This guy has to go down in the books as the best Python game developer.
Just what I needed in my life. Thanks so much !
Could someone help me with the following: When running after the 2:40:00 mark the tiles that are being placed are transparent instead of full? When I change the alpha of the current_tile_img the placed tiles are not transparent anymore. How can it be that this is not the case in the video.
God damn Fluffy , you really went in with this one
Awesome stuff you did sharing this , many thanks :) . One thing for those who made it to enemies :P : while DaFluffyPotato does mention and switches to off grid placement for the player ( and subsequent the enemies ), if one does place the spawners by accident on grid like me, extract will fail. This is because the spawners are not part of self.offgrid_tiles, but self.tilemap, and the loop in the extract function its done on the self.tilemap directly and not on a copy. Reckon by accident and the loop should be done on a copy to catch this cases.
@Nolexes
Ай бұрын
I totally overheard the offgrid part couldn't get my game running anymore and got different kind of errors trying to fix it so thanks for the comment. I bet it would have taken me ages to find this out on my own :D
I almost cried not finding that typo that didn't let me start the game at the end of the cloud part. Dude I love your insights you give into various methods of handling stuff. Super abstract thinking. I aspire to get on that level at some point. This is my first step into game development. Hope I get my mind primed the right way following your thought process.
Thank you for sharing!!! This is such a great tutorial :)
Thank you very much sir we needed just this. You are pygame god.
This is actually really cool, I have never seen anyone use Json files for loading maps I have only used csv files that's such a neat trick, also another neat trick for even more performance, use orjson instead of normal json its much faster
If anyone runs into an issue with their character falling through the floor: Collision detection is checking where you are located in the a grid system ---> that's what the tiles_around() function does. It uses the co-ordinates from the top left of your player image to workout where you are. If your player image is larger that the grid system it will only register that you are in the next grid section to update the collisions after you have fallen through the floor. Try checking from the center of the image instead. Or else you may need to do more than one check i.e. top left, bottom right. Or else increase the checking distance to include more tiles. Interesting way to do the collision detection though
@HammouaI0I0I0
Ай бұрын
how to do this btw
@SagaContinu
Ай бұрын
@@HammouaI0I0I0 Adjust tilemap.physics_rect_around() function to check from the center of the player instead of the top left player_loc = self.game.player.rect().center However, if the distance from the center of the image to the sides (right,left,top,bottom) is still greater than a tile width this won't work.
@HammouaI0I0I0
Ай бұрын
@@SagaContinu cool, but where do i insert this line of code edit: cool my player doesn't fall trough the wall, but its sometilmes glitch out with upper collisions
If i wanna run this game in my mobile phone how can i? am i gonna have to re adjust the frame size and responsiveness of the game to run on diffren size?
i have a few questions, i hear people and most of the internet say that python is very slow compared to programming languages like c++, so is there any disadvantage that i would get from making 2d and 3d games with python? thanks!
my coding got so much cleaner from using this as a guideline, thanks!
Hi DaFluffyPotato, through your teaching video, I learned about the python construction and many useful skill about game development! Especially on python container, it did help me a a lot to understand the syntax and tips. Thank you for your kindly sharing~~~
what shortcut are you using to open the test window like at 44:38 i can't figure out how to do it... "edit" mistakes were made
Immensely grateful for this. Thank you.
anyone know why printing the tiles around the player wont work (doesn't show i crossed or got near the grass while falling but can still use collision properly) i think it might be because i'm programming from inside WSL and the vscode term isn't giving me output info properly but idk.
I think you are the only developer who works so hard on making games in python, knowing that it was easier to do it in unity. You really inspire me a lot.
@DaFluffyPotato
10 ай бұрын
It's only easier to get started learning with Unity. At my level, I can work faster than people using Unity.
@chigstardan7285
10 ай бұрын
@@DaFluffyPotato That's so cool.
@sushismitcher225
10 ай бұрын
I have been using pygame for over a year, and I've made over 20 pygame snippets in vs code to make anything in pygame from particles to a basic platformer. This lets me make prototypes faster than with a game engine. Each method to making a game has its advantage.
@Man-mx2sy
8 ай бұрын
nah check out clear code, that dudes fire
@chigstardan7285
8 ай бұрын
@@Man-mx2sy man clear code is the best, though he uses pygame for educational material while fluffy uses it for his personal projects. I hear clear code is gonna bring a new Godot 4 tutorial.
Thank you so much for sharing this tutorial! I have a question though, at 1:51:00 during tile optimization, I'm getting a TypeError on line 37, within the definition of the render function. 'float' object cannot be interpreted as an integer. Would installing numpy and using arange() be a solution? I compared my code with the repository, maybe I'm missing something...
@DaFluffyPotato
8 ай бұрын
Just wrap the parameters with int(). I think the // operator has varying behaviours depending on the system/version.
@trumansmith7630
8 ай бұрын
@@DaFluffyPotato That worked, thank you!
Great video! I've learned a lot of basics about side scrollers, even though I'm following with c++ and raylib instead of python.
wow, 6 hour tutorial. definitely gonna check this out. thank you.
how many lines of code did you use i am also creating something similar. also how did it take you like thinking of code, formation of ideas etc though the clips say 6hr
HOLY MOLY A NEW ONE!!!
Wow! It's a big work!! You are so cool!!!
THANK YOU SO MUCH, Thanks to you i achived my rpg engine, and it's so fast ! I'm really happy
*HOW IS THIS FREE*
Thx potato i was looking for a tutorial like this
thank you!! pygame is tricky but i'm determined to get it down!!
This is so incredibly valuable.. thank you
amazing content..thank you so much..exactly what i am struggling with...
i literally said wow at the jumping part, genius idea
at 1:33:00 if you divide self.scroll by 30 then the camera follow up will be slow . If you jump from high distance your player will fall first and camera wouldn't be able to follow up player , so divide it by 20 so no matter how high you jump the camera will follow up player in slow manner but without losing its track .
could you explain to me the neighbor offset list at 1:07:15 ? I didn't really understand it
Hi there, I have a question, I was testing the code from the part "02_images_input_collisions.zip", but I noticed that, even with one image and some rectangles (btw, i used the .convert() in the image) the FPS is kinda weird, like, the movement of the cloud is not smooth. if i take the cloud to the upper part and hold the down arrow, i can see some stutter, like if some frames was being skipped. I can also see that in your video. I dont know if i was clear enough. I tried to debug and i added a start_time = time.time() right after the while True and added a print(time.time() - start_time) right after the self.clock.tick(60), the expected result should be close to 0.01666, but sometimes it was printing 0.019, 0.020. Is this expected? I can see some of these stutters when you show your partial results, i dont know if this is intrinsec to pygame.
@DaFluffyPotato
8 ай бұрын
clock.tick() isn't perfect. It will always take slightly longer than it's supposed to and cause some jitter because of the display refresh rate. Typically it's better to use delta time and uncapped framerates, which I have another tutorial on.
Hello, can I do the same thing on Replit? Replit is a browser-based IDE that requires no installation.
Good work !
This seems like a good approach for people who already know how to program. Honestly some of the APIs seem similar to normal web dev. I guess at the end of the day, game dev is still just listening for events, updating state and rendering to the display
Tutorial done! Thank you for this...from France
hey why do you just import classes/functions separately but not the whole file?
I learned more from this tutorial than my past 2 years of python classes
thanks a lot dude you're the best
I don't comment much on videos, but thank you very much for your videos which help me a lot. Keep it up 🔥🔥! sorry for my english i am french
MAN THIS IS FRICKIN LIT 🔥 thx man 🗿
Nice one!
Man, thank you so much for this...
Hey i search in vscode but don't find your color theme for python, can you help me ? and thx for yours video, there are very inspiring
the ultimate pygame tutorial has arrived.
amazing work
What do you use to create the blocks, clouds, etc
The character and tile are 64 pixels, so I changed the tile_size to 64, and the character does not collide with the tile How do I fix it? 1:27:20
Thank you for this complete course! I will try to reproduce it in C language and raylib...
this is an amazing tutorial! i learned a ton from it! i just want to let you know is that this project has a bug in the way you implemented the death by falling. if you wall-slide for too long it kills you, and for some reason in this project if you wall-slide for too long, it kind of glitches out and shakes the screen. I'm not too sure why that is. also, when you reloaded the level, the player's dash value is not reset. but i loved this tutorial and will be looking forward to more videos! thanks!
Hello, I recently got into the pygame development and I couldn't decide which ide to use, I am constantly changing between pycharm and vscode. Can you please write which extensions do you use in vscode?
@DaFluffyPotato
7 ай бұрын
There's one for Python that it automatically asks you to install after opening a Python file. I forgot what it does, but I think that's the only important one I use.
Following this series with Zig and Raylib pretty similar experience except a lot of low level concerns.
This deserves a million views
When running the exact same code you have for 16:30, I get an attribute error for 'Game' object not having a 'screen' attribute. What's the reason why? How do you fix that?
@DaFluffyPotato
8 ай бұрын
Compare with the code in the description. You probably made a mistake.
@joshf1949
8 ай бұрын
@@DaFluffyPotato yeah I found out just needed to double underscore for the "def __init__ (self):". Thanks! Side Note: You're an actual beast. Can't believe you aren't more popular. Thanks for great videos and content like this!
Sir, pls tell what is assets, that you use in entities file in render function I am getting error that 'game has no attributes assets'
@DaFluffyPotato
9 ай бұрын
Compare with the reference code. You must've missed that part of the tutorial. It's just where all the assets are stored.
@hemadevi7106
9 ай бұрын
Yeah, I got the key.... Thanks a lot for this great tutorial
hi, if you come across this comment, can you please tell why I am facing this error: for loc in self.tilemap: RuntimeError: dictionary changed size during iteration happens while I am trying to generate enemies via the editor, and when I run the game, it crashes and shows this error
@Ragna6765
10 ай бұрын
Ran into the same error, looking at the code again now im more surprised that it works in the video than not. Not sure if it´s the best way to do this but I fixed it by handling the deletion of keys after the loop: ''' def extract2(self, id_pairs, keep=False): matches_offgrid=[] matches = [] for tile in self.offgrid_tiles.copy(): if (tile['type'], tile['variant']) in id_pairs: matches_offgrid.append(tile.copy()) if not keep: self.offgrid_tiles.remove(tile) for loc in self.tile_map: tile = self.tile_map[loc] if (tile['type'], tile['variant']) in id_pairs: matches.append(tile.copy()) matches[-1]['pos'] = matches[-1]['pos'].copy() matches[-1]['pos'][0] *= self.tile_size matches[-1]['pos'][1] *= self.tile_size if not keep: for m in matches: tile_pos=str(int(m['pos'][0]/self.tile_size) )+";"+str(int(m['pos'][1]/self.tile_size)) print(tile_pos) print(self.tile_map.keys()) if tile_pos in list(self.tile_map): del self.tile_map[tile_pos] matches=matches+matches_offgrid return matches '''
@q1chen
9 ай бұрын
i had the same issue. you can fix it simply with "for loc in list(self.tilemap):" @@Ragna6765
Still following along here bit by bit with some experimenting along the way, great tutorial so far! I just wanted to ask, since the screenshake changes the blit position of the display, won't we get black bars on the edges of the screen when it occurs?
@DaFluffyPotato
9 ай бұрын
Yes. If you don't like that you can use the camera offset technique I mention instead. It's negligible.
I’m using replit for my python game project and I’m very confused as to why the ‘movement’ is labelled as unknown. If anybody could help me that would be greatly appreciated.
you can actually do something about that camera bug when it gets closer to it's target, I believe you can target more of a radius of 5-10 pixel from the player origins, so once it gets closer to the player it will stop trying to center it perfectly and avoid the bug (but of course, the player will be slightly offset by 5-ish pixels) OR when it gets to that 3-5 close pixels, suddenly speed the camera from 30 to 100 so it gets spot on in maximum 2 frames (about 1:35:50)
@khushankgalgat
5 ай бұрын
hey, can you please tell what camera bug are you talking about? i didnt understood what "choppy" movement sir is talking about? Please explain that bug in some detail.. Thank You Have a nice day!
What is the game parameter in your PhysicsEntity class, because I only see 4 parameters when there should be 5. Can you please explain this to me, because I dont see how you transported the game class to your entities file
@DaFluffyPotato
10 ай бұрын
Self isn't included. Both of your questions are general Python OOP concepts, which isn't the focus of the tutorial.
@elyctricity0
10 ай бұрын
@@DaFluffyPotato oh so when you're saying self for the first parameter in 44:05, you're referring to the game class. I get it now, thank you!
when ever I add over 9 tiles to the grass tiles it bug out the editor because it reads the 1 and 0 from 10, 1 and 2 from 12, etc. is there a way to fix that?
@DaFluffyPotato
2 ай бұрын
Make 1 "01" or convert to integers.
@J1_Studios.
2 ай бұрын
@@DaFluffyPotato thank you
THANK YOU!!
The ultimate course
For the Autotile map, can you use a set so you wouldn’t have to worry about the order? i.e. condition = {(1, 0), (0, 1)}
@DaFluffyPotato
10 ай бұрын
Sets are mutable and can't be used as dictionary keys.
Melhor tutorial do youtube!!
Finished the tutorial and have been playing around and adding my own little features. I added collectable coins that enemys drop when killed and have just made it so that the crates are destructible and also drop coins. I've been trying to get collision working between the crates and players / other crates. Any advice on the best way to implement this? I made both the coins and crates inherit the physicsEntity class so they already have collision with tiles etc. Im not sure if this was the best way to go about it.
@DaFluffyPotato
7 ай бұрын
If you're trying to make them pushable, you can look at my old code from The Crushed Sky since I implemented it there. It involves recursion.
@MrDekTek
7 ай бұрын
I will check it out, thanks for the great tutorial!@@DaFluffyPotato