PyGame Platformer Game Beginner Tutorial in Python - PART 9 | Creating multiple game levels

preview_player
Показать описание
In this Python tutorial I code a Platformer Game using the PyGame module. I'm going to cover the addition of new levels and how to manage different levels within the game

Note, sprites and sounds are open source:

Check out my other PyGame tutorials:
Рекомендации по теме
Комментарии
Автор

You create the best tutorials on Youtube out of any other programmer that I have watched. Very clear and understandable explanations delivered with a complete end product free of bugs. Please keep them coming. I truly appreciate the time and work that you put into these videos. I do have an idea for your next series if you are planning to continue with PyGame. This idea is creating an online multiplayer PyGame using python sockets, and networking. I know keeping the games pretty basic is beneficial with what you are trying to do so maybe a two player fighting knock off of Street Fighter (just one full fight: Round 1, 2, & 3) or maybe a multiplayer platformer that is a capture the flag type game (with the flag at the top and players start at the bottom and have the ability to shoot and re-spawn). Just some ideas. Whatever you decide to create I will watch.

AJ-jjgs
Автор

If you are having trouble with pickle you can try this: Cut and paste the world_data list of lists and save it to a text file inside the same folder as your program. Import json, then use the following code to call your level data:

if
level_file = open(f'level{level}_data', 'r')
world_data = json.load(level_file)
print(world_data )
world = World(world_data )


Hope this helps!

scottmather
Автор

Hi Russ! I'm enjoying your videos and following along at home. I noticed something worth mentioning in this one that may help others learning at home!

In Python, functions aren't able to reassign global variables unless you first declare them explicitly using the global keyword before the reassignment happens in said function. Specifically, adding a line like "global world_data" to the top of reset_level. In the case where you do NOT add the global keyword as just described you instead, at the time of reassignment, create a new locally scoped variable for use in the remainder of the function body as opposed to performing the reassignment on the globally scoped instance. Oddly, the level_reset function returns the new locally scoped copy of world back out showing some understanding of this concept but the clearing of world_data before calling reset_level will leave the global instance of world_data in the cleared state after the function executes. I added a print(world_data) after the level reset calls to verify and sure enough Python shows an empty list [] in the console meaning the locally scoped version that the reset_level function created has gone out of scope into the aether.

Fortunately, it does not look like world_data is actually used anywhere else (at least this far in the series!) so it's probably an entirely moot point. Unfortunately there's not a way to edit YouTube videos retroactively but perhaps if you had just removed world_data out of the global scope entirely at this point or addressed this "feature" of python it may have provided you with another great lesson for us following along at home.

I really appreciate all the work you have done here and I've been enjoying going through the series with my mentor who pointed this out to me. Wish you all the best.

kaylamarie
Автор

what is inside of the level1_data?
Is it like the world data list?

because i dont wanna use level editor

Super_Esel
Автор

if you have your (level{num}_data) list in a folder/dropdown menu like (Platformer-master) you need to add it before the level name. like this: pickle_in = open('Platformer-master/level{num}_data', 'rb') this was my fix for my problem. :)

seanwick
Автор

Hi, thanks first for the video, I have improved a lot, but I have a question, I want to create more worlds, but not with the level editor but by creating new files (I want to create files that you uploaded to github), but it would be a great help if you could share the contents of those files with me because it would be easier to do as you read these files have no "extension" and contain only a plain list, i tried but failed to do it and obviously the files that contain the world i couldn't open so i don't know what's in it and so i can't create new ones either.
I hope you can help me. (I mean these files-level0_data, level1_data, level2_data, etc.)
Thank you very much!
Have a nice day :)

tamashadhazy
Автор

If you have issue: "No such file or directory". You must enter full location of file. So for example in my case is

jakubrybar
Автор

Hello, the game is top but I have a question how to open a file with a level

Mariortizz
Автор

world_data = pickle.load(pickle_in)
_pickle.UnpicklingError: invalid load key, ‘w’.

Hi Russ I keep receiving this error I think it is something to do with my list file (I am making my own levels rather than using the level editor) any help would be appreciated

MD-tcmt
Автор

What do I do if the f prefix isn't supported? I can't seem to figure out another way around it.

camerynluis
Автор

I have 2 issues,

1. Inside the github above you posted a level "0" why is level = 1?

2. Almost every single level is impossible because you can't jump high enough!

jedicubing
Автор

hey the level editor is too large I am not able to see the save and load buttons, I tried resizing the window but then the buttons wouldn't work any suggestions can you give?

parthgupta
Автор

Hey, so i started differently, i did a 1100x600 screen
and my tiles were 44x24
so the level data isnt appropriate for my levels, what do i do?

soupnoodles
Автор

I got up to 20:17 but mine still froze when I touched the exit, I spent 40 minutes looking on what I did wrong but I couldnt find anything.

epicdragon
Автор

Can you do a tutorial for making a level editor ?. love your content btw

samixpunch
Автор

how can i fix ran out of input pls help for the world data

avengersaep
Автор

Hey Russ! Great video!

I want to make the levels with the world lists like you had at the start of the video instead of the level editor like you show here. How can I do this instead and have the next level happen after the player beats it?

LU-qrkh
Автор

Pls tell that the leve_data files are in .txt or.py

parthgupta
Автор

I've been previously using pycharm to run the pygame but I wanted to try it out on Sublime but I don't know how install pygame, can you help me?

technodris
Автор

Hi, another amazing video I have a slight issue with the game though. As reach the exit and move onto the next level, the next level is loaded in but the tiles have no collision. Also, the previous level tiles are removed but the collisions between them are still in the game making my player float in the air. I have compared my code to the source code and there does not seem to be any issue

prodOmelly
visit shbcf.ru