资源简介

Python版的飞机大战源码和素材。素材包括有图片和声音

资源截图

代码片段和文件信息

# -*- coding: utf-8 -*-
“““
Created on Wed Sep 11 16:36:03 2013

@author: Leo
“““

import pygame

SCREEN_WIDTH = 480
SCREEN_HEIGHT = 800

TYPE_SMALL = 1
TYPE_MIDDLE = 2
TYPE_BIG = 3

# 子弹类
class Bullet(pygame.sprite.Sprite):
    def __init__(self bullet_img init_pos):
        pygame.sprite.Sprite.__init__(self)
        self.image = bullet_img
        self.rect = self.image.get_rect()
        self.rect.midbottom = init_pos
        self.speed = 10

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

# 玩家类
class Player(pygame.sprite.Sprite):
    def __init__(self plane_img player_rect init_pos):
        pygame.sprite.Sprite.__init__(self)
        self.image = []                                 # 用来存储玩家对象精灵图片的列表
        for i in range(len(player_rect)):
            self.image.append(plane_img.subsurface(player_rect[i]).convert_alpha())
        self.rect = player_rect[0]                      # 初始化图片所在的矩形
        self.rect.topleft = init_pos                    # 初始化矩形的左上角坐标
        self.speed = 8                                  # 初始化玩家速度,这里是一个确定的值
        self.bullets = pygame.sprite.Group()            # 玩家飞机所发射的子弹的集合
        self.img_index = 0                              # 玩家精灵图片索引
        self.is_hit = False                             # 玩家是否被击中

    def shoot(self bullet_img):
        bullet = Bullet(bullet_img self.rect.midtop)
        self.bullets.add(bullet)

    def moveUp(self):
        if self.rect.top <= 0:
            self.rect.top = 0
        else:
            self.rect.top -= self.speed

    def moveDown(self):
        if self.rect.top >= SCREEN_HEIGHT - self.rect.height:
            self.rect.top = SCREEN_HEIGHT - self.rect.height
        else:
            self.rect.top += self.speed

    def moveLeft(self):
        if self.rect.left <= 0:
            self.rect.left = 0
        else:
            self.rect.left -= self.speed

    def moveRight(self):
        if self.rect.left >= SCREEN_WIDTH - self.rect.width:
            self.rect.left = SCREEN_WIDTH - self.rect.width
        else:
            self.rect.left += self.speed

# 敌人类
class Enemy(pygame.sprite.Sprite):
    def __init__(self enemy_img enemy_down_imgs init_pos):
       pygame.sprite.Sprite.__init__(self)
       self.image = enemy_img
       self.rect = self.image.get_rect()
       self.rect.topleft = init_pos
       self.down_imgs = enemy_down_imgs
       self.speed = 2
       self.down_index = 0

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

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-09-22 19:19  Python飞机大战\
     目录           0  2018-09-22 19:19  Python飞机大战\PythonShootGame-master\
     文件        2741  2016-06-29 01:29  Python飞机大战\PythonShootGame-master\gameRole.py
     文件        6403  2016-06-29 01:29  Python飞机大战\PythonShootGame-master\mainGame.py
     目录           0  2018-09-22 19:19  Python飞机大战\PythonShootGame-master\resources\
     目录           0  2018-09-22 19:19  Python飞机大战\PythonShootGame-master\resources\font\
     文件        1662  2016-06-29 01:29  Python飞机大战\PythonShootGame-master\resources\font\font.fnt
     文件        5193  2016-06-29 01:29  Python飞机大战\PythonShootGame-master\resources\font\font.png
     目录           0  2018-09-22 19:19  Python飞机大战\PythonShootGame-master\resources\image\
     文件       33518  2016-06-29 01:29  Python飞机大战\PythonShootGame-master\resources\image\background.png
     文件       20682  2016-06-29 01:29  Python飞机大战\PythonShootGame-master\resources\image\gameover.png
     文件        3388  2016-06-29 01:29  Python飞机大战\PythonShootGame-master\resources\image\shoot.pack
     文件      463797  2016-06-29 01:29  Python飞机大战\PythonShootGame-master\resources\image\shoot.png
     文件         793  2016-06-29 01:29  Python飞机大战\PythonShootGame-master\resources\image\shoot_background.pack
     文件       92377  2016-06-29 01:29  Python飞机大战\PythonShootGame-master\resources\image\shoot_background.png
     目录           0  2018-09-22 19:19  Python飞机大战\PythonShootGame-master\resources\sound\
     文件        8831  2016-06-29 01:29  Python飞机大战\PythonShootGame-master\resources\sound\achievement.mp3
     文件       12327  2016-06-29 01:29  Python飞机大战\PythonShootGame-master\resources\sound\big_spaceship_flying.mp3
     文件        7751  2016-06-29 01:29  Python飞机大战\PythonShootGame-master\resources\sound\bullet.mp3
     文件        8108  2016-06-29 01:29  Python飞机大战\PythonShootGame-master\resources\sound\bullet.wav
     文件        6815  2016-06-29 01:29  Python飞机大战\PythonShootGame-master\resources\sound\button.mp3
     文件       11287  2016-06-29 01:29  Python飞机大战\PythonShootGame-master\resources\sound\enemy1_down.mp3
     文件       17900  2016-06-29 01:29  Python飞机大战\PythonShootGame-master\resources\sound\enemy1_down.wav
     文件       12847  2016-06-29 01:29  Python飞机大战\PythonShootGame-master\resources\sound\enemy2_down.mp3
     文件       14444  2016-06-29 01:29  Python飞机大战\PythonShootGame-master\resources\sound\enemy2_down.wav
     文件        9415  2016-06-29 01:29  Python飞机大战\PythonShootGame-master\resources\sound\enemy3_down.mp3
     文件       71468  2016-06-29 01:29  Python飞机大战\PythonShootGame-master\resources\sound\enemy3_down.wav
     文件      117728  2016-06-29 01:29  Python飞机大战\PythonShootGame-master\resources\sound\game_music.mp3
     文件     1087532  2016-06-29 01:29  Python飞机大战\PythonShootGame-master\resources\sound\game_music.wav
     文件       14615  2016-06-29 01:29  Python飞机大战\PythonShootGame-master\resources\sound\game_over.mp3
     文件       44972  2016-06-29 01:29  Python飞机大战\PythonShootGame-master\resources\sound\game_over.wav
............此处省略4个文件信息

评论

共有 条评论