模块“ pygame”没有“ init”成员

时间:2019-05-13 08:11:50

标签: python pygame python-3.6

我遇到有关pygame模块的错误,但不知道为什么会发生。我没有名为pygame的文件/文件夹

检查pygame文件和文件夹

#Initialisation
import pygame
import random
from pygame.locals import *
pygame.init()

root = pygame.display.set_mode((1024,720))
pygame.display.set_caption("Tron Racer!")

clock = pygame.time.Clock()



#Defining Game Menu
#def game_menu():
  #  intro = True
  #  while intro:
   #     for event in pygame.event.get():
   #         if event.type = pygame.QUIT;
   #         pygame.quit()
   #         quit()
  #  gameDisplay.fill(0, 0, 0)
#Defining the intial values of the Bike(s)
class player(object):
    def __init__(self, x, y, width, height):
        self.x = x
        self.y = y
        self.width = width
        self.height = height

        self.vel = 5
        self.lives = 3

class trail(object):
    def __init__(self, x, y, width, height):
        self.x = x
        self.y = y
        self.width = width
        self.height = height
        self.vel = 5

#Drawing for Animation
def draw(root):
    return 

#Game Loop
Bike1 = player(300, 410, 32, 32)
Bike2 = player(200, 310, 32, 32)
BikeTrail1 = trail(Bike1.x, Bike1.y, 12, 12)
run = True
while run:
    pygame.time.delay(100)
    clock.tick(27)

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            run = False

    keys = pygame.key.get_pressed()
#Bike 1 
    events = pygame.event.get()
    for event in events:


        if event.type == pygame.KEYDOWN:
            if event.key == chr('K_a') and Bike1.x > 0:
                    Bike1.x -= Bike1.vel   #Vel to chance ONE value rather than four
                    Bike1.left = True
                    Bike1.right = False

            if event.type == pygame.KEYDOWN:
                if event.key == chr('K_d') and Bike1.x < 1024 - Bike1.width:
                    Bike1.x += Bike1.vel
                    Bike1.left = False
                    Bike1.right = True

            if event.type == pygame.KEYDOWN:
                if event.key == chr('K_w') and Bike1.y > 0 + Bike1.height - Bike1.vel:
                    Bike1.y -= Bike1.vel

            if event.type == pygame.KEYDOWN:
                if event.key == chr('K_s') and Bike1.x < 0 :
                    Bike1.y += Bike1.vel


#Bike 2
    event = pygame.event.get()
    for event in events:
            if event.type == pygame.KEYDOWN:
                if event.key == chr('K_LEFT')and Bike1.x > 0:
                    Bike1.x -= Bike1.vel   #Vel to chance ONE value rather than four
                    Bike1.left = True
                    Bike1.right = False

            if event.type == pygame.KEYDOWN:
                if event.key == chr('K_RIGHT') and Bike1.x < 1024 - Bike1.width:
                    Bike1.x += Bike1.vel
                    Bike1.left = False
                    Bike1.right = True

            if event.type == pygame.KEYDOWN:
                if event.key == chr('K_UP') and Bike1.y > 0 + Bike1.height - Bike1.vel:
                    Bike1.y -= Bike1.vel

            if event.type == pygame.KEYDOWN:
                if event.key == chr('K_DOWN') and Bike1.y > 0 + Bike1.height - Bike1.vel:
                    Bike1.y += Bike1.vel
#----------------------------------------------------------------------


#Draws // Updates the game
#game_menu()
root.fill((0, 0, 0))
pygame.draw.rect(root, (255, 0, 0), (Bike1.x, Bike1.y, Bike1.width, Bike1.height))
pygame.draw.rect(root, (0, 255, 0), (Bike2.x, Bike2.y, Bike2.width, Bike2.height))
pygame.display.update()

pygame.quit()

错误

https://cdn.discordapp.com/attachments/336426882088042502/577406886446497792/123123123.PNG

游戏应该可以正常运行。

对不起,我的英语水平不是最好的。

谢谢

0 个答案:

没有答案