car game frontend

 import pygame


pygame.init()

display_width = 800
display_height = 600

black = (0,0,0)
white = (255,255,255)
green = (0,255,0)
red = (255,0,0)
blue = (0,0,255)

Screen = pygame.display.set_mode((display_width,display_height))

pygame.display.set_caption("Car Game")

img = pygame.image.load("fcar.jpg")


def intro():
    intro = True
    menu1_x = 200
    menu1_y = 400
    menu2_x = 500
    menu2_y = 400
    menu_width = 100
    menu_height = 50


    while intro:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()

        Screen.fill(white)
        message_display("CAR RACING",60,380,70)
        Screen.blit(img,(100,100))
        pygame.draw.rect(Screen,green,(200,400,100,50))
        pygame.draw.rect(Screen,red,(500,400,100,50))

        mouse = pygame.mouse.get_pos()
        click = pygame.mouse.get_pressed()

        if menu1_x < mouse[0< menu1_x+menu_width and menu1_y < mouse[1< menu1_y+menu_height:
            pygame.draw.rect(Screen,blue,(200,400,100,50))
            if click[0== 1:
                intro = False
        if menu2_x < mouse[0< menu2_x+menu_width and menu2_y < mouse[1< menu2_y+menu_height:
            pygame.draw.rect(Screen,blue,(500,400,100,50))
            if click[0== 1:
                pygame.quit()
                quit()

        message_display("Start",40,menu1_x+menu_width/2,menu1_y+menu_height/2)
        message_display("Exit",40,menu2_x+menu_width/2,menu2_y+menu_height/2)
        pygame.display.update()

def text_objects(text,font):
    textSurface = font.render(text,True,black)
    return textSurface,textSurface.get_rect()

def message_display(text,size,x,y):
    font = pygame.font.Font("freesansbold.ttf",size)
    text_surface , text_rectangle = text_objects(text,font)
    text_rectangle.center =(x,y)
    Screen.blit(text_surface,text_rectangle)

intro()









Comments

Popular Posts