PyGame Scrolling Shooter Game Beginner Tutorial in Python - PART 9 | Loading Levels

preview_player
Показать описание
In this Python tutorial I code a Scrolling Shooter Game using the PyGame module. I'm going to cover how to load levels into the game using the csv module

Credits for assets used:

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

Excellent. You have taken up the better portion of my public holiday, and some extra.

Great series...it has answered a lot of my questions. I think Ill be referring back to these for a long time

HoRRoRlets
Автор

Excellent set of videos. Really well explained. I'm just starting out using Pygame so I found all the techniques you used here really useful. I'll be coming back to this time and again I think to make my own games. Thanks for taking the time to put this together.

antonyculy
Автор

First of all a really big thank you for these videos and I'm really looking forward to see the next episodes and the final result take shape! I've really been enjoying the parts released so far.

I couldn't help noticing a few minor things and got a few ideas that I wanted to share with you.

1. When you added the gravity to the Soldier class, you intended to cap it at 10, but there's a small bug in that code; the check is run, but the value is not actually capped.

2. I think you could make the actions a lot nicer to work with by using strings (or even Enums) rather than integers and have to try to remember that 0 is Idle, 1 running etc.

3. I think you in a few places in both this and the level editor could use Python's min and max functions to cap values at certain min/max values, and modulo (%) for wrapping around.

4. When creating the players and the enemies, it could be a good idea to use keyword arguments for speed, ammo and grenades to make it easier to remember what number corresponds to what attribute. For the grenades you could also specify a default value of 0, so you could just leave it out for the enemies.

5. The HealthBar takes in the current health in the constructor/__init__ and updates it as well, but it's actually never used outside the draw function, so you could actually use juste the passed in health argument without ever assigning it to self.health. Another alternative could be to give the constructor a reference to the player object and thus you wouldn't even need to pass in the health in the draw method.

6. I wanted to ask you that have you considered to use JSON as a format for the level data instead of CSV or pickling the data? That's a standard format that's somewhat readable in text editors (of course not easily importable into spreadsheets) and that would be able to preserve lists and numbers.

7. I think you could make a lot of the image handling less repetitive by adding some helper functions. I'm also a bit concerned about the os.listdir() to count files in a folder, as for example macOS tends to add some hidden .DS_Store files that could possibly end up causing issues.


9. Using subclasses could be a rather nice way to add the AI stuff to just the enemies and would give out of the box separation of variables that are only related to enemies.

10. I think you could well promote the videos also by adding a link to the playlist in the README file in the GitHub repo. Wouldn't likely either harm to there as well give credit to those who've created the graphics; you're of course doing that already in the videos. I couldn't avoid noticing that the code is indented with tabs, whereas the standard for Python is to use spaces. I think some IDE (like PyCharm, especially the professional version, don't know VS code and it's plugins that well, but they should also offer some of the features) could be rather nice addition, as they can easily detect many opportunities to improve code or catch code that's not doing anything.


In any case, I've enjoyed the videos and looking forward to the next episodes! A big thanks for making them!

JoakimNordling
Автор

thank you russ....best tutorial on pygame i have seen so far :) it is really helpful and very well

weitnow
Автор

Great series!! It really helped me...looking forward for your new series... blessings from India

dezalhadiya
Автор

29:50 - very cool, never known, it is possible to receive multiple values from functions return!

АнтонНазарук-щс
Автор

great work on this my friend I cant wait to see whats next :) <3

johnandlisalinderman
Автор

I have a problem with loading the images. I just ran the code after starting the video. I haven't changed anything from last video but it says it can't find the enemy images anymore? can you help pls - when i remove the enemys from the code by commenting out there creation it all works?

logankempson
Автор

why i have this error ModuleNotFoundError: No module named 'button'

factsnhien
Автор

it says that button.BUTTON is wrong so the button module has no attribute BUTTON how do I fix this

shido
Автор

Won't let me write return player, health_bar in the World class, keeps saying "index out of range". Any ideas on the fix? Also sometimes, it doesn't input the bottom tiles of the map, and misses some of the grass.

SebastianRyterband
Автор

Is the level editor strictly required for the game? Or can i type all the data into a text file? Also if the level editor is required can i replace the sprites?

theforgottencatnora
Автор

In the interest of saving memory, I've been trying to figure out a way to import levels and cutscenes as files and then remove them from the program once they have served their purpose without permanently deleting them. Do you know if this is possible?

soundtracksbymax
Автор

is there a link to download the level editor somewhere?

lwwk
Автор

yo dude thanks for the tutorial but could you give a link for the level editor in the video?

dzareg
Автор

Hello. First things first. Thanks for the videos. I need help. When I try to run the code, it gives me the error
world_data[x][y] = int(tile)
IndexError: list index out of range
Please help me!!!

matejzachveja
Автор

39:07 when you run the code your objects appear floating. But for me it is not. Is it any problem?

theairbusll
Автор

u are the best, thanks for sharing, subscribed ! with content like these sir you will have success

thedamon
Автор

Thank you for what are you doing. Appreciate it a lot.

kapitooshka
Автор

Hi Russ. Amazing videos, great tutorials and manging to merge my own code into this now with greater understanding of classes, functions and loops. Quick question, I have managed to get my own game and levels working with a congrats screen when level > MAX_LEVELS and a button click to return to main menu. (if press return, main menu = True) but when press return, it flickers and stays on main menu and will not start the game. My game start relies on return key being pressed, which turns main_menu to False, which should kick off the game at start of loop?

mattowen