0

I have recently started to make a game with python and pygame, I have a main script that has all my other scripts imported in and then it runs them all, but I have two main problems. The first being that when I run the first script in the main script it seems to stop after that class and not continue with the other script.

what i want the game to do:

show thee pictures as the opening credits. (working)

then once the credits are finished start up a menu, at the moment this is just one play button and a Rect which will have a collision response to detect whether the player has clicked it or not. (not working)

here are my scripts:

RUN.py (main game that runs everything together):

import pygame, random, math, sys, os, time
import startUp, Menu
from pygame.locals import *
pygame.init()

#classes setup
Begin = startUp.Begin()
Menu = Menu.HUD()
while True:

    #quit button 
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()



    #show 3 pics for the opening credits
    Begin.Run()

    #bring up the menu once the opening credits are done
    Menu.Run()

Then Menu.py (the menu for the game)

import pygame, time, random
from pygame.locals import *
pygame.init()

class HUD(object):

    def __init__(object):
        object.playButtonUp = "playButtonUp.png"
        object.playButtonUpHover = "playButtonUpHover.png"
        object.playButtonDown = "playButtonDown.png"

        object.Black = (0, 0, 0)
        object.Red = (0, 255, 0)
        object.screen = pygame.display.set_mode((1440, 720), 0, 32)

        object.playButtonUp = pygame.image.load(object.playButtonUp).convert_alpha()
        object.playButtonUpHover = pygame.image.load(object.playButtonUpHover).convert_alpha()
        object.playButtonDown = pygame.image.load(object.playButtonDown).convert_alpha()

    def Run(object):
        #object.screen.fill(object.Black)

        #creat rects
        object.playButtonRect = Rect(464, 232, 256, 128)

        #blit imagers
        object.screen.blit(object.playButtonUp, (464, 232))

there are no error message's and it seems to work but the image is not shown on the screen.

thanks for you time and help!

3
  • Does Begin.Run() ends? By the way, the standard python naming convention is to use lowercase for functions and methods names, and CapWords for class names. Commented Feb 25, 2014 at 9:41
  • I'm not familiar with pygame but is it okay to call pygame.init() twice? You repeat that in Menu.py. Commented Feb 25, 2014 at 9:42
  • well that's what I need to do, get begin.Run() end, but how? Commented Feb 25, 2014 at 9:46

1 Answer 1

1

Your structure is incorrect. You have merged two different approaches.

You have a Run script that should first show the 3 pictures, and after that show the menu.

Right now, you have a while loop that calls the run function of both Begin and Menu until you close the game.

Instead the files should look like this:

import pygame, random, math, sys, os, time
import startUp, Menu
from pygame.locals import *
pygame.init()

#classes setup
Begin = startUp.Begin()
Begin.run()

Menu = Menu.HUD()
Menu.run()

Menu.py

class HUD(object):
    def run(object):
        while True:
            object.playButtonRect = Rect(464, 232, 256, 128)
            object.screen.blit(object.playButtonUp, (464, 232))
            for event in pygame.event.get():
                if event.type == QUIT:
                    pygame.quit()
                    sys.exit()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.