mian.py里的our_plane = Ourplane(screen)相当于加载图片pygame.image.load?
# 具体遇到的问题
画图之前都是加载图片吧,our_plane = Ourplane(screen)是怎样加载图片的?
# 报错信息的截图
# 相关课程内容截图
# 尝试过的解决思路和结果
# 粘贴全部相关代码,切记添加代码注释(请勿截图)
pygame, sys constants game.plane Ourplane main(): pygame.init() size = width, height = , screen = pygame.display.set_mode(size) bg = pygame.image.load(constants.BG_IMG) img_game_title = pygame.image.load(constants.IMG_GAME_TITLE) img_game_title_rect = img_game_title.get_rect() t_width, t_height = img_game_title.get_size() img_game_title_rect.topleft = (((width - t_width) / ), (height/- t_height)) btn_start = pygame.image.load(constants.IMG_GAME_START_BTN) btn_start_rect = btn_start.get_rect() btn_width, btn_height = btn_start.get_size() btn_start_rect.topleft = (((width - btn_width) / ), (height/+ btn_height)) our_plane = Ourplane(screen)pygame constants Plane(pygame.sprite.Sprite): plane_images = [] destory_images = [] down_sound_src = active = bullets = pygame.sprite.Group() (, screen, speed = ): ().() .img_list = [] ._destory_img_list = [] .down_sound = .screen = screen .load_src() .speed = speed .rect = .img_list[].get_rect() .width, .height = .screen.get_size() .plane_w, .plane_h = .img_list[].get_size() load_src(): img .plane_images: .img_list.append(pygame.image.load(img)) img .destory_images: ._destory_img_list.append(pygame.image.load(img)) .down_sound_src: pygame.mixer.sound(.down_sound_src) image(): .img_list[] blit_me(): .screen.blit(.image, .image.get_rect()) move_up(): .rect.top -= .speed .rect.top <= : .rect.top = move_down(): .rect.top += .speed .rect.top>= .height - .plane_h: .rect.top = .height - .plane_h move_left(): .rect.left -= .speed .rect.left <= : .rect.left = move_right(): .rect.left += .speed .rect.left >= .width -.plane_w: .rect.left = .width -.plane_w broken_down(): .down_sound: .down_sound.play() img ._destory_img_list: .screen.blit(img, .rect) .actvie = Ourplane(Plane): plane_images = constants.IMG_OUR_PLANE destory_images = constants.OUR_DESTORY_IMG_LIST down_sound_src = update(, frame): frame % == : .screen.blit(.img_list[], .rect) : .screen.blit(.img_list[], .rect)在这里输入代码,可通过选择【代码语言】突出显示
21
收起
正在回答
2回答
同学,你好,不加载飞机图片是画不了飞机的,在Plane()飞机类中定义了load_src()方法加载飞机图片,在__init__()方法中调用该方法加载静态资源
同学可以重新看下当前小节的8分钟之后的视频,有详细的讲解。
1.Python零基础入门
- 参与学习 人
- 提交作业 2727 份
- 解答问题 8160 个
想要进入Python Web、爬虫、人工智能等高薪领域,你需要掌握本阶段的Python基础知识,课程安排带你高效学习轻松入门,学完你也能听得懂Python工程师的行业梗。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星