中途岛海战2019年9月20号雏形程序,含全部模块。

"""
   中途岛海战2019年9月20号雏形程序,含全部模块。
   这个版本是最基础的原形了,含有所有的模块,没有配音,没有封面,单人版本.
   雏形版本方便学习。会员可直接向博主索取源代码。
   
"""
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 check_collide_player_and_enemy(player_group,enemy_group):
    """检测玩家组成员和敌人组成员之间的碰撞"""
    result_dict = pygame.sprite.groupcollide(player_group,enemy_group,False,True)
    for player in result_dict:
        player.gasolines = 0

def check_collide_playerbullet_and_enemy(player_bullet_group,enemy_group):
    """检测玩家子弹和敌人组成员之间的碰撞"""
    result_dict = pygame.sprite.groupcollide(player_bullet_group,enemy_group,True,False)
    for bullet,enemis in result_dict.items():
       [e.die() for e in enemis]
        
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]
    

You must log in to read the rest of this article. Please log in or register as a user.