Skip to content

turning in mp3#2

Open
jonathankohlmeier wants to merge 28 commits intosd16fall:masterfrom
jonathankohlmeier:master
Open

turning in mp3#2
jonathankohlmeier wants to merge 28 commits intosd16fall:masterfrom
jonathankohlmeier:master

Conversation

@jonathankohlmeier
Copy link

No description provided.

for event in pygame.event.get():
if event.type == pygame.QUIT:
gameExit = True
return gameExit

Choose a reason for hiding this comment

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

Unless I miss my guess, this doesn't actually wind up getting called?

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

Function comments usually go inside the function itself :D.

@@ -0,0 +1,282 @@
import sys

Choose a reason for hiding this comment

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

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:

Choose a reason for hiding this comment

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

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)

Choose a reason for hiding this comment

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

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))

Choose a reason for hiding this comment

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

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)

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

nitpick: commented-out code



#function to handle orientation of unicorn depending on which direction it is going
def handle_tail(self):

Choose a reason for hiding this comment

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

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.

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.

4 participants

Comments