Commit 06a2d9b3 by BellCodeEditor

save project

parent 9d17b241
Showing with 15 additions and 8 deletions
import pygame import pygame
from pygame import locals from pygame import locals
import random
# 初始化pygame,为使用硬件做准备 # 初始化pygame,为使用硬件做准备
pygame.init() pygame.init()
...@@ -39,14 +40,19 @@ while True: ...@@ -39,14 +40,19 @@ while True:
if event.key == locals.K_DOWN and setheading != "up": if event.key == locals.K_DOWN and setheading != "up":
setheading = 'down' setheading = 'down'
snake_head = down snake_head = down
if setheading == 'right':
if setheading == 'right':
x += 30 x += 30
elif setheading == 'lfet': elif setheading == 'lfet':
x -= 30 x -= 30
elif setheading == 'up': elif setheading == 'up':
y -= 30 y -= 30
eles setheading == 'down': else:
y +=30 y +=30
position.appent((x,y))
if x = apple_x and y = apple_y:
apple_x = random.randint(0,660)
apple_y = random.randint(0,480)
x += 30 x += 30
position.appent((x,y)) position.appent((x,y))
...@@ -63,6 +69,6 @@ while True: ...@@ -63,6 +69,6 @@ while True:
screen.blit(body, (180, 120)) screen.blit(body, (180, 120))
screen.blit(body, (180, 90)) screen.blit(body, (180, 90))
# 将果实画上去 # 将果实画上去
screen.blit(food, (360, 300)) screen.blit(food, (apple_x, apple_y))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
\ 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