Commit 3874bfa9 by BellCodeEditor

auto save

parent 2f73c9dc
Showing with 8 additions and 1947 deletions
import pygame
from pygame import locals
# 初始化pygame,为使用硬件做准备
pygame.init()
# 创建一个窗口
screen = pygame.display.set_mode((660, 480))
RPG=pygame.time.Clock()
# 背景
background = pygame.image.load('bg.png')
#body
right = pygame.image.load('right.png')
food = pygame.image.load('apple.png')
body = pygame.image.load('body.png')
......@@ -18,14 +17,14 @@ left=pygame.image.load('left.png')
right_a='right'
right_b=right
X,Y=240,120
SB=[(210,120),(180,120),(180,90),(240,120),(X,Y)]
X,Y=240,90
SB=[(180,120),(180,90),(210,90),(X,Y)]
while True:
for event in pygame.event.get():
if event.type == locals.QUIT:
# 接收到退出事件后退出程序
exit()
elif event.type == locals.KEYDOWN:
if event.type == locals.KEYDOWN:
if event.key == locals.K_RIGHT and right_a != 'left':
right_a == 'right'
right_b== right
......@@ -38,17 +37,14 @@ while True:
if event.key == locals.K_UP and right_a != 'down':
right_b == up
right_a =='up'
if right_a == 'right':
X+=30
if right_a == 'left':
X-=30
if right_a == 'up':
if right_b == 'up':
Y+=30
if right_a == "down":
Y-=30
X+=30
if right_b == "down":
Y-=30
SB.append((X,Y))
SB.pop(0)
# 将背景图画上去
......@@ -56,1944 +52,9 @@ while True:
# 将贪吃蛇画上去
screen.blit(right, (X, Y))
for i in range(len(SB)-1):
screen.blit(body, SB[i])
# 将贪吃蛇的身体画上去
# screen.blit(body, (210, 120))
# screen.blit(body, (180, 120))
# screen.blit(body, (180, 90))
screen.blit(body, SB[i])
# 将果实画上去
screen.blit(food, (360, 300))
# 刷新画面
pygame.display.update()
RPG.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