Commit b2603901 by BellCodeEditor

save project

parent 9cd0652a
Showing with 7 additions and 3 deletions
import pygame import pygame
from pygame import locals#locals为pygame子模块(必写) from pygame import locals#locals为pygame子模块(必写)
from random import * import random
#初始化pygame,为使用硬件做准备 #初始化pygame,为使用硬件做准备
pygame.init() pygame.init()
#创建一个窗口 #创建一个窗口
...@@ -14,7 +14,7 @@ body=pygame.image.load('body.png') ...@@ -14,7 +14,7 @@ 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_font=pygame.image.Font('neuropol.ttf',18)#字体 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)]
...@@ -42,12 +42,16 @@ while True: ...@@ -42,12 +42,16 @@ while True:
#设置贪吃蛇的头部坐标 #设置贪吃蛇的头部坐标
if setheading=='right': if setheading=='right':
x+=30 x+=30
snake_head=right
elif setheading=='left': elif setheading=='left':
x-=30 x-=30
snake_head=left
elif setheading=='up': elif setheading=='up':
y-=30 y-=30
snake_head=up
else: else:
y+=30 y+=30
snake_head=down
position.append((x,y)) position.append((x,y))
#刷新苹果 #刷新苹果
if x==a_x and y==a_y: if x==a_x and y==a_y:
...@@ -71,7 +75,7 @@ while True: ...@@ -71,7 +75,7 @@ while True:
screen.blit(food,(a_x,a_y)) screen.blit(food,(a_x,a_y))
#绘制分数 #绘制分数
info='Score:'+str(score) info='Score:'+str(score)
text=my_font.render(info,Ture,(0,0,0)) text=my_font.render(info,True,(0,0,0))
screen.blit(text,(540,10)) screen.blit(text,(540,10))
#刷新画面 #刷新画面
pygame.display.update() pygame.display.update()
......
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