Commit 0138361a by BellCodeEditor

save project

parent 60d6ea55
Showing with 18 additions and 3 deletions
import pygame import pygame
from pygame import locals from pygame import locals
import random
# 初始化pygame,为使用pygame做准备 # 初始化pygame,为使用pygame做准备
pygame.init() pygame.init()
fp=pygame.time.Clock() fp=pygame.time.Clock()
...@@ -10,11 +11,15 @@ up=pygame.image.load("up.png") ...@@ -10,11 +11,15 @@ up=pygame.image.load("up.png")
left=pygame.image.load("left.png") left=pygame.image.load("left.png")
apple=pygame.image.load("apple.png") apple=pygame.image.load("apple.png")
body=pygame.image.load("body.png") body=pygame.image.load("body.png")
myfont=pygame.font.Font("neuropol.ttf",17)
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)]
setheading="right" setheading="right"
head=right head=right
Screen = pygame.display.set_mode((800,600)) Screen = pygame.display.set_mode((800,600))
apple_x=270
apple_y=240
score=0
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
print(event) print(event)
...@@ -41,12 +46,22 @@ while True: ...@@ -41,12 +46,22 @@ while True:
y-=30 y-=30
else: else:
y+=30 y+=30
position.append((x,y)) 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) 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(bg,(0,0))
Screen.blit(head,(x,y)) Screen.blit(head,(x,y))
Screen.blit(apple,(270,240)) for i in range(len(position)-1):
for i in range(3):
Screen.blit(body,position[i]) Screen.blit(body,position[i])
Screen.blit(apple,(apple_x,apple_y))
Screen.blit(text,(700,30))
pygame.display.update() pygame.display.update()
fp.tick(3) 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