用户:
Gin琴蕾查看:0 回复:0 评论:0 创建时间:2021-07-06T19:53:45
【作品展示】

【作品介绍】
good—————点击飞翔吧!
【作品源代码】
#导入库
import pygame
import random
import time
class Bird():
def __init__(self):
self.bird_sprites = [pygame.image.load("{}.png".format(i)) for i in range(3)]
self.a = 0
self.bird_x =50
self.bird_y = 100
self.down_speed= 0.4
self.up_speed = 0
self.bird_rect = self.bird_sprites[0].get_rect()
def bird_speed(self):
self.bird_rect.center = (self.bird_x,self.bird_y)
self.up_speed -= self.down_speed
self.bird_y -= self.up_speed
if self.up_speed>0:
self.a = 0
if self.up_speed<0:
self.a = 2
def bird_cruch(self):
result_up = self.bird_rect.colliderect(new_wall.wall_up_rect)
result_down = self.bird_rect.colliderect(new_wall.wall_down_rect)
if result_down or result_up or self.bird_rect.top > 512:
return True
class Wall():
def __init__(self):
self.wall_down = pygame.image.load("bottom.png")
self.wall_up = pygame.image.load("top.png")
self.wall_x = 288
self.gap = 170
self.offset = random.randint(-100,100)
self.wall_up_rect = self.wall_up.get_rect()
self.wall_down_rect = self.wall_down.get_rect()
def wall_update(self):
self.wall_up_rect.center = (self.wall_x, 0+self.offset)
self.wall_down_rect.center = (self.wall_x, 370+self.gap+self.offset)
self.wall_x -= 2
if self.wall_x < -80:
self.wall_x = 288
self.offset = random.randint(-100, 100)
# 游戏初始化,设置游戏标题,窗口等
pygame.init()
screen = pygame.display.set_mode((288, 512))
pygame.display.set_caption("翱翔吧!源码精灵")
# 获得游戏背景图片,源码精灵图片,初始坐标等
ks = pygame.image.load("开始.png")
a = pygame.image.load("background.png")
b = pygame.image.load("background2.png")
background_image = a
new_bird = Bird()
new_wall = Wall()
clock = pygame.time.Clock()
asd = "a"
success = pygame.mixer.Sound("success.wav")
pygame.mixer.music.load('bgm.mp3')
pygame.mixer.music.play(-1)
font = pygame.font.SysFont("SimHei",24)
fon = pygame.font.SysFont("SimHei",50)
score = 0
# pygame循环,源码精灵翱翔
keep_going = True
while keep_going:
for event in pygame.event.get():
if event.type == pygame.QUIT:
keep_going = False
if event.type == pygame.MOUSEBUTTONDOWN:
new_bird.up_speed = 7
asd = "b"
if asd == "a":
screen.blit(background_image, (0, 0))
screen.blit(ks,(60,400))
elif asd == "b":
new_bird.bird_speed()
screen.blit(background_image, (0, 0))
screen.blit(new_bird.bird_sprites[new_bird.a],new_bird.bird_rect)
screen.blit(new_wall.wall_up,new_wall.wall_up_rect)
screen.blit(new_wall.wall_down,new_wall.wall_down_rect)
new_wall.wall_update()
text = font.render("得分:" + str(score),True,(225,215,0),(225,0,0))
screen.blit(text, (10, 10))
if new_bird.bird_cruch():
asd = "c"
background_image = b
if new_wall.wall_x < -70:
score +=1
success.play()
else:
screen.blit(background_image, (0, 0))
keep_going = False
pygame.display.update()
clock.tick(60)
# 退出游戏
time.sleep(2)
pygame.quit()
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn