Commit ba8b8e62 by BellCodeEditor

auto save

parent 8f3f1cad
Showing with 11 additions and 6 deletions
import random
import pygame
pygame.font.init()
from pygame import locals
x,y=240,120
apple_x,apple_y=360,300
......@@ -17,7 +16,9 @@ pygame.init()
sj=pygame.time.Clock()
# 创建一个窗口
screen = pygame.display.set_mode((660, 480))
# 背景
a=pygame.image.load('a.png')
background = pygame.image.load('bg.png')
right = pygame.image.load('right.png')
food = pygame.image.load('apple.png')
......@@ -28,6 +29,7 @@ down = pygame.image.load('down.png')
z=[(180,90),(180,120),(210,120),(x,y)]
fx='right'
snakehead = right
while True:
for event in pygame.event.get():
print(event)
......@@ -47,6 +49,7 @@ while True:
if event.key == locals.K_DOWN and fx !='up':
fx = 'down'
snakehead = down
if fx == 'right':
x += 30
elif fx == 'left':
......@@ -55,9 +58,8 @@ while True:
y -= 30
else:
y += 30
if x<0 or x>630 or y<0 or y>450:
exit()
# x+=30
z.append((x,y))
if x == apple_x and y == apple_y:
......@@ -68,6 +70,7 @@ while True:
# screen.blit(body,())
# z.pop(0)
# 将背景图画上去
screen.blit(background, (0, 0))
# 将贪吃蛇画上去
screen.blit(snakehead, (x,y))
......@@ -79,7 +82,9 @@ while True:
# screen.blit(body, (180,90))
# 将果实画上去
screen.blit(food, (apple_x, apple_y))
pygame.font.init()
#print(pygame.font.get_fonts())
#self.font=pygame.font.SysFont(None,48)
#self.font = pygame.font.SysFont('arial',48)
# 刷新画面
pygame.display.update()
sj.tick(15)
\ No newline at end of file
sj.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