老师报错了,下面上传两个文件的代码

老师报错了,下面上传两个文件的代码

这个是main的代码

import sys
import pygame

from contants import BG_MUSIC, BG_IMG, IMG_GAME_TITLE, IMG_GAME_START_BTN
from game.plane import Plane, OurPlane


def main():
   """游戏入口,main方法"""
   #初始化
   pygame.init()

   width,height =480,852
   #屏幕对象
   screen = pygame.display.set_mode((width,height))
   #设置窗口标题
   pygame.display.set_caption("飞机大战")
   #加载背景图片
   bg = pygame.image.load(BG_IMG)
   bg_rect = bg.get_rect
   #游戏的标题
   img_game_title = pygame.image.load(IMG_GAME_TITLE)
   img_game_title_rect = img_game_title.get_rect()
   #游戏标题的宽度和高度
   t_width,t_height = img_game_title.get_size()
   #print(t_width,t_height)
   img_game_title_rect.topleft =(int((width-t_width)/2),int(height/2-t_height))
   #print(img_game_title_rect.topleft)
   #开始按钮
   btn_start = pygame.image.load(IMG_GAME_START_BTN)
   btn_start_rect = btn_start.get_rect()
   btn_width,btn_height = btn_start.get_size()
   btn_start_rect.topleft = (int((width-btn_width)/2),int(height/2+btn_height))
   #加载音乐
   pygame.mixer.music.load(BG_MUSIC)
   pygame.mixer.music.play(-1)#无限循环播放
   pygame.mixer.music.set_volume(0.2)#设置音量大小

   status = 0 #0准备中,1游戏中,2游戏结束

   our_plane = OurPlane(screen)

   while True:
       #1 监听事件
       for event in pygame.event.get():
           #退出游戏
           if event.type == pygame.QUIT:
               pygame.quit()
               sys.exit()
           elif event.type == pygame.MOUSEBUTTONDOWN:
               #鼠标点击进入游戏
               #游戏正在准备中,点击才能进入游戏
               if status ==0:
                   status == 1
       #更新游戏的状态
       if status == 0:
           #游戏准备中
           #绘制背景
           screen.blit(bg, bg.get_rect())
           #标题
           screen.blit(img_game_title,img_game_title_rect)
           #开始按钮
           screen.blit(btn_start,btn_start_rect)
       elif status == 1:
           #游戏进行中
           #绘制背景
           screen.blit(bg,bg_rect)
           #绘制飞机
           our_plane.blit_me()

       pygame.display.flip()

if __name__ == '__main__':
   main()

这个是plane文件的代码:

"""
飞机的基类
   我方的飞机 敌方的小型飞机 敌方的中型飞机 敌方的大型飞机
"""
import pygame
import contants

class Plane(pygame.sprite.Sprite):
   """飞机的基础类"""
   #飞机的图片
   plane_image = []
   #飞机爆炸的图片
   destory_image = []
   #坠毁的音乐地址
   down_sound_src = None
   #飞机的状态: True,活的,False,死的
   active = True
   #该飞机发射的子弹精灵组
   bullets = pygame.sprite.Group()

   def __int__(self,screen,speed = None):
       super.__init__()
       self.screen = screen
       #加载的静态资源
       self.image_list = []
       self.destory_image_list = []
       self.down_sound = None
       self.load_src()
       #飞行的速度
       self.speed = speed or 10
       #获取飞机的位置
       self.rect = self.image_list[0].get_rect()


   def load_src(self):
       """加载静态资源"""
       for img in self.plane_image:
           self.image_list.append(pygame.image.load(img))
       #飞机坠毁的图片
       for img in self.destory_image:
           self.destory_image_list.append(pygame.image.load(img))
       #坠毁的音乐
       if self.down_sound_src:
           self.down_sound = pygame.mixer.Sound(self.down_sound_src)
   @property
   def image(self):
       return  self.image_list[0]

   def blit_me(self):
       self.screen.blit(self.image,self.rect)

   def move_up(self):
       """飞机向上移动"""
       self.rect.top -= self.speed

   def move_down(self):
       """ 飞机向下移动 """
       self.rect.top += self.speed

   def move_left(self):
       """ 飞机向左移动 """
       self.rect.left -= self.speed

   def move_right(self):
       """ 飞机向右移动 """
       self.rect.left += self.speed

   def broken_down(self):
       """飞机坠毁效果"""
       #1.播放坠毁音乐
       if self.down_sound:
           self.down_sound.play()
       #2.播放坠毁动画
       for img in self.destory_image_list:
           self.screen.blit(img,self.rect)
       #3.坠毁后···
       self.active = False

class OurPlane(Plane):
   """我方的飞机"""
   #飞机的图片
   plane_imges =contants.OUR_PLANE_IMG_LIST
   #飞机爆炸的图片
   destory_images = contants.OUR_DESTROY_IMG_LIST
   #坠毁的音乐地址
   down_sound_src = None

然后报错

D:\untitled\venv\Scripts\python.exe D:/untitled1/cheapter12/main.py

pygame 1.9.6

Hello from the pygame community. https://www.pygame.org/contribute.html

Traceback (most recent call last):

  File "D:/untitled1/cheapter12/main.py", line 74, in <module>

    main()

  File "D:/untitled1/cheapter12/main.py", line 41, in main

    our_plane = OurPlane(screen)

  File "D:\untitled\venv\lib\site-packages\pygame\sprite.py", line 124, in __init__

    self.add(*groups)

  File "D:\untitled\venv\lib\site-packages\pygame\sprite.py", line 142, in add

    self.add(*group)

TypeError: add() argument after * must be an iterable, not pygame.Surface


Process finished with exit code 1



正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

1回答
好帮手慕笑蓉 2020-06-09 17:57:05

同学,你好。导致此错误的代码需要做如下修改:

http://img1.sycdn.imooc.com//climg/5edf5cc109e62de005630153.jpg

此外,还有一处需要修改:

http://img1.sycdn.imooc.com//climg/5edf5ce9090c43c706280181.jpg

如果解决了你的疑惑,请采纳,祝学习愉快~ 

  • 提问者 Buck_messic #1
    按照老师的知道改正后,依然有如下情况报错,为什么会有124,142行的错误呢? D:\untitled\venv\Scripts\python.exe D:/untitled1/cheapter12/main.py pygame 1.9.6 Hello from the pygame community. https://www.pygame.org/contribute.html Traceback (most recent call last): File "D:/untitled1/cheapter12/main.py", line 82, in <module> main() File "D:/untitled1/cheapter12/main.py", line 41, in main our_plane = OurPlane(screen) File "D:\untitled\venv\lib\site-packages\pygame\sprite.py", line 124, in __init__ self.add(*groups) File "D:\untitled\venv\lib\site-packages\pygame\sprite.py", line 142, in add self.add(*group) TypeError: add() argument after * must be an iterable, not pygame.Surface Process finished with exit code 1
    2020-06-09 18:18:11
  • 好帮手慕笑蓉 回复 提问者 Buck_messic #2
    同学,你好。出现124,142行报错是因为触发了的其他内部调用错误。修改后的报错信息没有改变,可将修改后的代码粘贴到问答区,方便老师快速定位问题原因。 祝学习愉快~
    2020-06-09 18:35:30
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
1.Python零基础入门
  • 参与学习           人
  • 提交作业       2727    份
  • 解答问题       8160    个

想要进入Python Web、爬虫、人工智能等高薪领域,你需要掌握本阶段的Python基础知识,课程安排带你高效学习轻松入门,学完你也能听得懂Python工程师的行业梗。

了解课程
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师