Commit 43fb72d4 by BellCodeEditor

save project

parent c16ebb67
Showing with 7 additions and 1 deletions
import pygame import pygame
from pygame import locals from pygame import locals
import random
# 初始化pygame,为使用pygame做准备 # 初始化pygame,为使用pygame做准备
pygame.init() pygame.init()
background=pygame.image.load('bg.png') background=pygame.image.load('bg.png')
...@@ -11,6 +12,8 @@ up=pygame.image.load('up.png') ...@@ -11,6 +12,8 @@ up=pygame.image.load('up.png')
down=pygame.image.load('down.png') down=pygame.image.load('down.png')
x,y=240,120 x,y=240,120
position=[(180,90),(180,120),(210,120),(x,y)] position=[(180,90),(180,120),(210,120),(x,y)]
apple_x=360
apple_y=360
setheading="right" setheading="right"
snake_head=right snake_head=right
# 创建一个窗口 # 创建一个窗口
...@@ -43,6 +46,9 @@ while True: ...@@ -43,6 +46,9 @@ while True:
else: else:
y += 30 y += 30
position.append((x,y)) position.append((x,y))
if x ==apple_x and y ==apple_y:
apple_x=random.randint(0,660)
apple_y=random.randint(0,480)
position.pop(0) position.pop(0)
screen.blit(background,(0,0)) screen.blit(background,(0,0))
screen.blit(snake_head,position[-1]) screen.blit(snake_head,position[-1])
...@@ -50,7 +56,7 @@ while True: ...@@ -50,7 +56,7 @@ 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])
screen.blit(food,(360,300)) screen.blit(food,(apple_x,apple_y))
# screen.blit(body,(210,120)) # screen.blit(body,(210,120))
# screen.blit(body,(180,120)) # screen.blit(body,(180,120))
pygame.display.update() 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