Commit f49dd7bc by BellCodeEditor

auto save

parent 66d26448
Showing with 19 additions and 3 deletions
import pygame import pygame
import random
from pygame import locals from pygame import locals
# 初始化pygame,为使用pygame做准备 # 初始化pygame,为使用pygame做准备
...@@ -14,6 +15,7 @@ left=pygame.image.load("left.png") ...@@ -14,6 +15,7 @@ left=pygame.image.load("left.png")
down=pygame.image.load("down.png") down=pygame.image.load("down.png")
up=pygame.image.load("up.png") up=pygame.image.load("up.png")
x=240 x=240
y=120 y=120
...@@ -23,6 +25,9 @@ body=pygame.image.load("body.png") ...@@ -23,6 +25,9 @@ body=pygame.image.load("body.png")
fangxiang="right" fangxiang="right"
tou=right tou=right
apple_x=360
apple_y=300
while True: while True:
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == locals.QUIT: if event.type == locals.QUIT:
...@@ -49,13 +54,23 @@ while True: ...@@ -49,13 +54,23 @@ while True:
y+=30 y+=30
if fangxiang == "up": if fangxiang == "up":
y-=30 y-=30
position.append((x,y)) position.append((x,y))
position.pop(0)
if x==apple_x and y==apple_y:
num1=random.randint(1,22)
num2=random.randint(1,16)
apple_x=num1*30-30
apple_y=num2*30-30
else:
position.pop(0)
screen.blit(background,(0,0)) screen.blit(background,(0,0))
screen.blit(apple,(60,90)) screen.blit(apple,(apple_x,apple_y))
screen.blit(tou, position[-1]) screen.blit(tou, position[-1])
for i in range(len(position)-1): for i in range(len(position)-1):
screen.blit(body, position[i]) screen.blit(body, position[i])
pygame.display.update() pygame.display.update()
FPS.tick(3) FPS.tick(3)
\ 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