library not initialized pygame

Quentin Bock qberz2005 at gmail.com
Tue May 4 10:45:29 EDT 2021


code:
#imports and variable for loop
import pygame
running = True

#initializes pygame
pygame.init()
pygame.mixer.init()
pygame.font.init()

#creates the pygame window
screen = pygame.display.set_mode((1200, 800))

#Title and Icon of window
pygame.display.set_caption("3.02 Project")
icon = pygame.image.load('3.02 icon.png')
pygame.display.set_icon(icon)

#setting up font
pygame.font.init()
font = pygame.font.Font('C:\Windows\Fonts\OCRAEXT.ttf', 16)
font_x = 10
font_y = 40
items_picked_up = 0
items_left = 3

def main():
    global running, event

    #Game Loop
    while running:
        #sets screen color to black
        screen.fill((0, 0, 0))

        #checks if the user exits the window
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False
                pygame.quit()

        def music():
            pygame.mixer.init()
            pygame.font.init()
            pygame.mixer.music.load('onoken - load.mp3')  #places song into
queue
            pygame.mixer.music.play(10, 0, 3)  #fist number indicates the
loop amount, second is the offset of the song, third is fading the song in
            song_text = font.render("Song: onoken - load", True, (255, 255,
255))
            screen.blit(song_text, (10, 750))
        music()

        def display_instruction(x, y):
            pygame.font.init()
            pygame.mixer.init()
            instructions = font.render("Each level contains 3 items you
must pick up in each room.", True, (255, 255, 255))
            instructions_2 = font.render("When you have picked up 3 items,
you will advance to the next room, there are 3.", True, (255, 255, 255))
            instructions_3 = font.render("You will be able to change the
direction you are looking in the room, this allows you to find different
objects.", True, (255, 255, 255))

            screen.blit(instructions, (10, 40))
            screen.blit(instructions_2, (10, 60))
            screen.blit(instructions_3, (10, 80))

        display_instruction(font_x, font_y)
        pygame.display.update()

main()

if you try to run this, I'm aware that the icon and music file will not
load because you don't have the file on your device, but if it somehow
works for you please let me know, and if you think there's any difference
between my code and when you ran it I need this figured out. Thanks


More information about the Python-list mailing list