python版飞机大战及码源

这是一个使用pygame库编写的Python飞机大战游戏,包含多种类型的敌机和子弹,以及资源强化功能。用户可以控制自己的战机,体验丰富的游戏效果。完整代码和素材可在GitHub上找到。
摘要由CSDN通过智能技术生成

飞机大战是之前学习python时根据网上的代码改编写成的,有完整的代码和素材。
文件结构:
在这里插入图片描述
images文件:放置程序所需要的图片素材
sound文件:放置程序所需要的声音素材
bullet.py:有普通以及强化两种类型的子弹

import pygame
class Bullet1(pygame.sprite.Sprite):
    def __init__(self, positon):
        pygame.sprite.Sprite.__init__(self)

        self.image = pygame.image.load("images/bullet1.png").convert_alpha()
        self.rect = self.image.get_rect()
        self.rect.left, self.rect.top = positon
        self.speed = 12
        self.active = True
        self.mask = pygame.mask.from_surface(self.image)

    def move(self):
        self.rect.top -= self.speed

        if self.rect.top < 0:
            self.active = False
    
    def reset(self, position):
        self.rect.left, self.rect.top = position
        self.active = True

class Bullet2(pygame.sprite.Sprite):
            def __init__(self, positon):
                pygame.sprite.Sprite.__init__(self)

                self.image = pygame.image.load("images/bullet2.png").convert_alpha()
                self.rect = self.image.get_rect()
                self.rect.left, self.rect.top = positon
                self.speed = 20
                self.active = True
                self.mask = pygame.mask.from_surface(self.image)

            def move(self):
                self.rect.top -= self.speed

                if self.rect.top < 0:
                    self.active = False

            def reset(self, position):
                self.rect.left, self.rect.top = position
                self.active = True



enemy.py:有小型,中型,大型三种类型的敌机

import pygame
from random import *
import time
import bullet

class SmallEnemy(pygame.sprite.Sprite):
    def __init__(self, bg_size):
        pygame.sprite.Sprite.__init__(self)

        self.image1 = pygame.image.load("images/enemy1.png").convert_alpha()
        self.destroy_images = []
        self.destroy_images.extend([\
            pygame.image.load("images/enemy1_down1.png").convert_alpha(),\
            pygame.image.load("images/enemy1_down2.png").convert_alpha(),\
            pygame.image.load("images/enemy1_down3.png").convert_alpha(),\
            pygame.image.load("images/enemy1_down4.png").convert_alpha()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值