I need help going from my starting menu to my game. At the moment i would like to prompt the user to hit enter and then go directly into the playable part of the program. However, i cant figure out how to clear what im doing and start up the game part. Heres the code so far (i will add the interactive part at the title menu later when i learn how from you guys):
[source lang="python"]import pygame, randomimport randintimport pplrtyimport sysfrom pygame.locals import *pygame.init()FPS = 30fpsClock = pygame.time.Clock()#variablesx = randint.xyear = 2011p = pplrty.pmousepos = pygame.mouse.get_pos()#get colorsWHITE = (255, 255, 255)RED = (255, 0, 0)#get display stuffDISPLAY = pygame.display.set_mode((640,480))pygame.display.set_caption('Program')#create fontsfontObj1 = pygame.font.Font('freesansbold.ttf', 16)#make wordstextObj1 = fontObj1.render('Hit Enter', True, RED)RectObj1 = textObj1.get_rect()RectObj1.center = (315, 240)#get imagestitle = pygame.image.load('title.png')stitle = pygame.transform.scale(title, (264, 64))bg = pygame.image.load('bg.png')sbg = pygame.transform.scale(bg, (640, 480))#fill the display with good stuffDISPLAY.blit(sbg, (0, 0))DISPLAY.blit(stitle, (188, 10))DISPLAY.blit(textObj1, RectObj1)#Main Loopwhile True: for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.key == pygame.K_RETURN: year += 1 if event.type == QUIT: pygame.quit() sys.exit() pygame.display.update()[/source]
keep in mind its still very underdeveloped.
Going from the menu into the game
Started by K1NNY, Sep 18 2012 09:27 AM
1 reply to this topic
Sponsor:
#2 Members - Reputation: 878
Posted 18 September 2012 - 10:38 AM
You should do some reserach on state machines.
At the most basic level, you could start with something like this:
If you're relatively new to Python, you might want to try my Python 3 video tutorial series: link.
At the most basic level, you could start with something like this:
def menu(): ... whatever you would typically do for the menu if keyHit(ENTER): return game def game(): ... your game loop if (SHOULD_GO_BACK_TO_MENU): return menu state = menu while True: state_next = state() if state_next: state = state_next
If you're relatively new to Python, you might want to try my Python 3 video tutorial series: link.
Learn the basics with my Python 3 video tutorial series. Looking for a good game engine, and relevant tutorials? Here you go.
Small and simple Python 3.x media library: pslab
Small and simple Python 3.x media library: pslab






