Commit d3a1e5cc by BellCodeEditor

save project

parent c83fae5f
Showing with 14 additions and 6 deletions
import pygame import pygame
from pygame import locals from pygame import locals
import random
# 初始化pygame,为使用硬件做准备 # 初始化pygame,为使用硬件做准备
pygame.init() pygame.init()
...@@ -19,6 +20,8 @@ right_a='right' ...@@ -19,6 +20,8 @@ right_a='right'
right_b=right right_b=right
x,y=240, 120 x,y=240, 120
a_b=[(120,120),(150,120),(180,120),(x,y)] a_b=[(120,120),(150,120),(180,120),(x,y)]
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:
...@@ -40,15 +43,19 @@ while True: ...@@ -40,15 +43,19 @@ while True:
if right_a=='light': if right_a=='light':
x+=30 x+=30
if right_a=='left': elif right_a=='left':
x-=30 x-=30
if right_a=='up': elif right_a=='up':
y-=30 y-=30
if right_a=='down': else :
y+=30 y+=30
x+=30
a_b.append((x,y)) a_b.append((x,y))
if x==apple_x and y==apple_ty:
numder1_x=random.randint(1,22)
numder2_y=random.randint(1,16)
apple_x=numder1*30-30
apple_y=numder2*30-30
else:
a_b.pop(0) a_b.pop(0)
# 将背景图画上去 # 将背景图画上去
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
...@@ -60,7 +67,7 @@ while True: ...@@ -60,7 +67,7 @@ while True:
# 将果实画上去 # 将果实画上去
screen.blit(food, (360, 300)) screen.blit(food, (apple_x, apple_y))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
r.tick(3) r.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