Commit 793ea04a by BellCodeEditor

save project

parent d5739bd2
Showing with 23 additions and 3 deletions
import random
import pygame import pygame
from pygame import locals from pygame import locals
...@@ -41,6 +42,20 @@ while True: ...@@ -41,6 +42,20 @@ 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
while True:
for event in pygame.event.get():
if event.type==locals.QUIT
exit()
if event.type==locals.KEYDOWN:
if event.type
if event.type==
if event.type==
# 设置贪吃蛇的头部坐标 # 设置贪吃蛇的头部坐标
if setheading == "right": if setheading == "right":
...@@ -51,6 +66,11 @@ while True: ...@@ -51,6 +66,11 @@ while True:
y -= 30 y -= 30
else: else:
y += 30 y += 30
if x==apple_x and y=apple_y:
apple_x=random.(0,660)
apple_y=random.(0,480)
apple_x=apple_x×30
apple_x=apple_y×30
position.append((x, y)) position.append((x, y))
position.pop(0) position.pop(0)
# 将背景图画上去 # 将背景图画上去
...@@ -60,9 +80,10 @@ while True: ...@@ -60,9 +80,10 @@ while True:
# 将贪吃蛇的身体画上去 # 将贪吃蛇的身体画上去
for i in range(len(position)-1): for i in range(len(position)-1):
screen.blit(body, position[i]) screen.blit(body, position[i])
apple_x=360
apple_y=300
screen.blit(food,(apple_x apple_y))
# 将果实画上去 # 将果实画上去
screen.blit(food, (360, 300))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
FPSCLOCK.tick(3) FPSCLOCK.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