|
|
@ -115,7 +115,52 @@ class Bullet(object):
|
|
|
|
# 速度
|
|
|
|
# 速度
|
|
|
|
self.speed = 20
|
|
|
|
self.speed = 20
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def display(self):
|
|
|
|
|
|
|
|
"""显示子弹到窗口"""
|
|
|
|
|
|
|
|
self.screen.blit(self.image, (self.x, self.y))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def auto_move(self):
|
|
|
|
|
|
|
|
"""让子弹飞 修改子弹y坐标"""
|
|
|
|
|
|
|
|
self.y -= self.speed
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 敌方子弹类
|
|
|
|
|
|
|
|
# 属性
|
|
|
|
|
|
|
|
class EnemyBullet(object):
|
|
|
|
|
|
|
|
def __init__(self, screen, x, y):
|
|
|
|
|
|
|
|
# 坐标
|
|
|
|
|
|
|
|
self.x = x + 50 / 2 - 8 / 2
|
|
|
|
|
|
|
|
self.y = y + 39
|
|
|
|
|
|
|
|
# 图片
|
|
|
|
|
|
|
|
self.image = pygame.image.load('./feiji/bullet1.png')
|
|
|
|
|
|
|
|
# 窗口
|
|
|
|
|
|
|
|
self.screen = screen
|
|
|
|
|
|
|
|
# 速度
|
|
|
|
|
|
|
|
self.speed = 20
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def display(self):
|
|
|
|
|
|
|
|
"""显示子弹到窗口"""
|
|
|
|
|
|
|
|
self.screen.blit(self.image, (self.x, self.y))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def auto_move(self):
|
|
|
|
|
|
|
|
"""让子弹飞 修改子弹y坐标"""
|
|
|
|
|
|
|
|
self.y += self.speed
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class GameSound(object):
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
|
|
|
|
pygame.mixer.init() # 音乐模块初始化
|
|
|
|
|
|
|
|
pygame.mixer.music.load('./feiji/bg2.ogg')
|
|
|
|
|
|
|
|
pygame.mixer.music.set_volume(0.5) # 声音大小
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def playBackgroundMusic(self):
|
|
|
|
|
|
|
|
pygame.mixer.music.play(-1) # 开始播放音乐
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
def main():
|
|
|
|
|
|
|
|
"""完成整个程序的控制"""
|
|
|
|
|
|
|
|
sound = GameSound()
|
|
|
|
|
|
|
|
sound.playBackgroundMusic()
|
|
|
|
|
|
|
|
|
|
|
|
# 1. 创建一个窗口,用来显示内容
|
|
|
|
# 1. 创建一个窗口,用来显示内容
|
|
|
|
screen = pygame.display.set_mode((480, 852), 0, 32)
|
|
|
|
screen = pygame.display.set_mode((480, 852), 0, 32)
|
|
|
|