Commit 0138361a by BellCodeEditor

save project

parent 60d6ea55
Showing with 20 additions and 5 deletions
import pygame
from pygame import locals
import random
# 初始化pygame,为使用pygame做准备
pygame.init()
fp=pygame.time.Clock()
......@@ -10,11 +11,15 @@ up=pygame.image.load("up.png")
left=pygame.image.load("left.png")
apple=pygame.image.load("apple.png")
body=pygame.image.load("body.png")
myfont=pygame.font.Font("neuropol.ttf",17)
x,y=240,120
position=[(180,90),(180,120),(210,120),(x,y)]
setheading="right"
head=right
Screen = pygame.display.set_mode((800,600))
apple_x=270
apple_y=240
score=0
while True:
for event in pygame.event.get():
print(event)
......@@ -40,13 +45,23 @@ while True:
elif setheading=="up":
y-=30
else:
y+=30
position.append((x,y))
position.pop(0)
y+=30
if x==apple_x and y==apple_y:
apple_x=random.randint(0,21)*30
apple_y=random.randint(1,15)*30
score+=1
else:
position.pop(0)
if x<0 or x>770 or y<0 or y>570:
exit()
position.append((x,y))
t="Scrore:"+str(score)
text=myfont.render(t,True,(0,0,0))
Screen.blit(bg,(0,0))
Screen.blit(head,(x,y))
Screen.blit(apple,(270,240))
for i in range(3):
for i in range(len(position)-1):
Screen.blit(body,position[i])
Screen.blit(apple,(apple_x,apple_y))
Screen.blit(text,(700,30))
pygame.display.update()
fp.tick(3)
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