0
import pygame, os
from pygame.locals import *

# Game Initialization
pygame.init()

# Center the Game Application
os.environ['SDL_VIDEO_CENTERED'] = '1'

# Game Resolution
screen=pygame.display.set_mode((0,0),pygame.FULLSCREEN)
X=screen.get_width()
Y=screen.get_height()

# Text Renderer
def text_format(message, textFont, textSize, textColor):
    newFont=pygame.font.Font(textFont, textSize)
    newText=newFont.render(message, 0, textColor)

    return newText


# Colors
red=(255, 0, 0)
black=(0, 0, 0)
gray=(50, 50, 50)
blue=(0, 0, 255)
white=(255, 255, 255)

# Game Fonts
font = "NFS_by_JLTV.ttf"


# Game Framerate
clock = pygame.time.Clock()
FPS=60


# create the display surface object
# of specific dimension..e(X, Y).
display_surface = screen

# set the pygame window name
pygame.display.set_caption('Controls')

# create a font object.
# 1st parameter is the font file
# which is present in pygame.
# 2nd parameter is size of the font
font = pygame.font.Font('NFS_by_JLTV.ttf', 32)

# create a text surface object,
# on which text is drawn on it.
text = font.render("""This is the information about the game. """ , True, white)
text = font.render("""To play this game you need to use the left and right arrow keys. """  , 
True, white)
text = font.render("""Left to move the car left and right to move the car right. """  , True, 
white)
text = font.render("""You may also choose to change the car you are driving if you unlock any 
other cars when playing the game """ , True, white)

# create a rectangular object for the
# text surface object
textRect = text.get_rect()

# set the center of the rectangular object.
textRect.center = (X // 2, Y // 2)

# infinite loop
while True:

    # completely fill the surface object
    # with white color
    display_surface.fill(black)

    # copying the text surface object
    # to the display surface object
    # at the center coordinate.
    display_surface.blit(text, textRect)

    # iterate over the list of Event objects
    # that was returned by pygame.event.get() method.
    for event in pygame.event.get():

        # if event object type is QUIT
        # then quitting the pygame
        # and program both.
        if event.type == pygame.QUIT:

            # deactivates the pygame library
                pygame.quit()

            # quit the program.
            quit()

        # Draws the surface object to the screen.
        pygame.display.update()

This code is to show information about a game I have made. Why is the text information not showing as a paragraph either on the top left or middle? Also, how would I allow the user to redirect themselves to the main menu of my game? Would I just link the main menu to this code and make it be able to go back with the back key or what?

0 Answers0