Skip to content

Conversation

@srangar03
Copy link

No description provided.

Copy link

@branchwelder branchwelder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall, I really couldn't find much to comment on!

@@ -0,0 +1,210 @@
import pygame

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seeing as this file is not used in your game, you shouldn't commit it with the rest of your work.

TextRect.center = ((display_width/2),(display_height/2))
screen.blit(TextSurf, TextRect)

pygame.display.update()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style nit: leave space between functions

screen.blit(background_image, (0, 0))
pygame.display.flip()

def text_objects(text, font):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that you organized your code into a bunch of different functions rather than cramming it all into the main loop 😺

"""
Define all the inital variables
"""
white = (255, 255, 255)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By convention, constants are ALL_CAPS e.g. WHITE.

background_size = (display_width, display_height)
car_size = (100, 67)

"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a docstring (it's not documenting a module, class, method, or function), so it should be a # comment instead of a """string""".

"""
Initialize the game
"""
pygame.init()
Copy link
Contributor

@osteele osteele Dec 5, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To take this to the next level, moving the top-level code into a function.

Then you can name the function, which makes the code more readable. For example, if the function is called initialize_game or init_game or game_init, then it's evident what it does even without the comment. Also, this gives you a place to attach the docstring (and examples!), if it is still useful.

This also makes it easier to test the code. This is (mostly) beyond the scope of this class, but it's a good habit to get into.

The global variables would be become attributes of a class, e.g. Game. The functions below would use e.g. self. barriers_list instead of global barriers_list.

"""
Initialize images
"""
background_colour = (white)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parens not necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants