derfium derfium - 3 months ago
173 1

No description

Python

p

from pygame.locals import *
import pygame
import eztext

# New Game Screen
def new():
    '''
    This is the Pygame screen for "New Game"
    '''
    # Initiation for Pygame
    pygame.init()

    # GameExit. Pygame runs while GameExit = False
    gameExit = False

    # FPS Clock
    clock = pygame.time.Clock()

    # Load the Background picture
    # TODO Throw away and generate Text with pygame
    background_new = pygame.image.load(r"C:\Users\Marcel\Desktop\_Python\market_raid_v2\data\new_game_back.png")

    # Size of Gamescreen
    game_display = pygame.display.set_mode((800, 600))

    # Location of the "Back Tile"
    exit_tile = pygame.Rect(400, 466, 400, 134)

    # Textbox for Name
    txtbox = eztext.Input(maxlength = 20, color = (0, 0, 0), prompt='')

    # Game Loop
    while not gameExit:
        clock.tick(30)
        events = pygame.event.get()
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                gameExit = True
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    gameExit = True

            #Checks if the Player clicked the "Exit" Button
            if event.type == pygame.MOUSEBUTTONDOWN:
                pos = pygame.mouse.get_pos()
                print (pos)
                if exit_tile.collidepoint(pos):
                    main()
                    print('exit')


        # Displays the Background Picture
        game_display.blit(background_new, [0, 0])

        # Sets the position for the Textbox
        txtbox.set_pos(400,240)

        txtbox.update(events)
        txtbox.draw(game_display)



        pygame.display.update()

    pygame.quit()
    quit()


def load():
    pygame.init()
    gameExit = False

    clock = pygame.time.Clock()

    background_about = pygame.image.load(r"C:\Users\Marcel\Desktop\_Python\market_raid_v2\data\load_back.png")
    game_display = pygame.display.set_mode((800, 600))

    exit_tile = pygame.Rect(400, 466, 400, 134)

    while not gameExit:
        clock.tick(30)
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                gameExit = True
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    gameExit = True
            if event.type == pygame.MOUSEBUTTONDOWN:
                pos = pygame.mouse.get_pos()
                print (pos)
                if exit_tile.collidepoint(pos):
                    main()
                    print('exit')

        game_display.blit(background_about, [0, 0])
        pygame.display.update()

    pygame.quit()
    quit()




#Settingsmenu
def settings():
    '''This is the settings menu in which you will be able to change various settings'''
    # TODO Think about settings


    pygame.init()
    gameExit = False


    clock = pygame.time.Clock()

    # Game Display
    game_display = pygame.display.set_mode((800, 600))

    # Load Background Picture in .png
    background_settings = pygame.image.load(r"C:\Users\Marcel\Desktop\_Python\market_raid_v2\data\settings_back.png")

    # Caption for settings
    pygame.display.set_caption('Market Raid Settings')

    # Tiles to click on
    exit_tile = pygame.Rect(400, 466, 400, 134)

    # Settings Loop
    while not gameExit:
        # Set maximum frames per second to 30
        clock.tick(30)
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                gameExit = True
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    gameExit = True
            if event.type == pygame.MOUSEBUTTONDOWN:
                pos = pygame.mouse.get_pos()
                print (pos)
                if exit_tile.collidepoint(pos):
                    main()
                    print('exit')

        game_display.blit(background_settings, [0, 0])
        pygame.display.update()

    pygame.quit()
    quit()




def about():
    pygame.init()
    gameExit = False

    clock = pygame.time.Clock()

    background_about = pygame.image.load(r"C:\Users\Marcel\Desktop\_Python\market_raid_v2\data\about_back.png")
    game_display = pygame.display.set_mode((800, 600))

    exit_tile = pygame.Rect(400, 466, 400, 134)

    while not gameExit:
        clock.tick(30)
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                gameExit = True
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    gameExit = True
            if event.type == pygame.MOUSEBUTTONDOWN:
                pos = pygame.mouse.get_pos()
                print (pos)
                if exit_tile.collidepoint(pos):
                    main()
                    print('exit')

        game_display.blit(background_about, [0, 0])
        pygame.display.update()

    pygame.quit()
    quit()



# Main menu
def main():
    pygame.init()
    gameExit = False

    clock = pygame.time.Clock()

    background_main = pygame.image.load(r"C:\Users\Marcel\Desktop\_Python\market_raid_v2\data\main_menu_back.png")
    game_display = pygame.display.set_mode((800, 600))


    # Rectangles to clock on
    new_game_tile = pygame.Rect(0, 200, 400, 200)
    load_game_tile = pygame.Rect(0, 400, 400, 200)
    settings_tile = pygame.Rect(400, 200, 400, 133)
    about_tile = pygame.Rect(400, 333, 400, 133)
    exit_tile = pygame.Rect(400, 466, 400, 134)

    pygame.display.set_caption('Market Raid')

    # Main menu Loop
    while not gameExit:
        clock.tick(30)
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                gameExit = True
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    gameExit = True
            if event.type == pygame.MOUSEBUTTONDOWN:
                pos = pygame.mouse.get_pos()
                print (pos)
                if new_game_tile.collidepoint(pos):
                    print('new')
                    new()
                elif load_game_tile.collidepoint(pos):
                    load()
                    print('load')
                elif settings_tile.collidepoint(pos):
                    print('settings')
                    settings()
                elif about_tile.collidepoint(pos):
                    print('about')
                    about()
                elif exit_tile.collidepoint(pos):
                    gameExit = True
                    print('exit')

        game_display.blit(background_main, [0, 0])
        pygame.display.update()


    pygame.quit()
    quit()


main()
Comments