文章目录
雷霆战机大家都玩过吧,就这种的
- 一、准备工作
- 二、代码展示
- 三、效果展示



使用的软件版本:
- Python3.6
- pycharm2019 专业版
你们用其它的也可以,没有软件的话我放在最后面了
这两个模块安装一下
- pygame
- random
安装模块如果不会的话,看我以前发的文章:如何安装python模块, python模块安装失败的原因以及解决办法
我们要准备这些东西 1、字体文件
2、背景音乐文件
3、背景图片
可以自己设计,自己准备,名字改成一样的就好了。 当然,你也可以改成其他名字,但是代码里的名字你也得改,就挺麻烦的。
但是我呢也给大家都准备好了,直接保存就好了↓↓↓
Python
/pycharm
安装包及安装教程、源代码及要用的文件
网盘提取码:qwer
算了我直接放代码吧,有点长,你们肯定坚持不下去看,我都放注释里去讲,这样你们才看的下去。
#导入模块
import pygame, os
import time
import random
from pygame.sprite import Sprite
from pygame.sprite import Group
def fire_music():
pass
# 设置开火音乐
# effect = pygame.mixer.Sound('sounds/fire.wav')
# pygame.mixer.Sound.play(effect)
class Boss(Sprite):
def __init__(self,boss_img_name):
super().__init__()
# 加载BOSS图片
self.image = pygame.image.load('图片/'+boss_img_name+'.png').convert_alpha()
# 转换BOSS大小
# self.image = pygame.transform.scale(self.image, (1, 12))
# 生成BOSS矩形框架
self.rect = self.image.get_rect()
self.blood = 1000
# boss左右移动的速度
self.speed = 3.5
def move(self):
if self.rect.centerx>=512:
self.speed =-self.speed
if self.rect.centerx 200:
self.shoot_frequency = 1
# 删除子弹
def moveBullet(self):
for bullet in self.bullets:
bullet.move()
if bullet.rect.bottom = 768:
pos_y2 = 0
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
# 监听键盘事件
# 按键弹起取消飞机向上尾焰 矫正飞机姿势
if event.type == pygame.KEYUP:
student_plane.set_image('down')
student_plane.air = None
# 发射子弹
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE and len(student_plane.bullets) =40:
student_plane.rect.centerx -=8.5
elif keys[pygame.K_d]:
# 设置飞机状态图片
student_plane.set_image('right')
if student_plane.rect.centerx = 45:
student_plane.rect.centery -=8.5
elif keys[pygame.K_s]:
# 设置飞机状态图片
student_plane.set_image('down')
if student_plane.rect.centery 768:
enemy_bullets.remove(enemy_bullet)
# -----------------------Boss --------------------------
if score >=140:
# 小敌机出现的节奏
ran1,ran2 = 15,25
max_enemies = 17
screen.blit(boss.image,boss.rect)
boss.move()
for my_bullet in student_plane.bullets:
hit_boss = pygame.sprite.collide_rect(boss,my_bullet)
if hit_boss:
boss.blood -=1.2
score+=1
if boss.blood
关注
打赏
最近更新
- 深拷贝和浅拷贝的区别(重点)
- 【Vue】走进Vue框架世界
- 【云服务器】项目部署—搭建网站—vue电商后台管理系统
- 【React介绍】 一文带你深入React
- 【React】React组件实例的三大属性之state,props,refs(你学废了吗)
- 【脚手架VueCLI】从零开始,创建一个VUE项目
- 【React】深入理解React组件生命周期----图文详解(含代码)
- 【React】DOM的Diffing算法是什么?以及DOM中key的作用----经典面试题
- 【React】1_使用React脚手架创建项目步骤--------详解(含项目结构说明)
- 【React】2_如何使用react脚手架写一个简单的页面?