Commit 2b756c4c by BellCodeEditor

auto save

parent 4dd4abd7
Showing with 32 additions and 6 deletions
......@@ -3,7 +3,7 @@ from pygame import locals
import random
# 初始化pygame,为使用硬件做准备
pygame.init()
myfont=pygame.font.Font("neuropol.ttf",15)
myfont=pygame.font.Font("neuropol.ttf",15)#设置字体
# 创建一个窗口
screen = pygame.display.set_mode((660, 480))
FPSCLOCK = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
......@@ -58,7 +58,11 @@ while True:
if x==apple_x and y==apple_y:
apple_x=random.randint(1,22)*30-30
apple_y=random.randint(1,16)*30-30
score+=10
score+=10#贪吃蛇吃到苹果
if x<apple_x+30 and x>apple_x and y<apple_y-30 and y>apple_y:
apple_x=random.randint(1,22)*30-30
apple_y=random.randint(1,16)*30-30
score+=10#贪吃蛇吃到苹果
else:
position.pop(0)#贪吃蛇身体增加
# 将背景图画上去
......@@ -71,9 +75,8 @@ while True:
screen.blit(body, position[i])
# 将果实画上去
screen.blit(food, (apple_x, apple_y))
# 刷新画面
info="Score"+str(score)
text=myfont.render(info,True,(0,255,0))
screen.blit(text,(540,10))
pygame.display.update()
FPSCLOCK.tick(5)
\ No newline at end of file
pygame.display.update()# 刷新画面
FPSCLOCK.tick(10)
\ No newline at end of file
import pygame
from pygame import locals
pygame.init()#初始化
screen = pygame.display.set_mode((800,600))#创建窗口
background = pygame.image.load('bg.png')#载入背景
right = pygame.image.load('right.png')#载入蛇头
left = pygame.image.load('left.png')#载入蛇头
up = pygame.image.load('up.png')#载入蛇头
down = pygame.image.load('down.png')#载入蛇头
body = pygame.image.load('body.png')#载入蛇身
food = pygame.image.load('apple.png')#载入果实
while True:
for event in pygame.event.get():#监听玩家事件
if event.type == locals.QUIT:
exit()#收到退出事件后退出程序
screen.blit(background,(0,0))#渲染背景图
screen.blit(right,(240,120))#渲染蛇头
screen.blit(food,(360,300))#渲染果实
screen.blit(body,(210,120))#渲染蛇身
screen.blit(body,(180,120))#渲染蛇身
screen.blit(body,(180,90))#渲染蛇身
pygame.display.update()#刷新画面
\ 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