蓝大伟 发表于 2020-8-24 19:37:38

帮看一下飞机大战代码什么问题

import pygame
from sprites1 import *

pygame.init()

screen = pygame.display.set_mode((480,700))

bg = pygame.image.load("./images/background.png")

screen.blit(bg,(0,0))
#pygame.display.update()

f = pygame.image.load("./images/me1.png")
screen.blit(f, (200, 500))
pygame.display.update()

clock = pygame.time.Clock()
hero_rect = pygame.Rect(150,300,102,126)
enemy = GameSprite("./images/enemy2.png")
enemy1 = GameSprite("./images/enemy2.png",2)
enemy_group = pygame.sprite.Group(enemy)
while True:
    clock.tick(30)
    for event in pygame.event.get():
      if event.type == pygame.QUIT:
            print("游戏结束。。。")
            pygame.quit()
            exit()

    hero_rect.y -= 5
    if hero_rect.y <= -100:
      hero_rect.y = 700
    screen.blit(bg,(0,0))
    screen.blit(f,hero_rect)
    enemy_group.update
    enemy_group.draw(screen)
    pygame.display.update()








libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
Traceback (most recent call last):
File "C:/Users/tlan2/Desktop/真·飞机大战/01.py", line 19, in <module>
    enemy = GameSprite("./images/enemy2.png")
File "C:\Users\tlan2\Desktop\真·飞机大战\venv\sprites1.py", line 7, in __init__
    self.rect = relf.image.get_rect()
NameError: name 'relf' is not defined

Hoiste 发表于 2020-8-24 19:51:10

先把报错的信息提到的对应位置的relf改成self,再看有无报错。
页: [1]
查看完整版本: 帮看一下飞机大战代码什么问题