├── .gitignore ├── README.md ├── bin ├── __init__.py └── main.py ├── config ├── __init__.py └── settings.py ├── manage.py ├── material ├── image │ ├── background.png │ ├── bomb.png │ ├── btn_finish.png │ ├── bullet1.png │ ├── bullet2.png │ ├── enemy1.png │ ├── enemy1_down1.png │ ├── enemy1_down2.png │ ├── enemy1_down3.png │ ├── enemy1_down4.png │ ├── enemy2.png │ ├── enemy2_down1.png │ ├── enemy2_down2.png │ ├── enemy2_down3.png │ ├── enemy2_down4.png │ ├── enemy2_hit.png │ ├── enemy3_down1.png │ ├── enemy3_down2.png │ ├── enemy3_down3.png │ ├── enemy3_down4.png │ ├── enemy3_down5.png │ ├── enemy3_down6.png │ ├── enemy3_hit.png │ ├── enemy3_n1.png │ ├── enemy3_n2.png │ ├── game_loading1.png │ ├── game_loading2.png │ ├── game_loading3.png │ ├── game_loading4.png │ ├── game_over.png │ ├── game_pause_nor.png │ ├── game_pause_pressed.png │ ├── game_resume_nor.png │ ├── game_resume_pressed.png │ ├── hero1.png │ ├── hero2.png │ ├── hero_blowup_n1.png │ ├── hero_blowup_n2.png │ ├── hero_blowup_n3.png │ ├── hero_blowup_n4.png │ ├── life.png │ ├── shoot_copyright.png │ ├── ufo1.png │ └── ufo2.png ├── play.jpg └── sound │ ├── achievement.mp3 │ ├── achievement.wav │ ├── big_spaceship_flying.mp3 │ ├── big_spaceship_flying.wav │ ├── bullet.mp3 │ ├── bullet.wav │ ├── button.mp3 │ ├── button.wav │ ├── enemy1_down.mp3 │ ├── enemy1_down.wav │ ├── enemy2_down.mp3 │ ├── enemy2_down.wav │ ├── enemy2_out.wav │ ├── enemy3_down.mp3 │ ├── enemy3_down.wav │ ├── game_music.mp3 │ ├── game_music.wav │ ├── game_over.mp3 │ ├── game_over.wav │ ├── get_bomb.mp3 │ ├── get_bomb.wav │ ├── get_double_laser.mp3 │ ├── get_double_laser.wav │ ├── out_porp.mp3 │ ├── use_bomb.mp3 │ └── use_bomb.wav └── src ├── __init__.py ├── bullet.py ├── enemy.py └── plane.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | 28 | # PyInstaller 29 | # Usually these files are written by a python script from a template 30 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 31 | *.manifest 32 | *.spec 33 | 34 | # Installer logs 35 | pip-log.txt 36 | pip-delete-this-directory.txt 37 | 38 | # Unit test / coverage reports 39 | htmlcov/ 40 | .tox/ 41 | .coverage 42 | .coverage.* 43 | .cache 44 | nosetests.xml 45 | coverage.xml 46 | *.cover 47 | .hypothesis/ 48 | 49 | # Translations 50 | *.mo 51 | *.pot 52 | 53 | # Django stuff: 54 | *.log 55 | local_settings.py 56 | 57 | # Flask stuff: 58 | instance/ 59 | .webassets-cache 60 | 61 | # Scrapy stuff: 62 | .scrapy 63 | 64 | # Sphinx documentation 65 | docs/_build/ 66 | 67 | # PyBuilder 68 | target/ 69 | 70 | # Jupyter Notebook 71 | .ipynb_checkpoints 72 | 73 | # pyenv 74 | .python-version 75 | 76 | # celery beat schedule file 77 | celerybeat-schedule 78 | 79 | # SageMath parsed files 80 | *.sage.py 81 | 82 | # dotenv 83 | .env 84 | 85 | # virtualenv 86 | .venv 87 | venv/ 88 | ENV/ 89 | 90 | 91 | 92 | *~ 93 | .DS_Store 94 | */migrations 95 | db.sqlite3 96 | 97 | .idea/ 98 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 回忆中的飞机大战 2 | 3 | ## 使用 4 | ``` 5 | 环境: python3 + pygame 6 | 7 | clone 此项目, 启动 manage.py 即可. 8 | ``` 9 | 10 | ## 如图 11 | ![Image text](https://raw.githubusercontent.com/csrftoken/PlayPlane/master/material/play.jpg) 12 | 13 | -------------------------------------------------------------------------------- /bin/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # Date: 2017/11/30 4 | 5 | -------------------------------------------------------------------------------- /bin/main.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | import sys 5 | from pygame.locals import * 6 | 7 | from config.settings import * 8 | from src.plane import OurPlane # 导入我们的飞机 9 | from src.enemy import SmallEnemy 10 | from src.bullet import Bullet 11 | 12 | 13 | bg_size = 480, 852 # 初始化游戏背景大小(宽, 高) 14 | screen = pygame.display.set_mode(bg_size) # 设置背景对话框 15 | pygame.display.set_caption("飞机大战") # 设置标题 16 | 17 | background = pygame.image.load(os.path.join(BASE_DIR, "material/image/background.png")) # 加载背景图片,并设置为不透明 18 | 19 | 20 | # 血槽颜色绘制 21 | color_black = (0, 0, 0) 22 | color_green = (0, 255, 0) 23 | color_red = (255, 0, 0) 24 | color_white = (255, 255, 255) 25 | 26 | # 获取我方飞机 27 | our_plane = OurPlane(bg_size) 28 | 29 | 30 | def add_small_enemies(group1, group2, num): 31 | """ 32 | 添加小型敌机 33 | 指定个敌机对象添加到精灵组(sprite.group) 34 | 参数group1、group2是两个精灵组类型的形参,用以存储多个精灵对象(敌机)。 35 | 需要注意的一点是group既然是特定的精灵组结构体,在向其内部添加精灵对象时需要调用其对应的成员函数add() 36 | :return: 37 | """ 38 | for i in range(num): 39 | small_enemy = SmallEnemy(bg_size) 40 | group1.add(small_enemy) 41 | group2.add(small_enemy) 42 | 43 | 44 | def main(): 45 | # 响应音乐 46 | pygame.mixer.music.play(-1) # loops 接收该参数, -1 表示无限循环(默认循环播放一次) 47 | running = True 48 | switch_image = False # 切换飞机的标识位(使飞机具有喷气式效果) 49 | delay = 60 # 对一些效果进行延迟, 效果更好一些 50 | 51 | enemies = pygame.sprite.Group() # 生成敌方飞机组(一种精灵组用以存储所有敌机精灵) 52 | small_enemies = pygame.sprite.Group() # 敌方小型飞机组(不同型号敌机创建不同的精灵组来存储) 53 | 54 | add_small_enemies(small_enemies, enemies, 6) # 生成若干敌方小型飞机 55 | 56 | # 定义子弹, 各种敌机和我方敌机的毁坏图像索引 57 | bullet_index = 0 58 | e1_destroy_index = 0 59 | me_destroy_index = 0 60 | 61 | # 定义子弹实例化个数 62 | bullet1 = [] 63 | bullet_num = 6 64 | for i in range(bullet_num): 65 | bullet1.append(Bullet(our_plane.rect.midtop)) 66 | 67 | while running: 68 | 69 | # 绘制背景图 70 | screen.blit(background, (0, 0)) 71 | 72 | # 微信的飞机貌似是喷气式的, 那么这个就涉及到一个帧数的问题 73 | clock = pygame.time.Clock() 74 | clock.tick(60) 75 | 76 | # 绘制我方飞机的两种不同的形式 77 | if not delay % 3: 78 | switch_image = not switch_image 79 | 80 | for each in small_enemies: 81 | if each.active: 82 | # 随机循环输出小飞机敌机 83 | each.move() 84 | screen.blit(each.image, each.rect) 85 | 86 | pygame.draw.line(screen, color_black, 87 | (each.rect.left, each.rect.top - 5), 88 | (each.rect.right, each.rect.top - 5), 89 | 2) 90 | energy_remain = each.energy / SmallEnemy.energy 91 | if energy_remain > 0.2: # 如果血量大约百分之二十则为绿色,否则为红色 92 | energy_color = color_green 93 | else: 94 | energy_color = color_red 95 | pygame.draw.line(screen, energy_color, 96 | (each.rect.left, each.rect.top - 5), 97 | (each.rect.left + each.rect.width * energy_remain, each.rect.top - 5), 98 | 2) 99 | else: 100 | if e1_destroy_index == 0: 101 | enemy1_down_sound.play() 102 | screen.blit(each.destroy_images[e1_destroy_index], each.rect) 103 | e1_destroy_index = (e1_destroy_index + 1) % 4 104 | if e1_destroy_index == 0: 105 | each.reset() 106 | 107 | # 当我方飞机存活状态, 正常展示 108 | if our_plane.active: 109 | if switch_image: 110 | screen.blit(our_plane.image_one, our_plane.rect) 111 | else: 112 | screen.blit(our_plane.image_two, our_plane.rect) 113 | 114 | # 飞机存活的状态下才可以发射子弹 115 | if not (delay % 10): # 每十帧发射一颗移动的子弹 116 | bullet_sound.play() 117 | bullets = bullet1 118 | bullets[bullet_index].reset(our_plane.rect.midtop) 119 | bullet_index = (bullet_index + 1) % bullet_num 120 | 121 | for b in bullets: 122 | if b.active: # 只有激活的子弹才可能击中敌机 123 | b.move() 124 | screen.blit(b.image, b.rect) 125 | enemies_hit = pygame.sprite.spritecollide(b, enemies, False, pygame.sprite.collide_mask) 126 | if enemies_hit: # 如果子弹击中飞机 127 | b.active = False # 子弹损毁 128 | for e in enemies_hit: 129 | e.active = False # 小型敌机损毁 130 | 131 | # 毁坏状态绘制爆炸的场面 132 | else: 133 | if not (delay % 3): 134 | screen.blit(our_plane.destroy_images[me_destroy_index], our_plane.rect) 135 | me_destroy_index = (me_destroy_index + 1) % 4 136 | if me_destroy_index == 0: 137 | me_down_sound.play() 138 | our_plane.reset() 139 | 140 | # 调用 pygame 实现的碰撞方法 spritecollide (我方飞机如果和敌机碰撞, 更改飞机的存活属性) 141 | enemies_down = pygame.sprite.spritecollide(our_plane, enemies, False, pygame.sprite.collide_mask) 142 | if enemies_down: 143 | our_plane.active = False 144 | for row in enemies: 145 | row.active = False 146 | 147 | # 响应用户的操作 148 | for event in pygame.event.get(): 149 | if event.type == 12: # 如果用户按下屏幕上的关闭按钮,触发QUIT事件,程序退出 150 | pygame.quit() 151 | sys.exit() 152 | 153 | if delay == 0: 154 | delay = 60 155 | delay -= 1 156 | 157 | # 获得用户所有的键盘输入序列(如果用户通过键盘发出“向上”的指令,其他类似) 158 | key_pressed = pygame.key.get_pressed() 159 | if key_pressed[K_w] or key_pressed[K_UP]: 160 | our_plane.move_up() 161 | if key_pressed[K_s] or key_pressed[K_DOWN]: 162 | our_plane.move_down() 163 | if key_pressed[K_a] or key_pressed[K_LEFT]: 164 | our_plane.move_left() 165 | if key_pressed[K_d] or key_pressed[K_RIGHT]: 166 | our_plane.move_right() 167 | 168 | # 绘制图像并输出到屏幕上面 169 | pygame.display.flip() 170 | 171 | 172 | 173 | 174 | -------------------------------------------------------------------------------- /config/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # Date: 2017/11/30 4 | 5 | -------------------------------------------------------------------------------- /config/settings.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | import os 5 | import pygame 6 | 7 | 8 | BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 9 | 10 | pygame.init() # 游戏初始化 11 | pygame.mixer.init() # 混音器初始化 12 | 13 | # 游戏背景音乐 14 | pygame.mixer.music.load(os.path.join(BASE_DIR, "material/sound/game_music.wav")) 15 | pygame.mixer.music.set_volume(0.2) 16 | 17 | # 子弹发射音乐 18 | bullet_sound = pygame.mixer.Sound(os.path.join(BASE_DIR, "material/sound/bullet.wav")) 19 | bullet_sound.set_volume(0.2) 20 | 21 | # 我方飞机挂了的音乐 22 | me_down_sound = pygame.mixer.Sound(os.path.join(BASE_DIR, "material/sound/game_over.wav")) 23 | me_down_sound.set_volume(0.2) 24 | 25 | # 敌方飞机挂了的音乐 26 | enemy1_down_sound = pygame.mixer.Sound(os.path.join(BASE_DIR, "material/sound/enemy1_down.wav")) 27 | enemy1_down_sound.set_volume(0.2) 28 | 29 | enemy2_down_sound = pygame.mixer.Sound(os.path.join(BASE_DIR, "material/sound/enemy2_down.wav")) 30 | enemy2_down_sound.set_volume(0.2) 31 | 32 | enemy3_down_sound = pygame.mixer.Sound(os.path.join(BASE_DIR, "material/sound/enemy3_down.wav")) 33 | enemy3_down_sound.set_volume(0.2) 34 | 35 | button_down_sound = pygame.mixer.Sound(os.path.join(BASE_DIR, "material/sound/button.wav")) 36 | button_down_sound.set_volume(0.2) 37 | 38 | level_up_sound = pygame.mixer.Sound(os.path.join(BASE_DIR, "material/sound/achievement.wav")) 39 | level_up_sound.set_volume(0.2) 40 | 41 | bomb_sound = pygame.mixer.Sound(os.path.join(BASE_DIR, "material/sound/use_bomb.wav")) 42 | bomb_sound.set_volume(0.2) 43 | 44 | get_bomb_sound = pygame.mixer.Sound(os.path.join(BASE_DIR, "material/sound/get_bomb.wav")) 45 | get_bomb_sound.set_volume(0.2) 46 | 47 | get_bullet_sound = pygame.mixer.Sound(os.path.join(BASE_DIR, "material/sound/get_double_laser.wav")) 48 | get_bullet_sound.set_volume(0.2) 49 | 50 | big_enemy_flying_sound = pygame.mixer.Sound(os.path.join(BASE_DIR, "material/sound/big_spaceship_flying.wav")) 51 | big_enemy_flying_sound.set_volume(0.2) 52 | 53 | -------------------------------------------------------------------------------- /manage.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | from bin.main import main 5 | 6 | 7 | if __name__ == '__main__': 8 | """ 9 | 环境: python3 + pygame 10 | running 起来就可以打飞机了O(∩_∩)O~. 11 | """ 12 | main() 13 | 14 | 15 | """ 16 | PlayPlane/ 17 | |-- bin/ 18 | | |-- main.py 程序运行主体程序 19 | |-- config/ 20 | | |-- settings.py 程序配置(例如: 游戏背景音乐的加载等) 21 | |-- material 程序素材放置(打飞机游戏素材放置) 22 | |-- ... 23 | |-- src/ 程序主体模块存放 24 | | |-- __init__.py 25 | | |-- bullet.py 我方飞机发射子弹实现代码存放 26 | | |-- enemy.py 敌方飞机实现代码存放 27 | | |-- plane.py 我方飞机实现代码存放 28 | |-- manage.py 程序启动文件 29 | |-- README.md 30 | """ -------------------------------------------------------------------------------- /material/image/background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/image/background.png -------------------------------------------------------------------------------- /material/image/bomb.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/image/bomb.png -------------------------------------------------------------------------------- /material/image/btn_finish.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/image/btn_finish.png -------------------------------------------------------------------------------- /material/image/bullet1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/image/bullet1.png -------------------------------------------------------------------------------- /material/image/bullet2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/image/bullet2.png -------------------------------------------------------------------------------- /material/image/enemy1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/image/enemy1.png -------------------------------------------------------------------------------- /material/image/enemy1_down1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/image/enemy1_down1.png -------------------------------------------------------------------------------- /material/image/enemy1_down2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/image/enemy1_down2.png -------------------------------------------------------------------------------- /material/image/enemy1_down3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/image/enemy1_down3.png -------------------------------------------------------------------------------- /material/image/enemy1_down4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/image/enemy1_down4.png -------------------------------------------------------------------------------- /material/image/enemy2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/image/enemy2.png -------------------------------------------------------------------------------- /material/image/enemy2_down1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/image/enemy2_down1.png -------------------------------------------------------------------------------- /material/image/enemy2_down2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/image/enemy2_down2.png -------------------------------------------------------------------------------- /material/image/enemy2_down3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/image/enemy2_down3.png -------------------------------------------------------------------------------- /material/image/enemy2_down4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/image/enemy2_down4.png -------------------------------------------------------------------------------- /material/image/enemy2_hit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/image/enemy2_hit.png -------------------------------------------------------------------------------- /material/image/enemy3_down1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/image/enemy3_down1.png -------------------------------------------------------------------------------- /material/image/enemy3_down2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/image/enemy3_down2.png -------------------------------------------------------------------------------- /material/image/enemy3_down3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/image/enemy3_down3.png -------------------------------------------------------------------------------- /material/image/enemy3_down4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/image/enemy3_down4.png -------------------------------------------------------------------------------- /material/image/enemy3_down5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/image/enemy3_down5.png -------------------------------------------------------------------------------- /material/image/enemy3_down6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/image/enemy3_down6.png -------------------------------------------------------------------------------- /material/image/enemy3_hit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/image/enemy3_hit.png -------------------------------------------------------------------------------- /material/image/enemy3_n1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/image/enemy3_n1.png -------------------------------------------------------------------------------- /material/image/enemy3_n2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/image/enemy3_n2.png -------------------------------------------------------------------------------- /material/image/game_loading1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/image/game_loading1.png -------------------------------------------------------------------------------- /material/image/game_loading2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/image/game_loading2.png -------------------------------------------------------------------------------- /material/image/game_loading3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/image/game_loading3.png -------------------------------------------------------------------------------- /material/image/game_loading4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/image/game_loading4.png -------------------------------------------------------------------------------- /material/image/game_over.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/image/game_over.png -------------------------------------------------------------------------------- /material/image/game_pause_nor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/image/game_pause_nor.png -------------------------------------------------------------------------------- /material/image/game_pause_pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/image/game_pause_pressed.png -------------------------------------------------------------------------------- /material/image/game_resume_nor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/image/game_resume_nor.png -------------------------------------------------------------------------------- /material/image/game_resume_pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/image/game_resume_pressed.png -------------------------------------------------------------------------------- /material/image/hero1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/image/hero1.png -------------------------------------------------------------------------------- /material/image/hero2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/image/hero2.png -------------------------------------------------------------------------------- /material/image/hero_blowup_n1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/image/hero_blowup_n1.png -------------------------------------------------------------------------------- /material/image/hero_blowup_n2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/image/hero_blowup_n2.png -------------------------------------------------------------------------------- /material/image/hero_blowup_n3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/image/hero_blowup_n3.png -------------------------------------------------------------------------------- /material/image/hero_blowup_n4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/image/hero_blowup_n4.png -------------------------------------------------------------------------------- /material/image/life.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/image/life.png -------------------------------------------------------------------------------- /material/image/shoot_copyright.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/image/shoot_copyright.png -------------------------------------------------------------------------------- /material/image/ufo1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/image/ufo1.png -------------------------------------------------------------------------------- /material/image/ufo2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/image/ufo2.png -------------------------------------------------------------------------------- /material/play.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/play.jpg -------------------------------------------------------------------------------- /material/sound/achievement.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/sound/achievement.mp3 -------------------------------------------------------------------------------- /material/sound/achievement.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/sound/achievement.wav -------------------------------------------------------------------------------- /material/sound/big_spaceship_flying.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/sound/big_spaceship_flying.mp3 -------------------------------------------------------------------------------- /material/sound/big_spaceship_flying.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/sound/big_spaceship_flying.wav -------------------------------------------------------------------------------- /material/sound/bullet.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/sound/bullet.mp3 -------------------------------------------------------------------------------- /material/sound/bullet.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/sound/bullet.wav -------------------------------------------------------------------------------- /material/sound/button.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/sound/button.mp3 -------------------------------------------------------------------------------- /material/sound/button.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/sound/button.wav -------------------------------------------------------------------------------- /material/sound/enemy1_down.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/sound/enemy1_down.mp3 -------------------------------------------------------------------------------- /material/sound/enemy1_down.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/sound/enemy1_down.wav -------------------------------------------------------------------------------- /material/sound/enemy2_down.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/sound/enemy2_down.mp3 -------------------------------------------------------------------------------- /material/sound/enemy2_down.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/sound/enemy2_down.wav -------------------------------------------------------------------------------- /material/sound/enemy2_out.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/sound/enemy2_out.wav -------------------------------------------------------------------------------- /material/sound/enemy3_down.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/sound/enemy3_down.mp3 -------------------------------------------------------------------------------- /material/sound/enemy3_down.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/sound/enemy3_down.wav -------------------------------------------------------------------------------- /material/sound/game_music.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/sound/game_music.mp3 -------------------------------------------------------------------------------- /material/sound/game_music.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/sound/game_music.wav -------------------------------------------------------------------------------- /material/sound/game_over.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/sound/game_over.mp3 -------------------------------------------------------------------------------- /material/sound/game_over.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/sound/game_over.wav -------------------------------------------------------------------------------- /material/sound/get_bomb.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/sound/get_bomb.mp3 -------------------------------------------------------------------------------- /material/sound/get_bomb.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/sound/get_bomb.wav -------------------------------------------------------------------------------- /material/sound/get_double_laser.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/sound/get_double_laser.mp3 -------------------------------------------------------------------------------- /material/sound/get_double_laser.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/sound/get_double_laser.wav -------------------------------------------------------------------------------- /material/sound/out_porp.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/sound/out_porp.mp3 -------------------------------------------------------------------------------- /material/sound/use_bomb.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/sound/use_bomb.mp3 -------------------------------------------------------------------------------- /material/sound/use_bomb.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/triaquae/jerkoff/fb6c7c30004a1501df455a6320def92401d3af68/material/sound/use_bomb.wav -------------------------------------------------------------------------------- /src/__init__.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # Date: 2017/11/26 4 | 5 | -------------------------------------------------------------------------------- /src/bullet.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | """ 5 | 子弹的实现 6 | """ 7 | 8 | import pygame 9 | 10 | 11 | class Bullet(pygame.sprite.Sprite): 12 | 13 | def __init__(self, position): 14 | super(Bullet, self).__init__() 15 | self.image = pygame.image.load("material/image/bullet1.png") 16 | self.rect = self.image.get_rect() 17 | self.rect.left, self.rect.top = position 18 | self.speed = 30 19 | self.active = True 20 | self.mask = pygame.mask.from_surface(self.image) 21 | 22 | def move(self): 23 | """ 24 | 子弹移动, 超出屏幕范围, 则设置死亡 25 | :return: 26 | """ 27 | if self.rect.top < 0: 28 | self.active = False 29 | else: 30 | self.rect.top -= self.speed 31 | 32 | def reset(self, position): 33 | """ 34 | 复位函数 35 | :param position: 36 | :return: 37 | """ 38 | self.rect.left, self.rect.top = position 39 | self.active = True 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /src/enemy.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | """ 5 | 定义敌机 6 | """ 7 | 8 | from random import randint 9 | 10 | import pygame 11 | 12 | 13 | class SmallEnemy(pygame.sprite.Sprite): 14 | """ 15 | 定义小飞机敌人 16 | """ 17 | energy = 1 18 | 19 | def __init__(self, bg_size): 20 | super(SmallEnemy, self).__init__() 21 | self.image = pygame.image.load("material/image/enemy1.png") 22 | self.rect = self.image.get_rect() 23 | self.width, self.height = bg_size[0], bg_size[1] 24 | self.mask = pygame.mask.from_surface(self.image) # 获取飞机图像的掩膜用以更加精确的碰撞检测 25 | self.speed = 2 26 | self.energy = SmallEnemy.energy 27 | # 定义敌机出现的位置, 保证敌机不会在程序已开始就立即出现 28 | self.rect.left, self.rect.top = ( 29 | randint(0, self.width - self.rect.width), randint(-5 * self.rect.height, -5), 30 | ) 31 | self.active = True 32 | # 加载飞机损毁图片 33 | self.destroy_images = [] 34 | self.destroy_images.extend( 35 | [ 36 | pygame.image.load("material/image/enemy1_down1.png"), 37 | pygame.image.load("material/image/enemy1_down2.png"), 38 | pygame.image.load("material/image/enemy1_down3.png"), 39 | pygame.image.load("material/image/enemy1_down4.png") 40 | ] 41 | ) 42 | 43 | def move(self): 44 | """ 45 | 定义敌机的移动函数 46 | :return: 47 | """ 48 | if self.rect.top < self.height: 49 | self.rect.top += self.speed 50 | else: 51 | self.reset() 52 | 53 | def reset(self): 54 | """ 55 | 当敌机向下移动出屏幕且飞机是需要进行随机出现的, 以及敌机死亡 56 | :return: 57 | """ 58 | self.rect.left, self.rect.top = (randint(0, self.width - self.rect.width), randint(-5 * self.rect.height, 0)) 59 | self.active = True 60 | 61 | 62 | class MidEnemy(pygame.sprite.Sprite): 63 | 64 | def __init__(self): 65 | super(MidEnemy, self).__init__() 66 | self.image = pygame.image.load("material/image/enemy2.png") 67 | 68 | 69 | class BigEnemy(pygame.sprite.Sprite): 70 | 71 | def __init__(self): 72 | super(BigEnemy, self).__init__() 73 | self.image = pygame.image.load("material/image/enemy3.png") 74 | 75 | 76 | -------------------------------------------------------------------------------- /src/plane.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | """ 5 | 创建飞机 6 | 在pygame中, 所有可移动的对象均叫可看作一个精灵(sprite) 7 | 该类并实现了碰撞方法 spritecollide 8 | 9 | 我方飞机和敌方飞机指定掩膜属性以及生存状态标志位 添加 self.mask 属性(可以实现更精准的碰撞效果) 10 | """ 11 | from config.settings import BASE_DIR 12 | 13 | import os 14 | # 倒入精灵模块, 使飞机可以动起来 15 | import pygame 16 | 17 | 18 | class OurPlane(pygame.sprite.Sprite): 19 | 20 | def __init__(self, bg_size): 21 | super(OurPlane, self).__init__() 22 | # 确定我方飞机背景图(有俩张,可以让它们不停的切换,形成动态效果) 23 | self.image_one = pygame.image.load(os.path.join(BASE_DIR, "material/image/hero1.png")) 24 | self.image_two = pygame.image.load(os.path.join(BASE_DIR, "material/image/hero2.png")) 25 | # 获取我方飞机的位置 26 | self.rect = self.image_one.get_rect() 27 | # 本地化背景图片的尺寸 28 | self.width, self.height = bg_size[0], bg_size[1] 29 | # 获取飞机图像的掩膜用以更加精确的碰撞检测 30 | self.mask = pygame.mask.from_surface(self.image_one) 31 | # 定义飞机初始化位置,底部预留60像素 32 | self.rect.left, self.rect.top = (self.width - self.rect.width) // 2, (self.height - self.rect.height - 60) 33 | # 设置飞机移动速度 34 | self.speed = 10 35 | # 设置飞机存活状态(True为存活, False为死亡) 36 | self.active = True 37 | # 加载飞机损毁图片 38 | self.destroy_images = [] 39 | self.destroy_images.extend( 40 | [ 41 | pygame.image.load(os.path.join(BASE_DIR, "material/image/hero_blowup_n1.png")), 42 | pygame.image.load(os.path.join(BASE_DIR, "material/image/hero_blowup_n2.png")), 43 | pygame.image.load(os.path.join(BASE_DIR, "material/image/hero_blowup_n3.png")), 44 | pygame.image.load(os.path.join(BASE_DIR, "material/image/hero_blowup_n4.png")), 45 | ] 46 | ) 47 | 48 | def move_up(self): 49 | """ 50 | 飞机向上移动的操作函数,其余移动函数方法类似 51 | """ 52 | if self.rect.top > 0: # 如果飞机尚未移动出背景区域 53 | self.rect.top -= self.speed 54 | else: # 若即将移动出背景区域,则及时纠正为背景边缘位置 55 | self.rect.top = 0 56 | 57 | def move_down(self): 58 | """ 59 | 飞机向下移动 60 | """ 61 | if self.rect.bottom < self.height - 60: 62 | self.rect.top += self.speed 63 | else: 64 | self.rect.bottom = self.height - 60 65 | 66 | def move_left(self): 67 | """ 68 | 飞机向左移动 69 | """ 70 | if self.rect.left > 0: 71 | self.rect.left -= self.speed 72 | else: 73 | self.rect.left = 0 74 | 75 | def move_right(self): 76 | """ 77 | 飞机向右移动 78 | """ 79 | if self.rect.right < self.width: 80 | self.rect.right += self.speed 81 | else: 82 | self.rect.right = self.width 83 | 84 | def reset(self): 85 | # 初始化飞机(飞机挂了, 初始化到初始位置) 86 | self.rect.left, self.rect.top = (self.width - self.rect.width) // 2, (self.height - self.rect.height - 60) 87 | # 重置飞机的存活状态 88 | self.active = True 89 | 90 | 91 | 92 | --------------------------------------------------------------------------------