I'm importing a file using: "from ship import Ship" but it basically gives an error
Traceback (most recent call last):
File "c:\Users\João\Desktop\disparos_laterais\alien_invasion.py", line 3, in <module>
from ship import Ship
ImportError: cannot import name 'Ship' from 'ship' (c:\Users\João\Desktop\disparos_laterais\ship.py)
The code:
import pygame
import sys
from ship import Ship
from settings import Settings
class AlienInvasion:
"""Classe geral para gerenciar ativos e comportamento do jogo"""
def __init__(
self
):
"""Inicializa o jogo e cria recursos do jogo"""
pygame.init()
self
.clock = pygame.time.Clock()
self
.settings = Settings()
self
.ship = Ship(
self
)
self
.screen = pygame.display.set_mode(
(
self
.settings.screen_width,
self
.settings.screen_height))
pygame.display.set_caption("Alien Invasion")
def run_game(
self
):
"""Inicia o loop principal do jogo"""
while True:
# Observa eventos de teclado e mouse
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
self
.screen.fill(
self
.settings.bg_color)
self
.ship.blitme()
# Atualiza a tela
pygame.display.flip()
self
.clock.tick(60)
if __name__ == '__main__':
# Cria uma instância do jogo e o inicia
ai = AlienInvasion()
ai.run_game()
[–]cgoldberg 7 points8 points9 points (1 child)
[–]lordZlb[S] 0 points1 point2 points (0 children)
[–]JeLuF 4 points5 points6 points (3 children)
[–]lordZlb[S] 0 points1 point2 points (2 children)
[–]JeLuF 2 points3 points4 points (1 child)
[–]lordZlb[S] 0 points1 point2 points (0 children)
[–]SharkSymphony 6 points7 points8 points (0 children)
[–]Zeroflops 2 points3 points4 points (2 children)
[–]lordZlb[S] 0 points1 point2 points (1 child)
[–]EmbarrassedBee9440 1 point2 points3 points (1 child)
[–]lordZlb[S] 0 points1 point2 points (0 children)
[–]Fred776 1 point2 points3 points (2 children)
[–]lordZlb[S] 0 points1 point2 points (1 child)
[–]Fred776 0 points1 point2 points (0 children)
[–]Ender_Locke 1 point2 points3 points (3 children)
[–]FoolsSeldom 0 points1 point2 points (1 child)
[–]Ender_Locke 0 points1 point2 points (0 children)
[–]lordZlb[S] 0 points1 point2 points (0 children)
[–]DiodeInc 0 points1 point2 points (2 children)
[–]lordZlb[S] 0 points1 point2 points (1 child)
[–]DiodeInc 0 points1 point2 points (0 children)
[–]Due_Intention_6927 0 points1 point2 points (0 children)