中途岛海战0.1版

python midway war中途岛海战0.1版
python midway war中途岛海战0.1版

中途岛海战是本人编写的一个飞机大战游戏。这个版本的敌机有三种阵形,一种是一字型阵列,一种是走8字型阵列,还有一种是走椭圆形阵列。这是最原始的版本,方便学习。vip会员扫码付款后,可向博主直接索取代码。 下面是部分代码预览:

"""
   中途岛海战2019年9月20号雏形程序,含三个阵列。
   这个版本是最基础的原形了,含有所有的模块,没有配音,没有封面,单人版本.
   雏形版本方便学习。vip会员可直接向博主索取源代码。   
"""
import pygame
from pygame.locals import *
from enemy0 import Enemy0
from enemy2 import Enemy2
from enemy8 import Enemy8
from player import * 
from player_bullet import *

def reden(image):
    """去掉绿色和蓝色,保留红色像素值"""
    image_3Darray = pygame.surfarray.array3d(image) # 转为矩阵
    image_3Darray[:,:,1:] = 0
    return pygame.surfarray.make_surface(image_3Darray)

def spawn_player_bullet(imgright,imgleft,imgup,screen,pbg,shoot_int,pos):
    """
       每隔一定时间产生玩家所射击的子弹
    """
    global frame_counter ,scatter_bullet_amounts 
    if frame_counter % shoot_int == 0 :        
        if scatter_bullet_amounts > 0 :
            scatter_bullet_amounts -= 2                
            pb2 = Player_Bullet(imgright,pos,(14,-14),screen)
            pb3 = Player_Bullet(imgleft,pos,(-14,-14),screen)               
            pbg.add(pb2)                   # 增加到子弹组
            pbg.add(pb3)                   # 增加到子弹组
        
        pb1 = Player_Bullet(imgup,pos,(0,-20),screen)
        pbg.add(pb1)                       # 增加到子弹组
    ...............................................
def main():
    """主要函数"""
    global frame_counter ,scatter_bullet_amounts,shoot_interval
    
    width,height = size = 960,720
        
    screen = pygame.display.set_mode(size)
    pygame.display.set_caption("Python中途岛海战by李兴球")
    bg = pygame.image.load('images/海洋.png')    

    # 玩家飞机程序段
    player_images = ["player_images/Plane 1.png"]
    player_images.append("player_images/Plane 2.png")
    player_images.append("player_images/Plane 3.png")
    dead_images = ["player_images/Plane Explode.png"]
    dead_images.append("player_images/Death1.png")
    dead_images.append("player_images/Death2.png")
    dead_images.append("player_images/Death3.png")
    dead_images.append("player_images/Death4.png")
    dead_images.append("player_images/Death5.png")

    player_images = [pygame.image.load(im) for im in player_images]
    dead_images = [pygame.image.load(im) for im in dead_images]
    [rml_read_more]
    player_group = pygame.sprite.Group()
    death_group = pygame.sprite.Group()
    
    ks = [K_UP,K_DOWN,K_LEFT,K_RIGHT]
    pos = width//2,height-100
    p = player_images,dead_images,pos,ks
    p1 = Player(*p)
    player_group.add(p1)
    
    # 敌机处理程序段    
    enemy_image = "enemy_images/Fighters.png"
    enemy_image = pygame.image.load(enemy_image)
   
    enemy_exp_images = [f"enemy_images/Death{i}.png" for i in range(1,6)]
    enemy_exp_images = [pygame.image.load(im) for im in enemy_exp_images]

    enemy_group = pygame.sprite.Group()    
    
    Enemys = [Enemy0,Enemy2,Enemy8]        # 敌机类组成的列表
    p0 = enemy_image,enemy_exp_images,(0,height//2),screen
    p2 = enemy_image,enemy_exp_images,350,200,(width//2,height//2)
    p8 = enemy_image,enemy_exp_images,(width//2,100)
    ps = [p0,p2,p8]
    intervals = [400,200,200]              # 每个敌机出现的间隔时间

    # 玩家子弹处理程序段
    .................................
    
    clock = pygame.time.Clock()
    # 开始迭代三种类型的队列敌机
    for index in range(3):
        Enemy = Enemys[index]
        p = ps[index]
        inter = intervals[index]
        pygame.time.set_timer(USEREVENT,inter) # 设置自定义事件定时器
        idle_time = 0                     # 两个飞行阵列之间的计时器
        enemy_array_begin  = True         # 飞行阵列开始
        running = True
         
        while running and enemy_array_begin:
            frame_counter += 1
            for event in pygame.event.get():
                if event.type == QUIT:running=False
                if Enemy.counter < Enemy.amounts:
                   if event.type == USEREVENT:
                      enemy_group.add(Enemy(*p))
            .........................................
            screen.blit(bg,(0,0))       # 渲染背景
            enemy_group.draw(screen)    # 画每架飞机
            player_group.draw(screen)   # 画玩家操作的飞机
            player_bullet_group.draw(screen)
            pygame.display.update()     # 更新显示
            clock.tick(60)
        if not running: break 
        
    pygame.quit()

if __name__ == "__main__":

    main()

 

下载完整源代码与素材,包含所有子模块等,请扫码付款。

VIP免费查看

已有0人支付

本站所有作品,教程等皆为原创,盗版必究。一旦付款,表示同意本站知识付费原则:数字商品,不支持退款。亦可直接向微信号scratch8付款购买。QQ群免费教学群:225792826 (提供真实姓名可入群)
李兴球的博客_Python创意编程技术前沿_pygame » 中途岛海战0.1版
scratch

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

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