Commit de90e8cb by BellCodeEditor

save project

parent da5a92d2
Showing with 62 additions and 7 deletions
import pygame import pygame
from pygame import locals from pygame import locals
import random
# 初始化pygame,为使用硬件做准备 # 初始化pygame,为使用硬件做准备
pygame.init() pygame.init()
# 创建一个窗口 # 创建一个窗口
screen = pygame.display.set_mode((660, 480)) screen = pygame.display.set_mode((660, 480))#660, 480
FPSCLOCK = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数) FPSCLOCK = pygame.time.Clock() # pygame时钟,控制游戏速度(帧数)
# 背景 # 背景
background = pygame.image.load('bg.png') background = pygame.image.load('bg.png')
right = pygame.image.load('right.png') # 头 朝右 right = pygame.image.load('right.png') # 头 朝右
food = pygame.image.load('apple.png') # 食物 苹果 food = pygame.image.load('apple.png')
food1= pygame.image.load('apple.png')
food2 = pygame.image.load('apple.png')
food3 = pygame.image.load('apple.png')
food4 = pygame.image.load('apple.png')
food5= pygame.image.load('apple.png')
food6 = pygame.image.load('apple.png')
# 食物 苹果
body = pygame.image.load('body.png') # 身体 body = pygame.image.load('body.png') # 身体
left = pygame.image.load('left.png') # 头 朝左 left = pygame.image.load('left.png') # 头 朝左
up = pygame.image.load('up.png') # 头 朝上 up = pygame.image.load('up.png') # 头 朝上
down = pygame.image.load('down.png') # 头 朝下 down = pygame.image.load('down.png') # 头 朝下
ziti=pygame.font.Font('neuropol.ttf',18)
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,apple_y=360,300
apple_x1,apple_y1=360,300
apple_x2,apple_y2=360,300
apple_x3,apple_y3=360,300
apple_x4,apple_y4=360,300
apple_x5,apple_y5=360,300
apple_x6,apple_y6=360,300
setheading = "right" setheading = "right"
fenshu=0
snake_head = right snake_head = right
while True: while True:
...@@ -52,7 +68,37 @@ while True: ...@@ -52,7 +68,37 @@ 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,21)*30
apple_y=random.randint(0,15)*30
fenshu+=100
if x==apple_x1 and y==apple_y1:
apple_x1=random.randint(0,21)*30
apple_y1=random.randint(0,15)*30
fenshu+=100
if x==apple_x3 and y==apple_y3:
apple_x3=random.randint(0,21)*30
apple_y3=random.randint(0,15)*30
fenshu+=100
if x==apple_x4 and y==apple_y4:
apple_x4=random.randint(0,21)*30
apple_y4=random.randint(0,15)*30
fenshu+=100
if x==apple_x6 and y==apple_y6:
apple_x6=random.randint(0,21)*30
apple_y6=random.randint(0,15)*30
fenshu+=100
if x==apple_x5 and y==apple_y5:
apple_x5=random.randint(0,21)*30
apple_y5=random.randint(0,15)*30
fenshu+=100
else:
position.pop(0) position.pop(0)
# 将背景图画上去 # 将背景图画上去
screen.blit(background, (0, 0)) screen.blit(background, (0, 0))
# 将贪吃蛇的头画上去 # 将贪吃蛇的头画上去
...@@ -62,7 +108,16 @@ while True: ...@@ -62,7 +108,16 @@ while True:
screen.blit(body, position[i]) screen.blit(body, position[i])
# 将果实画上去 # 将果实画上去
screen.blit(food, (360, 300)) screen.blit(food, (apple_x, apple_y))
screen.blit(food1, (apple_x1, apple_y1))
screen.blit(food2, (apple_x2, apple_y2))
screen.blit(food3, (apple_x3, apple_y3))
screen.blit(food4, (apple_x4, apple_y4))
screen.blit(food5, (apple_x5, apple_y5))
screen.blit(food6, (apple_x6, apple_y6))
info="scoro"+str(fenshu)
text=ziti.render(info,True,(0,0,0))
screen.blit(text,(540,10))
# 刷新画面 # 刷新画面
pygame.display.update() pygame.display.update()
FPSCLOCK.tick(3) FPSCLOCK.tick(5)
\ No newline at end of file \ 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