Commit 74db5c0c by BellCodeEditor

save project

parent 035782a0
Showing with 16 additions and 5 deletions
import pygame
from pygame import locals
import turtle
# 初始化pygame,为使用pygame做准备
pygame.init()
......@@ -8,8 +9,11 @@ screen = pygame.display.set_mode((660,480))
fps=pygame.time.Clock()
#载入图片
bg=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')
apple=pygame.image.load('apple.png')
snake=pygame.image.load('right.png')
body=pygame.image.load('body.png')
x=360
y=300
......@@ -22,25 +26,32 @@ while True:
if event.type==locals.KEYDOWN:
if event.key==locals.K_RIGHT and heah!='left':
heah='right'
if event.key==locals.K_RIGHT and heah!='right':
if event.key==locals.K_LEFT and heah!='right':
heah='left'
if event.key==locals.K_RIGHT and heah!='down':
if event.key==locals.K_UP and heah!='down':
heah='up'
if event.key==locals.K_RIGHT and heah!='up':
if event.key==locals.K_DOWN and heah!='up':
heah='down'
if heah=="right":
x+=30
tou=right
if heah=="left":
x-=30
tou=left
if heah=="down":
y+=30
tou=down
if heah=="up":
y-=30
tou=up
pos.append((x,y))
pos.pop(0)
if x==a_x and y==a_y:
a_x=random.randint.randint(0,22)*30
a_y=random.randint.randint(0,16)*30
screen.blit(bg,(0,0))
screen.blit(apple,(120,150))
screen.blit(snake,(x,y))
screen.blit(tou,(x,y))
for i in range(len(pos)-1):
screen.blit(body,pos[i])
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