飞机的基类不应该去设置我方飞机的初始位置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | class Plane(pygame.sprite.Sprite): """ 飞机的基类 """ #飞机的图片 plane_images = [] #飞机爆炸图片 destroy_images = [] #坠毁的音乐地址 down_sound_src = None #飞机的状态:True:活的 False:死的 active = True #该飞机发射的子弹精灵组 bullets = pygame.sprite.Group() def __init__( self ,screen,speed = None ): super ().__init__() self .screen = screen # 加载静态资源 self .img_list = [] self ._destroy_img_list = [] self .down_sound = None self .load_src() # 飞行的速度 self .speed = speed or 10 # 获取飞机的位置 self .rect = self .img_list[ 0 ].get_rect() #屏幕的宽度和高度 self .width, self .height = self .screen.get_size() #飞机的宽度和高度 self .plane_width, self .plane_height = self .img_list[ 0 ].get_size() # 改变飞机的初始化位置 self .rect.bottom = self .height self .rect.left = ( self .width - self .plane_width) / 2 |
老师将改变飞机的初始化位置写在了飞机的基类中,我感觉有点不合适,因为我方飞机和地方飞机的位置不一样,敌方飞机继承这个位置时就不对。
我觉得可以把设置我方飞机的初始位置写在our_plane的构造方法中:
1 2 3 4 5 6 7 8 9 10 11 12 13 | class OurPlane(Plane): """ 我方的飞机 """ #飞机的图片 plane_images = constants.OUR_PLANE_IMG_LIST #飞机爆炸图片 destroy_images = constants.OUR_DESTROY_IMG_LIST #坠毁的音乐地址 down_sound_src = None def __init__( self ,screen): super ().__init__(screen) # 改变飞机的初始化位置 self .rect.bottom = self .height self .rect.left = ( self .width - self .plane_width) / 2 |
2
收起
正在回答 回答被采纳积分+1
1回答
1.Python零基础入门
- 参与学习 人
- 提交作业 2727 份
- 解答问题 8160 个
想要进入Python Web、爬虫、人工智能等高薪领域,你需要掌握本阶段的Python基础知识,课程安排带你高效学习轻松入门,学完你也能听得懂Python工程师的行业梗。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧