Conversation
| for event in pygame.event.get(): | ||
| if event.type == pygame.QUIT: | ||
| gameExit = True | ||
| return gameExit |
There was a problem hiding this comment.
Unless I miss my guess, this doesn't actually wind up getting called?
There was a problem hiding this comment.
Ah, yep -- y'all check for pygame.QUIT, alongside checking for "q" and such, in the game loop. Calling pygame.event.get() outside of the game loop can cause some issues, so this function is probably not a good idea to use.
| def __init__(self, **kwargs): | ||
| super(Rainbow,self).__init__(**kwargs) | ||
|
|
||
| #init unicorn/snake image |
There was a problem hiding this comment.
Minor nitpick -- usually, class comments are set inside the class.
e.g.,
class Rainbow(Image):
`''' init rainbow image '''``
| return gameOver | ||
|
|
||
|
|
||
| #function to handle orientation of unicorn depending on which direction it is going |
There was a problem hiding this comment.
Function comments usually go inside the function itself :D.
| @@ -0,0 +1,282 @@ | |||
| import sys | |||
There was a problem hiding this comment.
Not sure what the deal is with this file - looks like a copy of game.py might've accidentally been added as .py~?
For what it's worth, some editors will make automatic backups with the ~ suffix; that might be what happened here. Since Git tracks history itself, there's no need to add/commit backups to it!
| return (self.display_width/2, self.display_height/2) | ||
| #identify if unicorn intersects carrot. | ||
| def did_collide(self,obj1, obj2): | ||
| if obj1.x > obj2.x and obj1.x < obj2.x + obj2.image_width or obj1.x + obj1.image_width > obj2.x and obj1.x + obj1.image_width < obj2.x + obj2.image_width: |
There was a problem hiding this comment.
Fun fact - if statements can be split up amongst multiple lines for ease of use/reading/debugging! Nothing wrong with what you did here, of course - just an option.
| gameOver = False | ||
| snake_head = [] | ||
| snake_head.append(self.x) | ||
| snake_head.append(self.y) |
There was a problem hiding this comment.
You can just declare snake_head as [self.x, self.y], rather than appending twice to an empty list.
| super(Carrot,self).__init__(**kwargs) | ||
|
|
||
| def set_random_location(self,display_width,display_height): | ||
| self.x = round(random.randrange(0, display_width-self.image_width)) |
There was a problem hiding this comment.
Many snake games avoid allowing targets to spawn "inside" the snake itself. Could be interesting to think about how one would go about doing that!
| pygame.display.quit(str()) | ||
| pygame.quit() | ||
|
|
||
| run_game(800,600) |
There was a problem hiding this comment.
Sometimes, it's useful to add in run_game commands (and other such run commands) in an if __name__ == "__main__" loop, so that if you import functions/objects from here into another file it won't automatically start up a game.
| self.x += self.delta_x | ||
| self.y += self.delta_y | ||
| # self.delta_x = 0 | ||
| # self.delta_y = 0 |
|
|
||
|
|
||
| #function to handle orientation of unicorn depending on which direction it is going | ||
| def handle_tail(self): |
There was a problem hiding this comment.
Not sure how getting the icon orientation is "handling tail", but this is a solid way to go about it with the tools in pygame.
No description provided.