Commit cb6b2983 by BellCodeEditor

save project

parent 1a770eb1
Showing with 1998 additions and 6 deletions
import pygame import pygame
from pygame import locals from pygame import locals
# 初始化pygame,为使用pygame做准备 import random
pygame.init() pygame.init()
# 创建一个窗口
screen=pygame.display.set_mode((660,480)) screen=pygame.display.set_mode((660,480))
FPSCLOCK=pygame.time.Clock() FPSCLOCK=pygame.time.Clock()
background=pygame.image.load('bg.png') background=pygame.image.load('bg.png')
...@@ -13,10 +11,14 @@ body=pygame.image.load('body.png') ...@@ -13,10 +11,14 @@ body=pygame.image.load('body.png')
left=pygame.image.load('left.png') left=pygame.image.load('left.png')
up=pygame.image.load('up.png') up=pygame.image.load('up.png')
down=pygame.image.load('down.png') down=pygame.image.load('down.png')
my_food=pygame.font.Font('neuropol.ttf',18)
x,y=240,120 x,y=240,120
apple_x=360
apple_y=300
post=[(180,90),(180,120),(210,120),(x,y)] post=[(180,90),(180,120),(210,120),(x,y)]
set='right' set='right'
snake_head=right snake_head=right
scroo=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:
...@@ -42,11 +44,2002 @@ while True: ...@@ -42,11 +44,2002 @@ while True:
y-=30 y-=30
if set=='down': if set=='down':
y+=30 y+=30
if x==apple_x and y==apple_y:
num1=random.randint(1,22)
num2=random.randint(1,16)
apple_x=num1*30-30
apple_y=num2*30-30
scroo+=10
else:
post.pop(0)
post.append((x,y)) post.append((x,y))
post.pop(0)
screen.blit(background,(0,0)) screen.blit(background,(0,0))
screen.blit(food,(apple_x,apple_y))
screen.blit(snake_head,post[-1]) screen.blit(snake_head,post[-1])
for i in range(len(post)-1): for i in range(len(post)-1):
screen.blit(body,post[i]) screen.blit(body,post[i])
info='Scroo:'+str(scroo)
text=my_food.render(info,True,(0,0,0))
screen.blit(text,(540,10))
if x<0 or x>630 or y<0 or y>450:
scroo==0
pygame.display.update() pygame.display.update()
FPSCLOCK.tick(3) FPSCLOCK.tick(4)
\ 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