Commit 7fa3ed58 by BellCodeEditor

save project

parent d7a851f2
Showing with 24 additions and 4 deletions
import random
import pygame import pygame
from pygame import locals from pygame import locals
pygame.init() pygame.init()
...@@ -10,10 +11,14 @@ up=pygame.image.load('up.png') ...@@ -10,10 +11,14 @@ up=pygame.image.load('up.png')
down=pygame.image.load('down.png') down=pygame.image.load('down.png')
food=pygame.image.load('apple.png') food=pygame.image.load('apple.png')
body=pygame.image.load('body.png') body=pygame.image.load('body.png')
my_font=pygame.font.Font('neuropol.ttf',18)
x,y=240,120 x,y=240,120
position=[(180,90),(180,120),(210,120),(x,y)] position=[(180,90),(180,120),(210,120),(x,y)]
apple_x=360
apple_y=300
setheading="right" setheading="right"
snake_head=right snake_head=right
score=0
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
if event.type==locals.QUIT: if event.type==locals.QUIT:
...@@ -41,12 +46,27 @@ while True: ...@@ -41,12 +46,27 @@ while True:
else: else:
y +=30 y +=30
position.append((x,y)) position.append((x,y))
position.pop(0) info="score"+str(score)
if x==apple_x and y==apple_y:
a=random.randint(1,22)
b=random.randint(1,16)
apple_x=a*30-30
apple_y=b*30-30
score=score+1
else:
position.pop(0)
if x>630 or x<0 or y>450 or y<0:
exit()
elif position[-1] in position[0:-1]:
exit()
screen.blit(background,(0,0)) screen.blit(background,(0,0))
info="score"+str(score)
text=my_font.render(info,True,(0,0,0))
screen.blit(text,(0,0))
screen.blit(snake_head,position[-1]) screen.blit(snake_head,position[-1])
for i in range(len(position)-1): for i in range(len(position)-1):
screen.blit(body,position[i]) screen.blit(body,position[i])
screen.blit(food,(360,300)) screen.blit(food,(apple_x,apple_y))
pygame.display.update() pygame.display.update()
FPSCLOCK.tick(3) FPSCLOCK.tick(10)
\ No newline at end of file \ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment