闪电侠接金币源代码免费下载

你好,请进入Q群:225792826,免费下载本站最新提供的视频教程原创源码资料,从2020年2月20号到3月底,成为本站会员只要原价的3折,即2980元*0.3 = 894元 ,向微信scratch8付款即可成为本站会员。即可拥有本站所有原创资源,并提供技术支持。如本消息修改,以最后时间的为准。

python the flash man pick coin闪电侠接金币动画图
python the flash man pick coin闪电侠接金币动画图

本程序采用闪电侠美剧的音乐,气势宏大,激情飞扬。

"""
   闪电侠接金币。本程序先会显示封面,然后按空格键进入游戏。
   闪电侠见钱眼开,披星戴月,一路逛奔只为了去接金币。
"""

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()              
本站所有作品,教程等皆为原创,盗版必究。一旦付款,表示同意本站知识付费原则:数字商品,不支持退款。亦可直接向微信号scratch8付款购买。QQ群免费教学群:225792826 (提供真实姓名可入群)
李兴球的博客_Python创意编程技术前沿 » 闪电侠接金币源代码免费下载

学本领,探索更大的世界!

李兴球博客 风火轮编程主页