用户:
菜狗乖乖查看:0 回复:0 评论:0 创建时间:2022-04-28T12:56:02
【作品展示】

【作品介绍】
看看
【作品源代码】
import pygame, random, time
pygame.init()
sc = pygame.display.set_mode((500, 500))
pygame.display.set_caption('拯救omo')
gameover = pygame.image.load(r"C:\mxcmaterials\拯救omo\go.png")
youwin = pygame.image.load(r"C:\mxcmaterials\拯救omo\yw.png")
bg = pygame.image.load(r"C:\mxcmaterials\拯救omo\bg.png")
omo_img = pygame.image.load(r"C:\mxcmaterials\拯救omo\omo.png")
boom_img = pygame.image.load(r"C:\mxcmaterials\拯救omo\bomb.png")
star_img = pygame.image.load(r"C:\mxcmaterials\拯救omo\star.png")
ghost_img = pygame.image.load(r"C:\mxcmaterials\拯救omo\ghost.png")
pygame.mixer.music.load(r"C:\mxcmaterials\拯救omo\bgm.wav")
pygame.mixer.music.play(loops=-1)
click_sound = pygame.mixer.Sound(r"C:\mxcmaterials\拯救omo\click.wav")
win_sound = pygame.mixer.Sound(r"C:\mxcmaterials\拯救omo\win.wav")
over_sound = pygame.mixer.Sound(r"C:\mxcmaterials\拯救omo\lose.wav")
star_sound = pygame.mixer.Sound(r"C:\mxcmaterials\拯救omo\gs.wav")
class Omo():
def __init__(self):
self.x = random.randint(0, 450)
self.y = random.randint(0, 450)
def draw_me(self):
sc.blit(omo_img, (self.x, self.y))
class Boom(Omo):
def draw_me(self):
sc.blit(boom_img, (self.x, self.y))
def move(self):
self.x += 1
if self.x > 500:
self.x = 0
def mouse_click():
for event in pygame.event.get():
mouse_x, mouse_y = pygame.mouse.get_pos()
if event.type == pygame.MOUSEBUTTONDOWN:
for omo in omo_list:
if omo.x < mouse_x < omo.x + 50 and omo.y < mouse_y < omo.y + 50:
omo_list.remove(omo)
click_sound.play()
return "omo"
for boom in boom_list:
if boom.x < mouse_x < boom.x + 50 and boom.y < mouse_y < boom.y + 50:
over_sound.play()
return "boom"
omo_list = []
for i in range(10):
omo = Omo()
omo_list.append(omo)
boom_list = []
for i in range(10):
boom = Boom()
boom_list.append(boom)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
exit()
sc.blit(bg, (0, 0))
re = mouse_click()
if re == 'boom':
pygame.mixer.music.stop()
sc.blit(bg, (0, 0))
sc.blit(gameover, (100, 200))
pygame.display.update()
time.sleep(5)
break
if len(omo_list) == 0:
pygame.mixer.music.stop()
sc.blit(bg, (0, 0))
sc.blit(youwin, (100, 200))
win_sound.play()
pygame.display.update()
time.sleep(5)
break
for omo in omo_list:
omo.draw_me()
for boom in boom_list:
boom.draw_me()
boom.move()
pygame.display.update()
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn