# Это просто импортирует все модули Pygame import pygame pygame.init () класс Game (object): def main (self, screen):
ько добавил немного музыки в свою игру-пигмею, но я думаю, что код настолько грязный, что ничего не находится в нужном месте. В результате этого добавления я теперь получаю эту ошибку:
Трассировка (последний вызов был последним): файл «C: \ Users \ 1234 \ AppData \ Local \ Programs \ Python \ Python36-32 \ My First game ERROR.py», строка 31, для события в pygame.event.get ( ): pygame.error: видеосистема не инициализирована
Вот код, который я написал:
import pygame, sys
pygame.mixer.init(44100, -16,2,2048)
class Game(object):
def main(self, screen):
import time
pygame.mixer.music.load('The Tonight Show Star Wars The Bee Gees Stayin Alive Shortened.mp3')
pygame.mixer.music.play(-1, 0.0)
#class Player(pygame.sprite.Sprite):
# def __init__(self, *groups):
# super(Player, self.__init__(*groups)
#self.image = pygame.image.load('Sprite-01.png')
# self.rect = pygame.rect.Rect((320, 240), self.image.get_size())
#def update(self):
# key = pygame
image = pygame.image.load('Sprite-01.png')
clock = pygame.time.Clock()
# initialize variables
image_x = 0
image_y = 0
while 1:
clock.tick(30)
for event in pygame.event.get():
if event.type == pygame.quit():
pygame.quit()
if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
pygame.quit()
image_x += 0
key = pygame.key.get_pressed()
if key[pygame.K_LEFT]:
image_x -= 10
if key[pygame.K_RIGHT]:
image_x += 10
if key[pygame.K_UP]:
image_y -= 10
if key[pygame.K_DOWN]:
image_y += 10
screen.fill((200, 200, 200))
screen.blit(image, (image_x, image_y))
pygame.display.flip()
pygame.mixer.music.stop(52)
if __name__ == '__main__':
pygame.init()
screen = pygame.display.set_mode((640, 480))
pygame.display.set_caption('St.Patrick game')
Game().main(screen)