Commit ada42052 by BellCodeEditor

save project

parent 83d9b868
Showing with 11 additions and 4 deletions
import pygame import pygame
from pygame import locals from pygame import locals
import random
x=240 x=240
y=120 y=120
apple_x = 360
apple_y = 300
SHENTI=[(180,90),(180,120),(210,120),(x,y)] SHENTI=[(180,90),(180,120),(210,120),(x,y)]
# 初始化pygame,为使用硬件做准备 # 初始化pygame,为使用硬件做准备
pygame.init() pygame.init()
# 创建一个窗口 # 创建一个窗口
screen = pygame.display.set_mode((889, 880)) screen = pygame.display.set_mode((660, 480))
# 背景 # 背景
background = pygame.image.load('bg.png') background = pygame.image.load('bg.png')
...@@ -48,7 +51,10 @@ while True: ...@@ -48,7 +51,10 @@ while True:
elif setheading == "left": elif setheading == "left":
x-=30 x-=30
else : else :
x+=30 x+=30
if apple_x and y == apple_x:
apple_x = random.randint(0,660)
apple_y = random.randint(0,480)
SHENTI.append((x,y)) SHENTI.append((x,y))
SHENTI.pop(0) SHENTI.pop(0)
# 接收到退出事件后退出程序 # 接收到退出事件后退出程序
...@@ -66,7 +72,7 @@ while True: ...@@ -66,7 +72,7 @@ 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()
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