Ejemplo n.º 1
0
def launch():
    
    # Initialize pygame
    pygame.init()
    # Initialize the pygame font module
    pygame.font.init()
    
    # Set the width and height of the window
    width, height = int(pygame.display.Info().current_w), int(pygame.display.Info().current_h)
    # Create the window
    screen = pygame.display.set_mode((width, height), pygame.HWSURFACE | pygame.DOUBLEBUF)
    # Set title
    pygame.display.set_caption("Galaxy Wars")
    
    # Initialize the joystick module
    pygame.joystick.init()
    # Check if there are any joysticks
    joystick_count = pygame.joystick.get_count()
    # If there are any joysticks, initialize the first one, else quit the joystick module
    if joystick_count:
        joystick = pygame.joystick.Joystick(0)
        joystick.init()
        JS = True
    else:
        pygame.joystick.quit()
        JS = False
    
    # Set choice
    choice = 1
    Schoice = 1
    MorS = "main"
    # Set 1/12 height
    height12 = height/12
    
    # Load images
    # Load the background image
    bgmain = pygame.image.load("resources/images/bgmain.jpg")
    bgmain = pygame.transform.scale(bgmain, (width, height))
    # Set display mode
    prevFS = settings.getFullscreen()
    if settings.getFullscreen() == True:
        screen = pygame.display.set_mode((width, height), pygame.HWSURFACE | pygame.DOUBLEBUF | pygame.FULLSCREEN)
    elif settings.getFullscreen() == False:
        screen = pygame.display.set_mode((width, height), pygame.HWSURFACE | pygame.DOUBLEBUF)

    
    # Keep looping through
    while True:
        # Set display mode if changed
        if prevFS != settings.getFullscreen():
            if settings.getFullscreen() == True:
                screen = pygame.display.set_mode((width, height), pygame.HWSURFACE | pygame.DOUBLEBUF | pygame.FULLSCREEN)
                prevFS = settings.getFullscreen()
            elif settings.getFullscreen() == False:
                screen = pygame.display.set_mode((width, height), pygame.HWSURFACE | pygame.DOUBLEBUF)
                prevFS = settings.getFullscreen()

        # Set joystick buttons, if there are any
        if JS:
            buttonUP = joystick.get_button(4)
            buttonDOWN = joystick.get_button(6)
            buttonX = joystick.get_button(14)
        # Clear the screen before drawing it again
        screen.fill(0)
        # Draw the background
        screen.blit(bgmain, (0,0))
        # Loop through the events
        for event in pygame.event.get():
            # Check if the event is the X button 
            if event.type == pygame.QUIT:
                # If it is quit the game
                pygame.quit()
                sys.exit()
            # Check if a key is pressed
            elif event.type == pygame.KEYDOWN:
                # Check if arrow down is pressed
                if event.key == K_DOWN:
                    if MorS == "main":
                        if choice == 1:
                            choice = 2
                        elif choice == 2:
                            choice = 3
                        elif choice == 3:
                            choice = 1
                    elif MorS == "settings":
                        if Schoice == 1:
                            Schoice = 2
                        elif Schoice == 2:
                            Schoice = 1
                # Check if arrow up is pressed
                elif event.key == K_UP:
                    if MorS == "main":
                        if choice == 1:
                            choice = 3
                        elif choice == 2:
                            choice = 1
                        elif choice == 3:
                            choice = 2
                    elif MorS == "settings":
                        if Schoice == 1:
                            Schoice = 2
                        elif Schoice == 2:
                            Schoice = 1
                # Check if return is pressed
                elif event.key == K_RETURN:
                    if MorS == "main":
                        if choice == 1:
                            singleplayer.play()
                        elif choice == 2:
                            MorS = "settings"
                        elif choice == 3:
                            pygame.quit()
                            sys.exit()
                    elif MorS == "settings":
                        if Schoice == 1:
                            settings.changeFullscreen()
                        elif Schoice == 2:
                            MorS = "main"
                # Quit by pressing escape
                elif event.key == K_ESCAPE:
                    pygame.quit()
                    sys.exit()
                # Fullscreen by pressing F4
                elif event.key == K_F4:
                    settings.changeFullscreen()
            # Check if there are any joysticks
            if JS:
                # Check if UP is pressed
                if buttonUP:
                    if choice == 1:
                        choice = 3
                    elif choice == 2:
                        choice = 1
                    elif choice == 3:
                        choice = 2
                # Check if DOWN is pressed
                elif buttonDOWN:
                    if choice == 1:
                        choice = 2
                    elif choice == 2:
                        choice = 3
                    elif choice == 3:
                        choice = 1
                # Check if X is pressed
                elif buttonX:
                    if choice == 1:
                        singleplayer.play()
                    elif choice == 2:
                        MorS = "settings"
                    elif choice == 3:
                        pygame.quit()
                        sys.exit()
    
        # Set font
        font = pygame.font.Font("freesansbold.ttf", 24)
        bigfont = pygame.font.Font("freesansbold.ttf", 48)
    
        if MorS == "main":
            # Check for cursor
            if choice == 1:
                spText = "-- Single Player --"
                stText = "Settings"
                xtText = "Exit"
            elif choice == 2:
                spText = "Single Player"
                stText = "-- Settings --"
                xtText = "Exit"
            elif choice == 3:
                spText = "Single Player"
                stText = "Settings"
                xtText = "-- Exit --"
    
            # Render text
            # Render title text
            title = bigfont.render("Galaxy Wars", True, (255,255,255))
            titleRect = title.get_rect()
            titleRect.centerx = screen.get_rect().centerx
            titleRect.centery = height12*2
            # Render single player text
            sp = font.render(spText, True, (255,255,255))
            spRect = sp.get_rect()
            spRect.centerx = screen.get_rect().centerx
            spRect.centery = height12*5
            # Render settings text
            st = font.render(stText, True, (255,255,255))
            stRect = st.get_rect()
            stRect.centerx = screen.get_rect().centerx
            stRect.centery = height12*6
            # Render exit text
            xt = font.render(xtText, True, (255,255,255))
            xtRect = xt.get_rect()
            xtRect.centerx = screen.get_rect().centerx
            xtRect.centery = height12*7
    
            # Draw text
            screen.blit(title, titleRect)
            screen.blit(sp, spRect)
            screen.blit(st, stRect)
            screen.blit(xt, xtRect)

        elif MorS == "settings":
            # Check for cursor
            if Schoice == 1:
                fsText = "-- Fullscreen: " + str(settings.getFullscreen()) + " --"
                bcText = "Back"
            elif Schoice == 2:
                fsText = "Fullscreen: " + str(settings.getFullscreen())
                bcText = "-- Back --"

            # Render text
            # Render title text
            title = bigfont.render("Galaxy Wars", True, (255,255,255))
            titleRect = title.get_rect()
            titleRect.centerx = screen.get_rect().centerx
            titleRect.centery = height12*2
            # Render fullscreen text
            fs = font.render(fsText, True, (255,255,255))
            fsRect = fs.get_rect()
            fsRect.centerx = screen.get_rect().centerx
            fsRect.centery = height12*5
            # Render back text
            bc = font.render(bcText, True, (255,255,255))
            bcRect = bc.get_rect()
            bcRect.centerx = screen.get_rect().centerx
            bcRect.centery = height12*6

            # Draw text
            screen.blit(title, titleRect)
            screen.blit(fs, fsRect)
            screen.blit(bc, bcRect)
    
        # Flip the display
        pygame.display.flip()
Ejemplo n.º 2
0
def launch():

    # Initialize pygame
    pygame.init()

    # Initialize the pygame font module
    pygame.font.init()

    # Set the width and height of the window
    width, height = int(pygame.display.Info().current_w), int(
        pygame.display.Info().current_h)
    # Create the window
    screen = pygame.display.set_mode((width, height),
                                     pygame.HWSURFACE | pygame.DOUBLEBUF)
    # Set title
    OurTitle = "Candy Mountain"
    pygame.display.set_caption(OurTitle)

    # Set choice
    choice = 1
    Schoice = 1
    MorS = "main"
    # Set 1/12 height
    height12 = height / 12

    # Load images
    # Load the background image
    grass = pygame.image.load("resources/images/grass.png")

    # Set display mode
    prevFS = settings.getFullscreen()
    if settings.getFullscreen() == True:
        screen = pygame.display.set_mode(
            (width, height),
            pygame.HWSURFACE | pygame.DOUBLEBUF | pygame.FULLSCREEN)
    elif settings.getFullscreen() == False:
        screen = pygame.display.set_mode((width, height),
                                         pygame.HWSURFACE | pygame.DOUBLEBUF)

    # Keep looping through
    while True:
        # Set display mode if changed
        if prevFS != settings.getFullscreen():
            if settings.getFullscreen() == True:
                screen = pygame.display.set_mode(
                    (width, height),
                    pygame.HWSURFACE | pygame.DOUBLEBUF | pygame.FULLSCREEN)
                prevFS = settings.getFullscreen()
            elif settings.getFullscreen() == False:
                screen = pygame.display.set_mode(
                    (width, height), pygame.HWSURFACE | pygame.DOUBLEBUF)
                prevFS = settings.getFullscreen()

        # Clear the screen before drawing it again
        screen.fill(0)
        # Draw the background
        for x in range(width / grass.get_width() + 1):
            for y in range(height / grass.get_height() + 1):
                screen.blit(grass, (x * 100, y * 100))

        # Loop through the events
        for event in pygame.event.get():
            # Check if the event is the X button
            if event.type == pygame.QUIT:
                # If it is quit the game
                pygame.quit()
                sys.exit()
            # Check if a key is pressed
            elif event.type == pygame.KEYDOWN:
                # Check if arrow down is pressed
                if event.key == K_DOWN:
                    if MorS == "main":
                        if choice == 1:
                            choice = 2
                        elif choice == 2:
                            choice = 3
                        elif choice == 3:
                            choice = 1
                    elif MorS == "settings":
                        if Schoice == 1:
                            Schoice = 2
                        elif Schoice == 2:
                            Schoice = 1
                # Check if arrow up is pressed
                elif event.key == K_UP:
                    if MorS == "main":
                        if choice == 1:
                            choice = 3
                        elif choice == 2:
                            choice = 1
                        elif choice == 3:
                            choice = 2
                    elif MorS == "settings":
                        if Schoice == 1:
                            Schoice = 2
                        elif Schoice == 2:
                            Schoice = 1
                # Check if return is pressed
                elif event.key == K_RETURN:
                    if MorS == "main":
                        if choice == 1:
                            singleplayer.play()
                        elif choice == 2:
                            MorS = "settings"
                        elif choice == 3:
                            pygame.quit()
                            sys.exit()
                    elif MorS == "settings":
                        if Schoice == 1:
                            settings.changeFullscreen()
                        elif Schoice == 2:
                            MorS = "main"
                # Quit by pressing escape
                elif event.key == K_ESCAPE:
                    pygame.quit()
                    sys.exit()
                # Fullscreen by pressing F4
                elif event.key == K_F4:
                    settings.changeFullscreen()

        # Set font
        font = pygame.font.Font("freesansbold.ttf", 24)
        bigfont = pygame.font.Font("freesansbold.ttf", 48)

        if MorS == "main":
            # Check for cursor
            if choice == 1:
                spText = "-- Single Player --"
                stText = "Settings"
                xtText = "Exit"
            elif choice == 2:
                spText = "Single Player"
                stText = "-- Settings --"
                xtText = "Exit"
            elif choice == 3:
                spText = "Single Player"
                stText = "Settings"
                xtText = "-- Exit --"

            # Render text
            # Render title text
            title = bigfont.render(OurTitle, True, (0, 0, 0))
            titleRect = title.get_rect()
            titleRect.centerx = screen.get_rect().centerx
            titleRect.centery = height12 * 2
            # Render single player text
            sp = font.render(spText, True, (0, 0, 0))
            spRect = sp.get_rect()
            spRect.centerx = screen.get_rect().centerx
            spRect.centery = height12 * 5
            # Render settings text
            st = font.render(stText, True, (0, 0, 0))
            stRect = st.get_rect()
            stRect.centerx = screen.get_rect().centerx
            stRect.centery = height12 * 6
            # Render exit text
            xt = font.render(xtText, True, (0, 0, 0))
            xtRect = xt.get_rect()
            xtRect.centerx = screen.get_rect().centerx
            xtRect.centery = height12 * 7

            # Draw text
            screen.blit(title, titleRect)
            screen.blit(sp, spRect)
            screen.blit(st, stRect)
            screen.blit(xt, xtRect)

        elif MorS == "settings":
            # Check for cursor
            if Schoice == 1:
                fsText = "-- Fullscreen: " + str(
                    settings.getFullscreen()) + " --"
                bcText = "Back"
            elif Schoice == 2:
                fsText = "Fullscreen: " + str(settings.getFullscreen())
                bcText = "-- Back --"

            # Render text
            # Render title text
            title = bigfont.render(OurTitle, True, (0, 0, 0))
            titleRect = title.get_rect()
            titleRect.centerx = screen.get_rect().centerx
            titleRect.centery = height12 * 2
            # Render fullscreen text
            fs = font.render(fsText, True, (0, 0, 0))
            fsRect = fs.get_rect()
            fsRect.centerx = screen.get_rect().centerx
            fsRect.centery = height12 * 5
            # Render back text
            bc = font.render(bcText, True, (0, 0, 0))
            bcRect = bc.get_rect()
            bcRect.centerx = screen.get_rect().centerx
            bcRect.centery = height12 * 6

            # Draw text
            screen.blit(title, titleRect)
            screen.blit(fs, fsRect)
            screen.blit(bc, bcRect)

        # Flip the display
        pygame.display.flip()
Ejemplo n.º 3
0
def launch():
    # Initialize pygame
    pygame.init()
    # Initialize the pygame font module
    pygame.font.init()

    # Set the width and height of the window
    width, height = int(pygame.display.Info().current_w), int(pygame.display.Info().current_h)
    # Create the window
    screen = pygame.display.set_mode((width, height), pygame.HWSURFACE | pygame.DOUBLEBUF)
    # Set title
    pygame.display.set_caption("Bunny and Badgers")
    
    # Initialize the joystick module
    pygame.joystick.init()
    # Check if there are any joysticks
    joystick_count = pygame.joystick.get_count()
    # If there are any joysticks, initialize the first one, else quit the joystick module
    if joystick_count:
        joystick = pygame.joystick.Joystick(0)
        joystick.init()
        JS = True
    else:
        pygame.joystick.quit()
        JS = False
    
    # Set choice
    choice = 1
    spchoice = 1
    Schoice = 1
    cmenu = "main"
    # Set 1/12 height
    height12 = height/12
    
    # Load images
    # Load the background image
    grass = pygame.image.load("resources/images/grass.png").convert()

    # Set display mode
    prevFS = settings.getFullscreen()
    if settings.getFullscreen() == True:
        screen = pygame.display.set_mode((width, height), pygame.HWSURFACE | pygame.DOUBLEBUF | pygame.FULLSCREEN)
    elif settings.getFullscreen() == False:
        screen = pygame.display.set_mode((width, height), pygame.HWSURFACE | pygame.DOUBLEBUF)

    
    # Keep looping through
    while True:
        # Set display mode if changed
        if prevFS != settings.getFullscreen():
            if settings.getFullscreen() == True:
                screen = pygame.display.set_mode((width, height), pygame.HWSURFACE | pygame.DOUBLEBUF | pygame.FULLSCREEN)
                prevFS = settings.getFullscreen()
            elif settings.getFullscreen() == False:
                screen = pygame.display.set_mode((width, height), pygame.HWSURFACE | pygame.DOUBLEBUF)
                prevFS = settings.getFullscreen()

        # Set joystick buttons, if there are any
        if JS:
            buttonUP = joystick.get_button(4)
            buttonDOWN = joystick.get_button(6)
            buttonX = joystick.get_button(14)
        # Clear the screen before drawing it again
        screen.fill(0)
        # Draw the background
        for x in range(width/grass.get_width()+1):
            for y in range(height/grass.get_height()+1):
                screen.blit(grass,(x*100,y*100))
    
        # Loop through the events
        for event in pygame.event.get():
            # Check if the event is the X button 
            if event.type == pygame.QUIT:
                # If it is quit the game
                pygame.quit()
                sys.exit()
            # Check if pressed on a text                
            elif event.type == pygame.MOUSEBUTTONDOWN:
                mpos = pygame.mouse.get_pos()
                if cmenu == "main":
                    if spRect.collidepoint(mpos):
                        cmenu = "singleplayer"
                    elif stRect.collidepoint(mpos):
                        cmenu = "settings"
                    elif xtRect.collidepoint(mpos):
                        pygame.quit()
                        sys.exit()
                elif cmenu == "singleplayer":
                    if ezRect.collidepoint(mpos):
                        singleplayer.play(10)
                    elif mdRect.collidepoint(mpos):
                        singleplayer.play(20)
                    elif dcRect.collidepoint(mpos):
                        singleplayer.play(30)
                elif cmenu == "settings":
                    if fsRect.collidepoint(mpos):
                        settings.changeFullscreen()
                    elif jsRect.collidepoint(mpos):
                        jstest.launch()
                    elif bcRect.collidepoint(mpos):
                        cmenu = "main"
            # Check if a key is pressed
            elif event.type == pygame.KEYDOWN:
                # Check if arrow down is pressed
                if event.key == K_DOWN:
                    if cmenu == "main":
                        if choice == 1:
                            choice = 2
                        elif choice == 2:
                            choice = 3
                        elif choice == 3:
                            choice = 1
                    elif cmenu == "singleplayer":
                        if spchoice == 1:
                            spchoice = 2
                        elif spchoice == 2:
                            spchoice = 3
                        elif spchoice == 3:
                            spchoice = 1
                    elif cmenu == "settings":
                        if Schoice == 1:
                            Schoice = 2
                        elif Schoice == 2:
                            Schoice = 3
                        elif Schoice == 3:
                            Schoice = 1
                # Check if arrow up is pressed
                elif event.key == K_UP:
                    if cmenu == "main":
                        if choice == 1:
                            choice = 3
                        elif choice == 2:
                            choice = 1
                        elif choice == 3:
                            choice = 2
                    elif cmenu == "singleplayer":
                        if spchoice == 1:
                            spchoice = 3
                        elif spchoice == 2:
                            spchoice = 1
                        elif spchoice == 3:
                            spchoice = 2
                    elif cmenu == "settings":
                        if Schoice == 1:
                            Schoice = 3
                        elif Schoice == 2:
                            Schoice = 1
                        elif Schoice == 3:
                            Schoice = 2
                # Check if return is pressed
                elif event.key == K_RETURN:
                    if cmenu == "main":
                        if choice == 1:
                            cmenu = "singleplayer"
                        elif choice == 2:
                            cmenu = "settings"
                        elif choice == 3:
                            pygame.quit()
                            sys.exit()
                    elif cmenu == "singleplayer":
                        if spchoice == 1:
                            singleplayer.play(10)
                        elif spchoice == 2:
                            singleplayer.play(20)
                        elif spchoice == 3:
                            singleplayer.play(30)
                    elif cmenu == "settings":
                        if Schoice == 1:
                            settings.changeFullscreen()
                        elif Schoice == 2:
                            jstest.launch()
                        elif Schoice == 3:
                            cmenu = "main"
                # Check if backspace is pressed
                elif event.key == K_BACKSPACE:
                    cmenu = "main"
                # Quit by pressing escape
                elif event.key == K_ESCAPE:
                    pygame.quit()
                    sys.exit()
                # Fullscreen by pressing F4
                elif event.key == K_F4:
                    settings.changeFullscreen()
            # Check if there are any joysticks
            if JS:
                # Check if UP is pressed
                if buttonUP:
                    if cmenu == "main":
                        if choice == 1:
                            choice = 3
                        elif choice == 2:
                            choice = 1
                        elif choice == 3:
                            choice = 2
                    elif cmenu == "singleplayer":
                        if spchoice == 1:
                            spchoice = 3
                        elif spchoice == 2:
                            spchoice = 1
                        elif spchoice == 3:
                            spchoice = 2
                    elif cmenu == "settings":
                        if Schoice == 1:
                            Schoice = 3
                        elif Schoice == 2:
                            Schoice = 1
                        elif Schoice == 3:
                            Schoice = 2
                # Check if DOWN is pressed
                elif buttonDOWN:
                    if cmenu == "main":
                        if choice == 1:
                            choice = 2
                        elif choice == 2:
                            choice = 3
                        elif choice == 3:
                            choice = 1
                    elif cmenu == "singleplayer":
                        if spchoice == 1:
                            spchoice = 2
                        elif spchoice == 2:
                            spchoice = 3
                        elif spchoice == 3:
                            spchoice = 1
                    elif cmenu == "settings":
                        if Schoice == 1:
                            Schoice = 2
                        elif Schoice == 2:
                            Schoice = 3
                        elif Schoice == 3:
                            Schoice = 1
                # Check if X is pressed
                elif buttonX:
                    if cmenu == "main":
                        if choice == 1:
                            cmenu = "singleplayer"
                        elif choice == 2:
                            cmenu = "settings"
                        elif choice == 3:
                            pygame.quit()
                            sys.exit()
                    elif cmenu == "singleplayer":
                        if spchoice == 1:
                            singleplayer.play(10)
                        elif spchoice == 2:
                            singleplayer.play(20)
                        elif spchoice == 3:
                            singleplayer.play(30)
                    elif cmenu == "settings":
                        if Schoice == 1:
                            settings.changeFullscreen()
                        elif Schoice == 2:
                            jstest.launch()
                        elif Schoice == 3:
                            cmenu = "main"
    
        # Set font
        font = pygame.font.Font("freesansbold.ttf", 24)
        bigfont = pygame.font.Font("freesansbold.ttf", 48)
    
        if cmenu == "main":
            # Check for cursor
            if choice == 1:
                spText = "-- Single Player --"
                stText = "Settings"
                xtText = "Exit"
            elif choice == 2:
                spText = "Single Player"
                stText = "-- Settings --"
                xtText = "Exit"
            elif choice == 3:
                spText = "Single Player"
                stText = "Settings"
                xtText = "-- Exit --"
    
            # Render text
            # Render title text
            title = bigfont.render("Bunny and Badgers", True, (0,0,0))
            titleRect = title.get_rect()
            titleRect.centerx = screen.get_rect().centerx
            titleRect.centery = height12*2
            # Render single player text
            sp = font.render(spText, True, (0,0,0))
            spRect = sp.get_rect()
            spRect.centerx = screen.get_rect().centerx
            spRect.centery = height12*5
            # Render settings text
            st = font.render(stText, True, (0,0,0))
            stRect = st.get_rect()
            stRect.centerx = screen.get_rect().centerx
            stRect.centery = height12*6
            # Render exit text
            xt = font.render(xtText, True, (0,0,0))
            xtRect = xt.get_rect()
            xtRect.centerx = screen.get_rect().centerx
            xtRect.centery = height12*7
    
            # Draw text
            screen.blit(title, titleRect)
            screen.blit(sp, spRect)
            screen.blit(st, stRect)
            screen.blit(xt, xtRect)

        elif cmenu == "singleplayer":
            # Check for cursor
            if spchoice == 1:
                ezText = "-- Easy --"
                mdText = "Medium"
                dcText = "Difficult"
            elif spchoice == 2:
                ezText = "Easy"
                mdText = "-- Medium --"
                dcText = "Difficult"
            elif spchoice == 3:
                ezText = "Easy"
                mdText = "Medium"
                dcText = "-- Difficult --"

            # Render text
            # Render title text
            title = bigfont.render("Bunny and Badgers", True, (0,0,0))
            titleRect = title.get_rect()
            titleRect.centerx = screen.get_rect().centerx
            titleRect.centery = height12*2
            # Render easy text
            ez = font.render(ezText, True, (0,0,0))
            ezRect = ez.get_rect()
            ezRect.centerx = screen.get_rect().centerx
            ezRect.centery = height12*5
            # Render medium text
            md = font.render(mdText, True, (0,0,0))
            mdRect = md.get_rect()
            mdRect.centerx = screen.get_rect().centerx
            mdRect.centery = height12*6
            # Render difficult text
            dc = font.render(dcText, True, (0,0,0))
            dcRect = dc.get_rect()
            dcRect.centerx = screen.get_rect().centerx
            dcRect.centery = height12*7

            # Draw text
            screen.blit(title, titleRect)
            screen.blit(ez, ezRect)
            screen.blit(md, mdRect)
            screen.blit(dc, dcRect)

        elif cmenu == "settings":
            # Check for cursor
            if Schoice == 1:
                fsText = "-- Fullscreen: " + str(settings.getFullscreen()) + " --"
                jsText = "Test joystick"
                bcText = "Back"
            elif Schoice == 2:
                fsText = "Fullscreen: " + str(settings.getFullscreen())
                jsText = "-- Test joystick --"
                bcText = "Back"
            elif Schoice == 3:
                fsText = "Fullscreen: " + str(settings.getFullscreen())
                jsText = "Test joystick"
                bcText = "-- Back --"

            # Render text
            # Render title text
            title = bigfont.render("Bunny and Badgers", True, (0,0,0))
            titleRect = title.get_rect()
            titleRect.centerx = screen.get_rect().centerx
            titleRect.centery = height12*2
            # Render fullscreen text
            fs = font.render(fsText, True, (0,0,0))
            fsRect = fs.get_rect()
            fsRect.centerx = screen.get_rect().centerx
            fsRect.centery = height12*5
            # Render joystick text
            js = font.render(jsText, True, (0,0,0))
            jsRect = js.get_rect()
            jsRect.centerx = screen.get_rect().centerx
            jsRect.centery = height12*6
            # Render back text
            bc = font.render(bcText, True, (0,0,0))
            bcRect = bc.get_rect()
            bcRect.centerx = screen.get_rect().centerx
            bcRect.centery = height12*7

            # Draw text
            screen.blit(title, titleRect)
            screen.blit(fs, fsRect)
            screen.blit(js, jsRect)
            screen.blit(bc, bcRect)
    
        # Flip the display
        pygame.display.flip()
Ejemplo n.º 4
0
def launch():
    # Initialize pygame
    pygame.init()
    # Initialize the pygame font module
    pygame.font.init()
    
    # Set the width and height of the window
    width, height = 640, 480
    # Create the window
    screen = pygame.display.set_mode((width, height), pygame.HWSURFACE | pygame.DOUBLEBUF)
    # Set title
    pygame.display.set_caption("Bunny and Badgers")
    
    # Set choices
    choice = 1
    # Set 1/12 height
    height12 = height/12
    
    # Load images
    # Load the background image
    grass = pygame.image.load("resources/images/grass.png").convert()
  
    # Keep looping through
    while True:
        # Draw the background
        for x in range(width/grass.get_width()+1):
            for y in range(height/grass.get_height()+1):
                screen.blit(grass,(x*100,y*100))
    
        # Loop through the events
        for event in pygame.event.get():
            # Check if pressed on a text                
            if event.type == pygame.MOUSEBUTTONDOWN:
                mpos = pygame.mouse.get_pos()
                if spRect.collidepoint(mpos):
                    singleplayer.play(20)
                elif xtRect.collidepoint(mpos):
                    pygame.quit()
                    sys.exit()
            # Check if a key is pressed
            elif event.type == pygame.KEYDOWN:
                # Check if back is pressed
                if event.key == K_AC_BACK:
                        pygame.quit()
                        sys.exit()
    
        # Set font
        font = pygame.font.Font("freesansbold.ttf", 24)
        bigfont = pygame.font.Font("freesansbold.ttf", 48)
    
        if cmenu == "main":
            spText = "Single Player"
            xtText = "Exit"
    
            # Render text
            # Render title text
            title = bigfont.render("Bunny and Badgers", True, (0,0,0))
            titleRect = title.get_rect()
            titleRect.centerx = screen.get_rect().centerx
            titleRect.centery = height12*2
            # Render single player text
            sp = font.render(spText, True, (0,0,0))
            spRect = sp.get_rect()
            spRect.centerx = screen.get_rect().centerx
            spRect.centery = height12*5
            # Render exit text
            xt = font.render(xtText, True, (0,0,0))
            xtRect = xt.get_rect()
            xtRect.centerx = screen.get_rect().centerx
            xtRect.centery = height12*6
    
            # Draw text
            screen.blit(title, titleRect)
            screen.blit(sp, spRect)
            screen.blit(xt, xtRect)
    
        # Flip the display
        pygame.display.flip()
Ejemplo n.º 5
0
def launch():

    # Initialize pygame
    pygame.init()
    # Initialize the pygame font module
    pygame.font.init()

    # Set the width and height of the window
    width, height = int(pygame.display.Info().current_w), int(
        pygame.display.Info().current_h)
    # Create the window
    screen = pygame.display.set_mode((width, height),
                                     pygame.HWSURFACE | pygame.DOUBLEBUF)
    # Set title
    pygame.display.set_caption("Galaxy Wars")

    # Initialize the joystick module
    pygame.joystick.init()
    # Check if there are any joysticks
    joystick_count = pygame.joystick.get_count()
    # If there are any joysticks, initialize the first one, else quit the joystick module
    if joystick_count:
        joystick = pygame.joystick.Joystick(0)
        joystick.init()
        JS = True
    else:
        pygame.joystick.quit()
        JS = False

    # Set choice
    choice = 1
    Schoice = 1
    MorS = "main"
    # Set 1/12 height
    height12 = height / 12

    # Load images
    # Load the background image
    bgmain = pygame.image.load("resources/images/bgmain.jpg")
    bgmain = pygame.transform.scale(bgmain, (width, height))
    # Set display mode
    prevFS = settings.getFullscreen()
    if settings.getFullscreen() == True:
        screen = pygame.display.set_mode(
            (width, height),
            pygame.HWSURFACE | pygame.DOUBLEBUF | pygame.FULLSCREEN)
    elif settings.getFullscreen() == False:
        screen = pygame.display.set_mode((width, height),
                                         pygame.HWSURFACE | pygame.DOUBLEBUF)

    # Keep looping through
    while True:
        # Set display mode if changed
        if prevFS != settings.getFullscreen():
            if settings.getFullscreen() == True:
                screen = pygame.display.set_mode(
                    (width, height),
                    pygame.HWSURFACE | pygame.DOUBLEBUF | pygame.FULLSCREEN)
                prevFS = settings.getFullscreen()
            elif settings.getFullscreen() == False:
                screen = pygame.display.set_mode(
                    (width, height), pygame.HWSURFACE | pygame.DOUBLEBUF)
                prevFS = settings.getFullscreen()

        # Set joystick buttons, if there are any
        if JS:
            buttonUP = joystick.get_button(4)
            buttonDOWN = joystick.get_button(6)
            buttonX = joystick.get_button(14)
        # Clear the screen before drawing it again
        screen.fill(0)
        # Draw the background
        screen.blit(bgmain, (0, 0))
        # Loop through the events
        for event in pygame.event.get():
            # Check if the event is the X button
            if event.type == pygame.QUIT:
                # If it is quit the game
                pygame.quit()
                sys.exit()
            # Check if a key is pressed
            elif event.type == pygame.KEYDOWN:
                # Check if arrow down is pressed
                if event.key == K_DOWN:
                    if MorS == "main":
                        if choice == 1:
                            choice = 2
                        elif choice == 2:
                            choice = 3
                        elif choice == 3:
                            choice = 1
                    elif MorS == "settings":
                        if Schoice == 1:
                            Schoice = 2
                        elif Schoice == 2:
                            Schoice = 1
                # Check if arrow up is pressed
                elif event.key == K_UP:
                    if MorS == "main":
                        if choice == 1:
                            choice = 3
                        elif choice == 2:
                            choice = 1
                        elif choice == 3:
                            choice = 2
                    elif MorS == "settings":
                        if Schoice == 1:
                            Schoice = 2
                        elif Schoice == 2:
                            Schoice = 1
                # Check if return is pressed
                elif event.key == K_RETURN:
                    if MorS == "main":
                        if choice == 1:
                            singleplayer.play()
                        elif choice == 2:
                            MorS = "settings"
                        elif choice == 3:
                            pygame.quit()
                            sys.exit()
                    elif MorS == "settings":
                        if Schoice == 1:
                            settings.changeFullscreen()
                        elif Schoice == 2:
                            MorS = "main"
                # Quit by pressing escape
                elif event.key == K_ESCAPE:
                    pygame.quit()
                    sys.exit()
                # Fullscreen by pressing F4
                elif event.key == K_F4:
                    settings.changeFullscreen()
            # Check if there are any joysticks
            if JS:
                # Check if UP is pressed
                if buttonUP:
                    if choice == 1:
                        choice = 3
                    elif choice == 2:
                        choice = 1
                    elif choice == 3:
                        choice = 2
                # Check if DOWN is pressed
                elif buttonDOWN:
                    if choice == 1:
                        choice = 2
                    elif choice == 2:
                        choice = 3
                    elif choice == 3:
                        choice = 1
                # Check if X is pressed
                elif buttonX:
                    if choice == 1:
                        singleplayer.play()
                    elif choice == 2:
                        MorS = "settings"
                    elif choice == 3:
                        pygame.quit()
                        sys.exit()

        # Set font
        font = pygame.font.Font("freesansbold.ttf", 24)
        bigfont = pygame.font.Font("freesansbold.ttf", 48)

        if MorS == "main":
            # Check for cursor
            if choice == 1:
                spText = "-- Single Player --"
                stText = "Settings"
                xtText = "Exit"
            elif choice == 2:
                spText = "Single Player"
                stText = "-- Settings --"
                xtText = "Exit"
            elif choice == 3:
                spText = "Single Player"
                stText = "Settings"
                xtText = "-- Exit --"

            # Render text
            # Render title text
            title = bigfont.render("Galaxy Wars", True, (255, 255, 255))
            titleRect = title.get_rect()
            titleRect.centerx = screen.get_rect().centerx
            titleRect.centery = height12 * 2
            # Render single player text
            sp = font.render(spText, True, (255, 255, 255))
            spRect = sp.get_rect()
            spRect.centerx = screen.get_rect().centerx
            spRect.centery = height12 * 5
            # Render settings text
            st = font.render(stText, True, (255, 255, 255))
            stRect = st.get_rect()
            stRect.centerx = screen.get_rect().centerx
            stRect.centery = height12 * 6
            # Render exit text
            xt = font.render(xtText, True, (255, 255, 255))
            xtRect = xt.get_rect()
            xtRect.centerx = screen.get_rect().centerx
            xtRect.centery = height12 * 7

            # Draw text
            screen.blit(title, titleRect)
            screen.blit(sp, spRect)
            screen.blit(st, stRect)
            screen.blit(xt, xtRect)

        elif MorS == "settings":
            # Check for cursor
            if Schoice == 1:
                fsText = "-- Fullscreen: " + str(
                    settings.getFullscreen()) + " --"
                bcText = "Back"
            elif Schoice == 2:
                fsText = "Fullscreen: " + str(settings.getFullscreen())
                bcText = "-- Back --"

            # Render text
            # Render title text
            title = bigfont.render("Galaxy Wars", True, (255, 255, 255))
            titleRect = title.get_rect()
            titleRect.centerx = screen.get_rect().centerx
            titleRect.centery = height12 * 2
            # Render fullscreen text
            fs = font.render(fsText, True, (255, 255, 255))
            fsRect = fs.get_rect()
            fsRect.centerx = screen.get_rect().centerx
            fsRect.centery = height12 * 5
            # Render back text
            bc = font.render(bcText, True, (255, 255, 255))
            bcRect = bc.get_rect()
            bcRect.centerx = screen.get_rect().centerx
            bcRect.centery = height12 * 6

            # Draw text
            screen.blit(title, titleRect)
            screen.blit(fs, fsRect)
            screen.blit(bc, bcRect)

        # Flip the display
        pygame.display.flip()
Ejemplo n.º 6
0
def launch():
    
    # Initialize pygame
    pygame.init()

    # Initialize the pygame font module
    pygame.font.init()
    
    # Set the width and height of the window
    width, height = int(pygame.display.Info().current_w), int(pygame.display.Info().current_h)
    # Create the window
    screen = pygame.display.set_mode((width, height), pygame.HWSURFACE | pygame.DOUBLEBUF)
    # Set title
    OurTitle = "Candy Mountain"
    pygame.display.set_caption(OurTitle)
    
    
    # Set choice
    choice = 1
    Schoice = 1
    MorS = "main"
    # Set 1/12 height
    height12 = height/12
    
    # Load images
    # Load the background image
    grass = pygame.image.load("resources/images/grass.png")

    # Set display mode
    prevFS = settings.getFullscreen()
    if settings.getFullscreen() == True:
        screen = pygame.display.set_mode((width, height), pygame.HWSURFACE | pygame.DOUBLEBUF | pygame.FULLSCREEN)
    elif settings.getFullscreen() == False:
        screen = pygame.display.set_mode((width, height), pygame.HWSURFACE | pygame.DOUBLEBUF)

    
    # Keep looping through
    while True:
        # Set display mode if changed
        if prevFS != settings.getFullscreen():
            if settings.getFullscreen() == True:
                screen = pygame.display.set_mode((width, height), pygame.HWSURFACE | pygame.DOUBLEBUF | pygame.FULLSCREEN)
                prevFS = settings.getFullscreen()
            elif settings.getFullscreen() == False:
                screen = pygame.display.set_mode((width, height), pygame.HWSURFACE | pygame.DOUBLEBUF)
                prevFS = settings.getFullscreen()

        # Clear the screen before drawing it again
        screen.fill(0)
        # Draw the background
        for x in range(width/grass.get_width()+1):
            for y in range(height/grass.get_height()+1):
                screen.blit(grass,(x*100,y*100))
    
        # Loop through the events
        for event in pygame.event.get():
            # Check if the event is the X button 
            if event.type == pygame.QUIT:
                # If it is quit the game
                pygame.quit()
                sys.exit()
            # Check if a key is pressed
            elif event.type == pygame.KEYDOWN:
                # Check if arrow down is pressed
                if event.key == K_DOWN:
                    if MorS == "main":
                        if choice == 1:
                            choice = 2
                        elif choice == 2:
                            choice = 3
                        elif choice == 3:
                            choice = 1
                    elif MorS == "settings":
                        if Schoice == 1:
                            Schoice = 2
                        elif Schoice == 2:
                            Schoice = 1
                # Check if arrow up is pressed
                elif event.key == K_UP:
                    if MorS == "main":
                        if choice == 1:
                            choice = 3
                        elif choice == 2:
                            choice = 1
                        elif choice == 3:
                            choice = 2
                    elif MorS == "settings":
                        if Schoice == 1:
                            Schoice = 2
                        elif Schoice == 2:
                            Schoice = 1
                # Check if return is pressed
                elif event.key == K_RETURN:
                    if MorS == "main":
                        if choice == 1:
                            singleplayer.play()
                        elif choice == 2:
                            MorS = "settings"
                        elif choice == 3:
                            pygame.quit()
                            sys.exit()
                    elif MorS == "settings":
                        if Schoice == 1:
                            settings.changeFullscreen()
                        elif Schoice == 2:
                            MorS = "main"
                # Quit by pressing escape
                elif event.key == K_ESCAPE:
                    pygame.quit()
                    sys.exit()
                # Fullscreen by pressing F4
                elif event.key == K_F4:
                    settings.changeFullscreen()

    
        # Set font
        font = pygame.font.Font("freesansbold.ttf", 24)
        bigfont = pygame.font.Font("freesansbold.ttf", 48)
    
        if MorS == "main":
            # Check for cursor
            if choice == 1:
                spText = "-- Single Player --"
                stText = "Settings"
                xtText = "Exit"
            elif choice == 2:
                spText = "Single Player"
                stText = "-- Settings --"
                xtText = "Exit"
            elif choice == 3:
                spText = "Single Player"
                stText = "Settings"
                xtText = "-- Exit --"
    
            # Render text
            # Render title text
            title = bigfont.render(OurTitle, True, (0,0,0))
            titleRect = title.get_rect()
            titleRect.centerx = screen.get_rect().centerx
            titleRect.centery = height12*2
            # Render single player text
            sp = font.render(spText, True, (0,0,0))
            spRect = sp.get_rect()
            spRect.centerx = screen.get_rect().centerx
            spRect.centery = height12*5
            # Render settings text
            st = font.render(stText, True, (0,0,0))
            stRect = st.get_rect()
            stRect.centerx = screen.get_rect().centerx
            stRect.centery = height12*6
            # Render exit text
            xt = font.render(xtText, True, (0,0,0))
            xtRect = xt.get_rect()
            xtRect.centerx = screen.get_rect().centerx
            xtRect.centery = height12*7
    
            # Draw text
            screen.blit(title, titleRect)
            screen.blit(sp, spRect)
            screen.blit(st, stRect)
            screen.blit(xt, xtRect)

        elif MorS == "settings":
            # Check for cursor
            if Schoice == 1:
                fsText = "-- Fullscreen: " + str(settings.getFullscreen()) + " --"
                bcText = "Back"
            elif Schoice == 2:
                fsText = "Fullscreen: " + str(settings.getFullscreen())
                bcText = "-- Back --"

            # Render text
            # Render title text
            title = bigfont.render(OurTitle, True, (0,0,0))
            titleRect = title.get_rect()
            titleRect.centerx = screen.get_rect().centerx
            titleRect.centery = height12*2
            # Render fullscreen text
            fs = font.render(fsText, True, (0,0,0))
            fsRect = fs.get_rect()
            fsRect.centerx = screen.get_rect().centerx
            fsRect.centery = height12*5
            # Render back text
            bc = font.render(bcText, True, (0,0,0))
            bcRect = bc.get_rect()
            bcRect.centerx = screen.get_rect().centerx
            bcRect.centery = height12*6

            # Draw text
            screen.blit(title, titleRect)
            screen.blit(fs, fsRect)
            screen.blit(bc, bcRect)
    
        # Flip the display
        pygame.display.flip()