Creating a Zelda style game in Python [with some Dark Souls elements]
A Zelda-style RPG in Python that includes a lot of elements you need for a sophisticated game like graphics and animations, fake depth; upgrade mechanics, a level map and quite a bit more.
Thanks for AI camp for sponsoring this video. You can find the link to their summer camp here: www.ai-camp.org/
If you want to support me: / clearcode
(You also get lots of perks)
Social stuff:
Twitter - / clear_coder
Discord - / discord
Timestamps:
0:00:00 - intro
0:02:30 - Project setup
0:06:52 - Level setup
0:28:38 - Creating the player
0:49:47 - Creating the camera
1:11:30 - Graphics
1:56:00 - Player animations
2:30:26 - Weapons
3:04:20 - UI
3:44:03 - Magic setup
4:00:19 - Enemy creation
4:57:00 - Player-enemy interaction
5:32:50 - Particles
5:56:25 - Spells
6:26:35 - Upgrade system and menu
7:24:26 - final fixes & sound
Related tutorials:
Introduction to pygame - • The ultimate introduct...
Using Tiled with pygame - • Creating a Mario style...
Debugging in pygame - • Debugging in Pygame
Project files:
github.com/clear-code-project...
Pastebin files:
pastebin.com/u/ClearCode/1/MB...
Artwork by Pixel-Boy and AAA
pixel-boy.itch.io/ninja-adven...
Пікірлер: 1 400
Just made my first “hello world” in my python class. Guess it’s time to make Zelda now
@crops1646
2 жыл бұрын
I think it should be better if you learned the language first. I talk for experience, doing something without understanding/remembering how to do it by yourself is kind of useless and is going to make you lose lots of hours
@aperture0
2 жыл бұрын
@@crops1646 he's being sarcastic bro
@crops1646
2 жыл бұрын
@@aperture0 you're probably right but maybe someone else could see this comment and believe it's a great idea
@aperture0
2 жыл бұрын
@@crops1646 ah I see your point
@seanc.9343
2 жыл бұрын
@@crops1646 hey i want to be a programmer what language should i study first?
It's honestly mind-boggling that we get this kind of content for free and that well put up together. I can't thank you enough for your work and passion to spread your knowledge! Keep it up, you're great
@spaidory874
2 жыл бұрын
I agree
@yanpaquis8514
2 жыл бұрын
So true!
@FlyingVyper
2 жыл бұрын
yup.
@iamgerer
2 жыл бұрын
True that!
@iamgerer
2 жыл бұрын
Thnx @Clear Code
AI Camp here - we are so proud that we sponsored this great video. Cannot wait for the summer to happen to see what people will create!
@unbreakable5510
2 жыл бұрын
Thank you
@harmitchhabra989
2 жыл бұрын
There are 256 subs right now, why must I be the one who has to ruin such a perfect binary number??
@filipbumbu851
2 жыл бұрын
@@harmitchhabra989 leo?
@WolfsInk
2 жыл бұрын
I'm actually in awe to see such a video so well put together. Thank you for sponsoring this!
@ai-camp
2 жыл бұрын
@@WolfsInk You are mostly welcome!
I can't believe what I am seeing. Just a few weeks ago I nearly gave up in frustration for lack of quality pygame tutorials, specifically for a Zelda style RPG. Then I found your channel and I started on your course at Udemy. I said to myself, I only wish he'd do Zelda. AND OMG here we are. Thank you very much, You have a real knack for knowing your audience... And your devotion to teaching has changed my life.
@konstantinrebrov675
Жыл бұрын
It seems like you manifested this lesson.
@Drake00000010
Жыл бұрын
How did it go? Did you make one
@K5RTO
9 ай бұрын
@@Drake00000010 A bit of a delay. I had some life stuff happen so I am just now finishing it up. A fantastic tutorial on par with all of his really great content.
@IkaroRafaelNunesdoVale
6 ай бұрын
@@K5RTO Which is his course on Udemy that you are referring to? Even practically in the year 2024, after some changes, is it worth it? I'm still new to the area, I have some questions
I thought this was a 7 min video at first :D I was not expecting a programming video when I clicked it, but thank you very much for creating this. It must have taken a lot of work and I appreciate it very much.
@The_True_Mx_Pink
2 жыл бұрын
I didn't even look at the time, I didn't even see it's 7 fucking hours long.
@MaxwellJWhite
2 жыл бұрын
@@The_True_Mx_Pink im assuming you arent a programmer lol thats pretty normal for a tutorial
@The_True_Mx_Pink
2 жыл бұрын
@@MaxwellJWhite You are correct
@chady51
2 жыл бұрын
Same I thought it's just vidoe of somone making pygame zelda than a entire tutorial
@loganwow
2 жыл бұрын
What version of python is this
This channel is by far the greatest coding channel judging by the deliverance of information, keep up the good stuff! Looking forward for more of your great pygame tutorials!
@loganwow
2 жыл бұрын
What version of python is this
This was a terrific introduction to pygame, the only thing that we forgot to add was a player death mechanic but I'm taking on the challenge on my own and feel well prepared to do so. Thank you so much!
@EvenTheDogAgrees
11 ай бұрын
Well, to be fair, he did point it out. Reason he didn't implement it is because it's easier to test your game mechanics if you don't also have to worry about not dying.
@minhquan5603
6 ай бұрын
can you ask with, passwork of file
@Corn0nTheCobb
5 ай бұрын
I can ask with, passwork of file if I really wanted to. But, can YOU? That's the real question.
This channel is actually underrated, he is also the one who made tutorial to make minecraft in Python. Great tutorials, keep it up
After a couple weeks, I FINALLY finished this tutorial. I had gone through a pygame textbook that was pretty outdated and this introduced me to so many concepts that the book didn't have. Thanks so much for this amazing tutorial!
@dragonriderjohann7683
Жыл бұрын
can i make this with a 4gb ram laptop?
@lightsilver127
Жыл бұрын
@@dragonriderjohann7683 sure you can
@auroragaming4991
5 ай бұрын
PLS NAME THE BOOK
@johnlloydpua6021
28 күн бұрын
@BitDifferent
@johnlloydpua6021
28 күн бұрын
Kwispy cream do you still have the code ? I tried recreating it but it always shows the error
i had alot of "importing" errors until i realized i need to (ctrl+s) save each of the modules before running the main module for the updated code to work. great video. i learned quite a bit about pygame. thank you :)
I found your channel by chance with this video and in two days I managed to follow you step by step and actually create the game. You can't even imagine how I happy I am right now! Thank you very much man, this project must have been really heavy so really thank you so much for doing it and sharing it here!
Who has the audacity to Dislike videos like these? It's truly insane that you can offer a free informative, educational video and somehow that's a bad thing.
I am going through the side scrolling videos now, and I can’t wait to get to this one. Looks amazing!!!
This looks incredible, can't wait to dig into it. Agree with the other comments I'm seeing, this is the *exact* tutorial for PyGame that I've been desiring for a few years now.
If you enjoy this tutorial check out my pygame course: www.udemy.com/course/learn-python-by-making-games/?referralCode=A80FECE8C76096E01111
@ZacharyRL101
Жыл бұрын
Already own it :)
Thank you so much for the pygame walkthrough! I blew people away in my intro to python class and I only turned in milestone 1 for my project. Which was having collisions working without any of the camera. I am so grateful for your explanations. Keep it up!!
I really appreciate you leaving your mistakes in. It makes a beginner coder like me feel better about myself when I make errors.
Oh Wow, the amount of work you put into your videos is overwhelming. Your channel is extremely underrated. Keep it going!
This is insanity, i've never seen a tutorial like this.... incredibly impressive. I wish I had this a few years ago, it's not so helpful to me now (especially at this length) but if anyone is a beginner this is great!
As a python enthusiast and huge fan of LoZ/DS games, I'm greatly looking forward to watching this. My first major project a few years ago was creating an old-school text adventure that runs in the CLI, and I created a simple animated dungeon map that can be called from within (using pygame). I've been planning to whip up some sort of 2d adventure game like this next - can't wait to dig in.
For a moment i thought this is just a project made by a team of professionals, the second moment i realized this is a WHOLE tutorial Holy crap this is next level dude!! Keep up the good work!!
@foxtro484
2 жыл бұрын
@Florian D. True, python and pygame are great to make games as a side project, but professionaly i would never use pygame. Don't get me wrong I love pygame.
@purpleplantain374
2 жыл бұрын
@@foxtro484 what would you recommend then? particularly for C++
@chady51
2 жыл бұрын
@@purpleplantain374 yeah java or c++ is mostly used for making games
@loganwow
2 жыл бұрын
What version of python is this
@chady51
2 жыл бұрын
@@loganwow Maybe It Python 3 python 2 is abit too old
I think new coders would also benefit from seeing how you divided each pack into your local files because your file locations are integral to your code, but we download them differently from PixelBoy. So as we code, we sort through a lot of things that you have preorganized. Seeing how you have them organized in each file would be helpful in the setup intro part of your vid.
@isaacclark5784
Жыл бұрын
I am a new coder and sorted through those exact problems
@switch_axe
Жыл бұрын
I experienced this as well! I love the tutorial,
@WhatsNextFam
9 ай бұрын
yeah im stuck i cant even find the rock.png in the pixel boys file
@WhatsNextFam
8 ай бұрын
Trust me guys with just a little messing around their is no problem in coding you guys can’t figure out!! I’ve followed so many tutorials since then made 20+ games and became a pygame master and the main thing I’ve taken away from all this was how to problem solve!! You guys got this!!
@jasg223
6 ай бұрын
@@WhatsNextFamso how’d you get your own tile for the rock.png
When I started learning Python on my own, I knew the basics but had no idea how to apply what I learned. This project is helping me because many abstract concepts are now solidifying inside my mind. Thank you so, so much for the great content you put out and for your patience, you are an EXCELLENT teacher, really! The effort you put into being thorough in your explanations is greatly appreciated!
Hey there! Just finished this tutorial among other you have uploaded. Just off to say you make really good resources for people to learn new things. Keep it up and THANK YOU.
More projects like these will be amazing!
I’m an hour in and I can say this: yes, a lot of this is going over my head right now because I don’t have a good enough grasp of Python classes, but WOW. Your presentation is impeccable… perfect pace, great examples, and the logical flow is really helpful. Incredible resource.
@loganwow
2 жыл бұрын
What version of python is this
@sm_stormzy1075
Жыл бұрын
@@loganwow Python 3, I would assume 3.9+
@sophomore3752
Жыл бұрын
To anyone feeling the same struggle: try watching his other videos in conjunction with this one. Such as the Super Mario video from a year ago and "Creating a platformer in Pygame". If your problem isn't simply understanding Pygame, but programming in general, I suggest practicing with simpler concepts first such as importing libraries, making functions and executables or even simple lists.
I've been watching this a little bit every day and I finally reached the end of the video. This was really cool, and I loved the end result!
This is amazing, and I can't believe I haven't subbed yet. I'm going to be modifying this code for an online-rpg style project I'm working on. Thanks so much for the great tutorial!
what a legend, creating zelda in python. can't even imagine doing that with or without motivation
I saw you mentioned making this video a while back, I didn't think it would be like this! You've really outdone yourself!
@Stopinvadingmyhardware
2 жыл бұрын
I don’t give a shit.
This is absolutely amazing. Instantly subscribed. I’ve always wanted to create a game like this style using Python, this is great! Thanks for posting, awesome job
These are the best tutorials one can find, thanks for the great content!
You are on of the most underrated KZreadrs on the platform. Thank you for your content.
Just finished the entire tutorial! Wonderful! Thank you so much for putting this together and teaching pygame.
@dankeroner
Жыл бұрын
I’m almost done, I’m thinking of adding new levels. Hell, I might post them on my GitHub
This was such an amazing project! I really wanted to start making adventurous games such as Pokémon and I have to say this tutorial covers already so much amazing what you did! You are amazing!
Genius and philanthropist, you just make my day and the world better, congrats and cheers from France
Thank you for the amazing pygame tutorials, you are really underrated.
Wow! This is fantastic! This channel and the Coding with Russ channel are right up there with this type of content and tutorials. Thank you so much for this, it is very much appreciated. The time and effort you have put into this, its astounding! :)
Fantastic work. Very appreciative of this free content that you provide, and it's done so professionally. Thank you!
Here at the second it came and already know its gonna be awesome
Dude, you are just awesome! Very impressive what you build here. Isn´t it awesome that programmers are able to make the inner child live forever this way? :-)
Sir, I just wanna tell you that you. have changed my life with software, and I admire your teaching style more that anyone's. Thank you for putting out amazing content and never failing to help us.
This is so great! I can't wait until I can get on this level of programming and can follow along with this and genuinely understand it!
Another amazing tutorial, thank you so much for all the work you put out here!
You are so my favourite coder on KZread. I cant believe that this is so much better and CHEAPER (free) compared to school coding classes. Keep up the good work!! Suggestion: pls do another tutorial is python ursina??
I was wondering how it was possible for such quality content to only have 500 views, but then I realised that I had caught this video just shortly after it had released.
Really impressive training session!! Great work, my friend!
I am glad to see there are always talents people like you who willing to produce such quality and FREE courses for all, this is meaningful, splendid, and much appreciated! Please produce more quality courses, for the whole industry and humanity.
I made it through the whole thing. Thanks a million!
I love the game and the art!
Incredible the quality of your work and sharing this with the whole world for free!!! We can't thank you enough!
Omg this was some next level effort. Dont know if I'll ever come to get to this tutorial, but thanks for doing it!
Excellent tutorial! Would you be interested in making up a tiny follow-up video to show how to code: 1) a game over "state" upon player death 2) a level "reset/retry" option after the player dies 3) how to load a new level upon clearing an "objective"
@mattowen1812
2 жыл бұрын
Integrate his overworld code from the mario platformer tutorial. Beware though, it resets the exp and menu settings every level... not been able to get the ui and upgrades into the game class yet so they stay with the player each level...
@thatguy-cf5gs
Жыл бұрын
@@mattowen1812 i know I’m late to the party here, but i may have figured out a solution to this. Let me know if you’re still stuck
@mattowen1812
Жыл бұрын
@@thatguy-cf5gs Hi. What was your solution eventually? I think I put all player variables I want to persist in a dictionary in the settings file. Alternatively, a method that passes current_exp to a new_exp variable then create level function with the new_exp passed in. I did this with my metroidvania here with the weapons the player has when swapping levels (or rooms in this case) m.kzread.info/dash/bejne/fZyK2bh_lNLSetY.html
this tutorial is fantastic!
What you do is incredible!
I’ve enjoyed your tutorials the most , been learning a lot and made 2 games so far, thanks a lot !!!!!!
Can't wait to give this a shot and learn. I've been interested in a Zelda clone but Most are super old /outdated.
The value of what you're giving the world simply can't be overstated, sir. You're an example of the kind of person that spends their time uplifting others and it's a pleasure to learn from you
Thank you so much for your generosity in sharing this with us!
Finally, I've made the first production with python thanks to you Clear Code! It took me like a month to finish this and I kinda understood how to make a game with python. It helped me a lot to improve for myself. Thank you Again!!
As a fan of both Zelda and Dark Souls, I was ecstatic to find this tutorial. Clear Code, your ability to teach complex concepts in an easy-to-understand manner is truly impressive. Your dedication to providing high-quality, free educational content for aspiring developers is greatly appreciated. I can't wait to start working on my own Python-based RPG using the skills I've learned from your tutorial. Thank you for your hard work and for sharing your knowledge with the world!
Just as a heads up to help those of you starting, theres way more than 7.5 hours of tutorial here. With bug fixing, exercises and working on theory discussed its probably closer to 18. To help you time box, you should double the minutes in each section to estimate how long each section will take.
Took quite a bit longer than 7.5 hours but successfully completed over a weekend. Thank you so much for this! Looking forward to following along with your other guides
What a great tutorial, thank you so much for putting this together and offering it for free. A real gift to coders getting started with python game creation.
You deserve much more subs 😃😃
Hey ! So im a mac user and i got stuck during the graphic part of the video (around 1:50:00), the probleme was that i was getting the worng sprites for the objects (getting statues instead of trees, etc.). After a bit of testing i undestood that the Mac os walk function doesnt "walk" throught the directory in the correct order so the list we're creating(image_surf) is unsorted. If u're struggling with the same issue, define a new list to get every images from the walk function, then sort it and iterate angain throught the sorted list. def import_folder(path): surface_list = [] sorted_list = [] for _, __, img_files in walk(path): for image in img_files: sorted_list.append(image) sorted_list.sort() for img in sorted_list: full_path = path + "/" + img image_surf = pygame.image.load(full_path).convert_alpha() surface_list.append(image_surf) It works now, i can keep enjoying your tutorial :)
@user-qk5mn8ew3l
Жыл бұрын
Hey, I run into the same problem as you did, but I wouldn't ever solve it on my own. Thanks a lot for your help!
@jianghanchang7654
Жыл бұрын
Thank you so much! I was stuck on this too on Mac
@genexperimen3163
Жыл бұрын
why can't i run? "pygame.error: Unsupported image format"
@briangardner2001
Жыл бұрын
OMG thank you! I was trying to figure this out by looking at the object csv files and seeing why they didn't match the ones in the video. I have to imagine it would've taken me a long time to consider that the walk() function was a possible culprit. I think there's a shorter way to solve the issue. Just add the line img_files.sort() inside the first for loop, like so: for _, __, img_files in walk(path): img_files.sort() for image in img_files:
@toutenunmot
Жыл бұрын
I had the same issue, also on mac. The basic sort() was not sufficient for me as I standardized the naming of the files to be n instead of 0n. 0.png, 1.png, 2.png instead of 0.png, 01.png, 02.png etc. I did this because if you had hundreds of files you would have odd names such as 001.png, 002.png and even worse if you were to have thousands or more files. Any how I put this in a try, except block: files = sorted(files, key=lambda file_name: int(file_name.split('.')[0]))
Just came out of a Uni CS class where our final project used PYGAME. I can actually understand a lot of what you're doing and it's impeccable. Absolutely love this! Warms my LOZ nerd heart!!
Very cool project. It was very interesting to see your working-process!
I'm at 2:56:43 right now, so I don't know if it'll be fixed later in the video, but because of the Y-sorting draw of the sprites, the weapon is overlaping the underneath sprite while the player is overlaped by the sprite, I think that to fix this, we should create another group of visible sprites, that will be drawn above all
It's Awesome
Really appreciate this tutorial! Even though it is pygame related, it contains such great insights into how a project should be structured with as little hardcoding as possible. This one should be watched, no matter if you are into creating games or not.
I´ve already watched that on Patreon it was amazing!
Its funny to me, as a child it was always magical and beyond my scope As a adult in college, it was still magical and beyond my scope Now, nearly 28, it's STILL magical and out of my scope 😂 but there's a lot of cool resources like this video to teach me it's not /as/ crazy as I always believed ❤
How is this free? Please keep up this amazing work
I'll be honest many times I skipped the announce for the sponsor but I video at this quality can't be rewarded enough, and it's free ! massive thanks to you I've been here for a long time and I am always amazed by the games and logic that you come up with.
An absolutely amazing tutorial. It's very thought provoking in a sense. Kudos to everyone who made it to the end :)
For the player animations this line of code "self.image = animation[int(self.frame_index)]" always causes an error called "IndexError: list index out of range". Does anyone know a reason or a mistake I might have made? Edit: I have now fixed it, it was cause when i was giving a file path for the animations I didn't put a slash at the end
@StefanoCherchi
2 жыл бұрын
Thank you so much, I had the exact same issue
@alonsogonzalez1279
5 ай бұрын
I have this specific mistake too; what file path for the animations are you referring to? the player’s?
This is such an amazing tutorial! Will you be able to do a dialog box and npc interaction video?
This is a really cool video, thank you very much for making it! It helped me very much understanding pygame, so a big thank you!
Finished your tutorial, thank you so much for the detail, I know this had to take forever to make, but it was worth it, IMO
Это очень крутая работа!!!! Спасибо тебе большое за проделанную сложную работу. Уже потерял надежду и думал, что это невозможно на Python.
@executed_code
2 жыл бұрын
Согласен. Многие почему-то думают, что Python годится только для каких-нибудь простеньких приложений.
@shadowu745
2 жыл бұрын
yes i love python so much
Thanks man, what a great tutorial! I had one big issue at the beginning: I got some error messages after setting the sprites in the row and col index and it took me some time to find out that, In my case, the graphic import at 16:31 did not work at all. I had to move the grapics folder to the code folder and get rid of the "../" part in path in both, tile.py and player.py.
@erikstrawn3885
2 жыл бұрын
I did the same thing, and it took me a little bit to figure it out. The "../" drops back one directory before going to the graphics directory. If you put your code in its own "code" folder instead of in the main folder, it loads the graphics files just fine. Next you need to sort out this error: File "../Zelda Tutorial/code/main.py", line 23, in run self.screen.fill('black') TypeError: invalid color argument I put standardized color tuples into settings.py and tossed in a line importing those settings into debug.py.
@randomblaster2887
2 жыл бұрын
or u can just remove one of the dots
@seresmora
2 жыл бұрын
i solved it by adding another "/.." to the path Because the reference folder is one level deeper, so it looks like this "../../graphics/test/rock.png", Im returning two folders instead of one
I have finally reached the end! Thank you very much for all of that hard work :)
What should I do first, the mario game or zelda(in terms of which one is more difficult)?
@ClearCode
2 жыл бұрын
Mario first, I'd say but they are equal in difficulty
First of all, thank you for your tutorial! You have done a great deal of work:) But when I see some of the decisions you made, my eye twitching a little... The game is absolutely unscalable (may be you will rewrite it later in the video I have seen only an hour of your tutorial yet) . You call update method for all visible objects when in fact only player has update method. You check collisions with all obstacles when you can check only with objects in small area around player. And it absolutely blew my mind when you decided to sort all objects before drawing at each frame!!! When the only thing which changes the relative position is player! I think that you at least have to tell people that there is a better way to write your code:) To be more constructive. The usual way to deal with collisions is geohash. You have to store your collidable objects in a hashmap with rounded coordinates as keys. Then you have constant complexity of computing collisions. And you can store static objects in sorted group apart from dynamic then at each step you will have to sort only dynamic object which are present on the screen. Keeping in mind that you usually have way more static objects than dynamic, it will be a significant reduce in computational complexity.
@jasonsworld333
2 жыл бұрын
This concerns me as Im following this for a project due Tuesday, hoping to pick up bits to add to my game, but Im not sure it will be worth it for scalability issues. I've noticed a problem with a lot of things in Pygame tutorials being limited to just what they are doing with not much explanation on the ability for scalability. If you know of anything please let me know
Been watching this video for weeks (I am taking my sweet time) and will be watching it for longer, and I have to say I have never been more excited for a coding tutorial
this is amazing! thanks for helping me learn to code, I love your content!
my player is only updating when i release the key, so only moving at 5px per key released and not while holding the key down. any fix?
@Yannick_td
2 жыл бұрын
I had the same problem and it was because my update functions in the main script where in for event in pygame.event.get(): instead of just in the while True:
Does someone know how Clear Code gets these perfect sized graphics? I can only get those small ones that looks awful when I maximize the width and height.
@ClearCode
2 жыл бұрын
1. Make sure you find good looking assets. Opengamearts and itch.io both have some really good (and free ones) but you do need to look for a bit 2. You can use a pixel scaler (lospec.com/pixel-art-scaler/) that can increase the size of an art asset without losing quality (for pixel art). 3. What also helped is that I set my screen scaling to 250% so that my 4K screen works more like 720p screen, which does make things look better. Obviously that doesn't work for actual games so make sure to focus on step 1 and 2 Hope that helps :)
@subarunatsuki1902
2 жыл бұрын
@@ClearCode Yes it does, thanks! :D
Much love 2 you. I spent an entire day going through everything and trying to understand it.
Thank you so much for your kindness ! Sharing this tutorial made me love this ! I hope you publish as time goes on... Tysm!
Great tutorial. Running on Mac I started getting some weirdness an hour and a half in due to the weird way that os.walk returns an unsorted list - on linux and windows the list is sorted. I rewrote the import_folder function in support . py to ensure that the image list return is sorted, then I sort on that to make a surface_list. def import_folder(path): image_list = [] surface_list = [] for _,__,img_files in walk(path): for image in img_files: full_path = path + '/' + image image_list.append(full_path) for image in sorted(image_list): image_surf = pygame.image.load(image).convert_alpha() surface_list.append(image_surf) return surface_list
@rodolfog.7571
2 жыл бұрын
omfg, u saved my life bro, thx
@Shrapp13
2 жыл бұрын
wasted an hour trying to rename each png to the number that would correspond to the right position in the unsorted list before I read this, much appreciation dude
3:03:20 [Weapon mechanic] I did the mechanics backwards, I hope it can be useful to someone else. This is the code: if keys[pygame.K_w] and self.can_switch_weapon: self.can_switch_weapon = False self.weapon_switch_time = pygame.time.get_ticks() self.key = "W" if ( self.weapon_index 0 ): self.weapon_index -= 1 else: self.weapon_index = len(list(weapon_data.keys())) - 1 self.weapon = list(weapon_data.keys())[self.weapon_index] (Sorry for my english, hehe)
Amazing, 7 hours of footage! Thanks a lot!
Mind boggling man i hope this stays for ever ❤️❤️
Hello people, I have an issue, in this part of the video, 5:45:36, in this part of the code: class ParticleEffect(pygame.sprite.Sprite): def __init__(self, position, animation_frames, groups): super().__init__(groups) # basic setup for any kind of animation self.frame_index = 0 self.animation_speed = 0.15 self.frames = animation_frames HERE--: self.image = self.frames[self.frame_index] self.rect = self.image.get_rect(center = position) It throws an error after I run the main program and kill some enemies. It says the list index is out of range.... How to solve it? I know it should be something like if self.frame_index > len(self.frames)-1: self.frame_index = 0. But where to put it? We have created the death particles for the enemies and then after that I got that error (maybe I had defeated six or so monsters)
@desmond-hawkins
2 жыл бұрын
The first thing to check is why you don't have anything in animation_frames. You're accessing frame 0, meaning the first one in the "frames" list. If you're getting an index list out of range, it means the list *must* be empty, otherwise it would pick whatever is at index zero. What you're proposing with the `if` condition works only for cases where your index is past the end of the list *and* there is something in the list. Your "if" condition says: if I'm past the end, just use the first one. But look at the statement 3 lines above: self.frame_index = 0 - you *are* already setting this to zero, so an "if" block that sets it to zero as well is not going to help. Think about it: if 0 is the index of the first element, you can only access frames[0] if there is at least one element. This means that using index 0 with an empty list *is* going out of range. Does that make sense? The thing to debug is why self.frames is empty, meaning why animation_frames is empty since you set self.frames to animation_frames. I see that animation_frames is passed as the second parameter to the constructor, so look at your code that builds this object with ParticleEffect(pos, animation_frames, groups) in create_grass_particles and find why animation_frames is empty. Good luck!
@LuisPereira-bn8jq
2 жыл бұрын
I didn't follow the tutorial line by line (I watch the video in chunks, then try to implement the functionality myself, which is better for learning), but your error doesn't make sense to me. The line HERE--: self.image = self.frames[self.frame_index] you gave is inside the init method, so this line is only ran when the particle is created, which means that self.frame_index will always be 0 here (since you just set self.frame_index = 0 a few lines before). So the only way for you to get a "list index out of range" here is if your self.frames is an empty list... which suggests an issue with self.frames. One way this can happen is if your path to the art assets is wrong, so that running import_folder returns an empty list.
@allisteria5906
2 жыл бұрын
TL:DR Make sure your Current Working Directory is the same as the location of your main .py file. Ayo, I had the exact same error. I know for me specifically, I had trouble right from the beginning because my python terminal's current working directory was the folder I was launching my IDE from, and it took me far longer than it should have to realize that lol. I use Visual Studio Code as my IDE. I always launch VSC from a root folder(that is to say the folder that contains the project in it's entirety) and so the settings default to using that root folder as the current working directory. If you downloaded any of the code from Github, when you extracted the contents it created a file, and that is the file I would launch VSC from. So basically whenever I would launch the main .py the project would throw FileNotFoundErrors, and I found a temporary work around by removing one of the periods. From "../" to "./". Nearly every file path the video shows us he states that we need to move up one working directory, with the "../". But whenever I used the same file pathing as shown in the video it would fail. For me it is because my Current Working Directory was a different folder than the folder that my main .py was being executed from. If the CWD is not the same as main .py then whenever a file path is read it will always fail. What's essentially going is that when a file path is called the program thinks it's somewhere different than it actually is. Think of it like an elevator into an underground secret lab or something. The main .py file is located on sublevel 3, and when called the file path says: "Okay we're on sublvl 3, we need to gotta go up to sublvl 2 to retrieve the data we need to do stuff!". But the program doesn't really know it's in sublvl 3, it relies on the Python Terminal for that. So if the CWD is set for sublvl 2 (like mine was by being set to the root file I was launching VSC from) the file path is going to say: "Okay bois we're on sublvl 2 and we gotta go up to sublvl 1!" It was not until I ran into the same error that you posted about that I figured out what was going on. Once I changed the Current Working Directory in the Python Terminal to the same folder as the main .py, which is located in the "code" folder, everything worked perfectly. Maybe this helps, if not sorry for the life story lol. EDIT: main .py were all hyperlinks, gave 'em all a space.
@LuisPereira-bn8jq
2 жыл бұрын
@@allisteria5906 Trying to keep track of current work directory should work, but it's probably not the best solution. It could cause issues, for instance, if the code was transferred to a different machine. First, for debugging purposes, it may make sense to replace relative paths that are giving issues with the absolute file paths. This allows you to verify that the rest of the code is working, and that the issue really is with the paths... Second, you can improve on the above by using code to generate the absolute paths for your specific machine. For example, is you start the a file with from pathlib import Path directory = str(Path(__file__).parent) the variable "directory" will contain the absolute path to the directory containing this file. So then you can just add stuff to the directory path to generate absolute paths for all the other files.
@allisteria5906
2 жыл бұрын
@@LuisPereira-bn8jq I understand what you're saying. I don't mean constantly keep track of what your CWD, because to my knowledge, the CWD doesn't really change in this project. It's just to make sure that the working file (main. py) and terminal are in sync. a simple "cd" in the terminal could potentially be all he needs. I'm assuming that our man is following the video, that's what I have been doing. So if he's followed the code exactly( Which is what I'm assuming most of us are doing) and everything is set up correctly then it should work. My issue is that I didn't set up my IDE correctly, I'm simply putting that forward as a possible solution. There is no need to change what code he's showing us since it all works (for the video, himself and myself) up to that point. An error like that almost 6 hours into the video indicates to me that it's probably something on the user side, rather than inherently wrong with the code he's following. Now what you're saying makes sense, and is definitely a good approach. I absolutely encourage learning to properly debug software (It's something I'm currently learning)
Screw it, I'm learning Python.
@swallowedinthesea11
2 жыл бұрын
bool('You can do it!')
You are blowing my mind for a completely guide. Thanks very much for your sharing knowledge
Awesome content and well explained. Perfection!
at 1:44:30 you are using the walk method wich dont aways return a list of files in order. Maybe its bc i'm using 3.8 but idk. Before the second for loop in line 17 i use img_files.sort() so this is in order and the surfaces match perfectly.
@simonthies214
2 жыл бұрын
Thanks for that solution... I had the same problem
@animeareformen8658
Жыл бұрын
excuse me I am at 1:50:37 and the code gives me an error for this line of code "surf = graphics['oggetti'][int(col)]", do you know why could give it ?