Python Forum

Full Version: Pygame Heli Dodge
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I've spent the past few days developing this small game: 

http://www.mediafire.com/file/sz28835b23...Cooper.rar

Inside the rar file you'll find a Python version and a Windows Executable version of the game, if possible could i have some feedback on the methods i have used and the efficiency of my code , feed back is really appreciated.

Cheers George Cooper
(Mar-31-2017, 03:38 PM)georgecoopers Wrote: [ -> ]feed back is really appreciated.
1) psd files clutter up the code. Keep for dev, but not for releases

2) you should split your program into multiple files. The gameClass needs needs to be split up. A function (class method) should do one thing not tons and tons. You can easily have a plane class, a boat class, a bullet class, etc.

3) 
Quote:
            #This handles the start screen hover over start button
            if  windowHeight/2+(50)> mouse[1] > windowHeight/2 and windowWidth/2-(300) < mouse[0] < windowWidth/2-(200):
                self.surface.fill(LIGHT_GREEN, rect=[windowWidth/2 - 300 ,windowHeight/2, 100, 50])
                if click[0] == 1:
                    self.startGame = True

This kind of stuff is a nightmare of code. You should use pygame.rect to check collision detection. There should also be a button class to handle the meat of this kind o stuff. it should be as simple as
if button_rect.collidepoint(pygame.mouse.get_pos()):#mouse in button area
Then there area not magic numbers floating all over the place like yours is

4) this is by far the most important one. You should only have one main game loop. At any point in a single game there should only be on line of pygame.display.update() and one loop. I am assuming you got this method from one youtube tutorial from a user sentdex that teaches people to code this dreaded method. The below shows one of his examples and a recode i did of his horrible method to fix it. old is his method, converted is the same program using good habits. Best thing, its about 100 lines small, so easily able to figure out how the conversion happens. I would suggest to get rid of this habit ASAP before moving on. 
https://github.com/metulburr/pygame_code...bad_habits

5) I would use spritesheets instead of individual images.

6) I would separate your images, sounds, music (resources) from your source (py files).

7) I would use github to house your code at. It is much better than mediafire. There are so many things you are missing out by not using version control software. Here is a simple starter tutorial
https://python-forum.io/Thread-Basic-Cre...ed-scripts

EDIT:
adding attachment for referece
Thank you for the feed back, ill try to correct everything you have said.

Cheeers George Cooper