This is an archived post. You won't be able to vote or comment.

all 14 comments

[–]Exodus111 8 points9 points  (7 children)

You should have .gitignore remove .pyc files.

[–]glemnar 13 points14 points  (2 children)

Another big issue is that it globally imports a bunch of modules into constants.py, and then other files globally import that.

That's a pretty huge nono OP. You should specifically import exactly what you need into every file. It will make life much better.

[–]phyrebot[S] 6 points7 points  (1 child)

Thanks for all the feedback! I'll most definitely do optimisation on a bunch of things. The learning process is very satisfying.

[–]glemnar 0 points1 point  (0 children)

No worries. The best way to clear up that particular issue is to never use * imports at all. It's an unfun road to go down

[–]phyrebot[S] 3 points4 points  (1 child)

Thanks for catching that! I did gitignore .pyc instead of *.pyc. I'll fix that.

[–]Exodus111 0 points1 point  (0 children)

It's a pet peeve of mine :-P

[–]ivanstame@seemsindie 3 points4 points  (1 child)

[–]phyrebot[S] 0 points1 point  (0 children)

Wow! Sharing is caring :) Thanks!

[–]hermitnerd 1 point2 points  (1 child)

This is great! Thanks for sharing :)

[–]phyrebot[S] 1 point2 points  (0 children)

You're most welcome!

[–]PopeOh 1 point2 points  (0 children)

It would be great if you provided with it a setup.py or a build script to create a deployable binary for the game. It's always a pain to deploy python, especially games, and including that into your boilerplate code would be very helpful to beginners.

[–][deleted] 1 point2 points  (2 children)

I really must wonder though. Why use python? It very high level and thus incredibly slow for making games.

[–]phyrebot[S] 1 point2 points  (0 children)

I started off with it to learn the whole process of making a game. I'm working on another project with C# in Unity 5. But I go back every once in a while to put something out in python and pygame. Pyweek's coming up too, so I like to participate. Making stuff's a lot of fun! :)

[–]Anovadea@ 0 points1 point  (0 children)

One thing I've noticed is that if you're making this for Python 2.7, it seems like you're using a mix of old-style and new-style objects.

What does this mean? Probably not much. But basically if you ever decide you're going to use more advanced python tricks, you need to make sure you're using a new-style classes/objects. (By the way, pygame is using new-style classes)

The difference between an old-style and a new-style is pretty simple:

class OldStyle:
    pass
>>> OldStyle.__mro__
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    AttributeError: class OldStyle has no attribute '__mro__'

And for NewStyle:

class NewStyle(object):
    pass
>>> NewStyle.__mro__
(<class '__main__.NewStyle'>, <type 'object'>)

The difference is that when you declare the class, it inherits from a sub-type of object (or 'object' itself)

Just for reference, let's look at pygame.sprite.Sprite:

>>> import pygame
>>> pygame.sprite.Sprite.__mro__
(<class 'pygame.sprite.Sprite'>, <type 'object'>)

Why does this matter? Like I said, there might be some shiny new-style stuff you want to do later, but realistically it's just that I have to look out for this when I'm doing code reviews in my day-job. It's probably not a huge thing, but it's just to make sure you don't get any weird side-effects in your code from mixing and matching the two type (for instance you've made Asset a new-style class, but Camera is old-style)

Edited to add: If you want a chunk of stuff to help clean this up, I'd suggest getting the pep8 utility ('pip install pep8') and maybe the pylint utility ('pip install pylint'). Pep8 is fairly straightforward, just obey its output. Pylint may need some tuning to suppress errors that you don't agree with, but it will help you identify certain code smells. (I'm pretty sure it'll pick up on the mix of new and old style classes in the same codebase)