Closed SophieWalden closed 5 years ago
Personally I like to split files for two reasons. To put a class in it for an object such as player sprites:
In your case you could do it for each tile.
You could do it for buttons.
The second reason is to split files if you have different stages to a game (such as in your game):
Main menu.
Options.
The game.
For this option you could add a flow in three stages:
Initialize graphics, render items for this screen.
Check and process input events (clicks, keys etc.)
Draw the screen.
In your main file (your case game.py) you would check which part is active, (the game, the options, the main menu, etc), whichever part is active on that file you call the three main functions.
About the pygame.draw, make sure you are using the same surface to draw on ofc. Make sure you import pygame in each file. You should only need to initialize pygame once. If you can't get it to work, post the error that's being thrown and send me the draft code file.
Ya, I learned how to split the file in 10 minutes and I'm going to update it now. Didn't see this comment till I uploaded it, but It still worked. You just have to execute the Main file for it to run
-8BitToaster
If anyone would like to help me I can't really figure this out. I have never split files with games using pygame, but have only done it with other projects that don't require pygame. Thus some errors about splitting it up come. If anyone would like to comment I have a few questions.
When I try to use pygame.draw. in another file, it doesn't like it because it says that it doesn't recognize pygame. I have tried pygame.init() and importing pygame, but I can't seem to get it to work.
I'm wondering whether when I try to change the files I should try to convert the functions to classes. I have heard of doing such things before, but I didn't know if I should do that.
I have been looking up tutorials on how to do have multiple files with pygame, but I can't find any that actually help me. Does anyone have any recommendations?
Any help with these questions is greatly appreciated and I would like to split it into multiple files before I continue.
-8BitToaster