本程序采用闪电侠美剧的音乐,气势宏大,激情飞扬。
""" 闪电侠接金币。本程序先会显示封面,然后按空格键进入游戏。 闪电侠见钱眼开,披星戴月,一路逛奔只为了去接金币。 """ import os from npc import * from coin import * from flashman import * from background import * os.environ['SDL_VIDEO_CENTERED'] = '1' width,height = 960,720 screen = pygame.display.set_mode((width,height)) pygame.display.set_caption('闪电侠接金币by李兴球') cover = pygame.image.load('闪电侠接金币封面.png') cover_w = cover.get_width() cover_h = cover.get_height() cover2 = cover.copy() pygame.mixer.init() pygame.mixer.music.load("The Flash Theme Song.wav") pygame.mixer.music.play(-1,0) coinsound = pygame.mixer.Sound("coin/collect.wav") screen.fill((23,83,55)) screen.blit(cover,(width//2 - cover_w//2,height//2 - cover_h//2)) pygame.display.update() clock = pygame.time.Clock() start_flag = True # 显示封面 scale = 1.01 running = True while running: event = pygame.event.poll() if event.type == QUIT: running = False start_flag = False if event.type == KEYDOWN: if event.key == K_SPACE: running = False if cover2.get_width() < width: cover2 = pygame.transform.rotozoom(cover,0,scale) cover_w = cover2.get_width() cover_h = cover2.get_height() screen.blit(cover2,(width//2 - cover_w//2,height//2 - cover_h//2)) pygame.display.update() scale += 0.005 clock.tick(60) # 如果在上面显示封面的过程中按了退出键,则结束程序 if start_flag == False: pygame.quit() exit() # 旋转缩小而去 angle = 0 cover3 = cover2.copy() running = True while running: event = pygame.event.poll() if event.type == QUIT: running = False start_flag = False if cover3.get_width() > 10: cover3 = pygame.transform.rotozoom(cover2,angle,scale) cover_w = cover3.get_width() cover_h = cover3.get_height() screen.fill((0,0,0)) screen.blit(cover3,(width//2 - cover_w//2,height//2 - cover_h//2)) pygame.display.update() scale -= 0.05 angle += 10 else: running = False clock.tick(60) # 如果在上面显示封面的过程中按了退出键,则结束程序 if start_flag == False: pygame.quit() exit() # 下面开始进入游戏中.......... bgs = pygame.image.load("space.png") background = Background(bgs,screen) # 实例化闪电侠 images = [f"im1/flash{i}.png" for i in range(1,4)] images = [pygame.image.load(im) for im in images] # 向右造型序列 images_right = [pygame.transform.rotozoom(im,0,0.4) for im in images] # 向左造型序列 images_left = [pygame.transform.flip(im,True,False) for im in images_right] man = FlashMan(images_right,images_left) # 金币程序段 images_coin = [f"coin/{i}.png" for i in range(8)] images_coin = [pygame.image.load(im) for im in images_coin] # 金币造型序列 images_coin = [pygame.transform.rotozoom(im,0,0.4) for im in images_coin] coingroup = pygame.sprite.Group() pygame.time.set_timer(USEREVENT,1000) # NPC程序段 images_npc = [f"im2/flash{i}.png" for i in range(1,4)] images_npc = [pygame.image.load(im) for im in images_npc] # 向右造型序列 images_right = [pygame.transform.rotozoom(im,0,0.4) for im in images_npc] # 向左造型序列 images_left = [pygame.transform.flip(im,True,False) for im in images_right] AI = NPC(images_right,images_left,screen) coins_man = 0 coins_ai = 0 running = True while running: for event in pygame.event.get(): if event.type == QUIT:running = False if event.type == USEREVENT: coingroup.add(Coin(images_coin,screen)) AI.update() man.update() coingroup.update() background.update() # 下面是闪电侠和金币的碰撞检测 c1 = pygame.sprite.spritecollide(man,coingroup,True) if c1 : coinsound.play() coins_man += 1 # 下面是逆闪电侠AI和金币的碰撞检测 c2 = pygame.sprite.spritecollide(AI,coingroup,True) if c2 : coinsound.play() coins_ai += 1 background.draw() screen.blit(man.image,man.rect) coingroup.draw(screen) screen.blit(AI.image,AI.rect) pygame.display.update() clock.tick(60) pygame.quit()
下载pygame版侠电侠接金币完整版源代码,包含各种模块与素材,请
需要浏览更多吗?
成为会员后,登陆才能继续浏览!联系微信scratch8即可办理会员。
(会员专属:能浏览所有文章,下载所有带链接的Python资源。)