Last active
November 10, 2017 16:57
-
-
Save bluemyria/49959d423cd4a59c37ef589c33107911 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Function For Moving Head | |
def moving_snake_head(self): | |
self.board.move(self.snake,self.x,self.y) | |
x1,y1,x2,y2=self.board.coords(self.snake) | |
if x1<=0 or y1<=0: | |
self.x=0 | |
self.y=0 | |
self.game_loss() | |
elif PLAYGROUND_HEIGHT<=y2 or PLAYGROUND_WIDTH<=x2: | |
self.x=0 | |
self.y=0 | |
self.game_loss() | |
else: | |
pass | |
return | |
# Snake Regularly Moving | |
def re_update(self): | |
self.moving_snake_head() | |
#self.update_snake_body_structure() | |
#self.food_of_snake() | |
return | |
# Snake Food | |
def food_of_snake(self): | |
if self.snake_food==None: | |
x1=random.randint(15,PLAYGROUND_WIDTH-15) | |
y1=random.randint(15,PLAYGROUND_HEIGHT-15) | |
self.snake_food=self.board.create_oval(x1,y1,x1+10,y1+10,fill='yellow', tag="food") | |
if self.snake_food: | |
x1,y1,x2,y2=self.board.coords(self.snake_food) | |
if len(self.board.find_overlapping(x1,y1,x2,y2))==2: | |
self.bodylength=self.bodylength+1 | |
self.board.delete("food") | |
self.snake_food=None | |
self.update_score_board() | |
return | |
# Creating Score Board | |
def creating_score_board(self): | |
self.scoreboard=Tkinter.Label(self, text="Score : {}".format(self.score)) | |
self.scoreboard.pack(anchor='n') | |
return | |
# Updating Score Board | |
def update_score_board(self): | |
self.score=self.score+1 | |
self.scoreboard['text']="Score : {}".format(self.score) | |
return | |
# Creating Snake Body Moving Function | |
def update_snake_body_structure(self): | |
x1,y1,x2,y2=self.board.coords(self.snake) | |
x2=(x2-((x2-x1)/2)) | |
y2=(y2-((y2-y1)/2)) | |
self.roadmap.append((x2,y2)) | |
self.board.delete('body') | |
time.sleep(0.2) | |
if len(self.roadmap)>=self.bodylength: | |
self.roadmap=self.roadmap[-self.bodylength:] | |
self.board.create_line(tuple(self.roadmap), tag="body",width=10,fill=SNAKE_BODY_COLOR) | |
return | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment