def locationScreen(game, location): """ takes a location object, displays the main screen and handles options. """ currentEvents = updateCurrentEvents(location) game.bgImage = location.image while True: common_functions.standardEventHandling() event = location._displayLocationScreen( currentEvents) #displays location background, events, options if event: if event == 'Leave': #only returned if you choose to leave the location and return to the parent hub return else: #any other event goes to the function designed for handling events playEvent(game, event) currentEvents = updateCurrentEvents( location ) #updates active events without having to reenter the location if cfg.rightClick and not cfg.hudMenu: return game._displayHud() pygame.display.update() cfg.FPSCLOCK.tick(cfg.FPS)
def playTravelEvent(player, event): eventPos = 0 while True: common_functions.standardEventHandling() event._displayTravelEventBackground() event._displayTravelEventText(event.text[eventPos]) if eventPos > len(event.text) - 2: action = event._displayTravelEventActions() else: action = event._displayTravelEventActions(last=False) player._displayHud() if action: if action == 'Next': eventPos += 1 elif action == 'End': return else: for i in TRAVELEVENTLIST: if i.tag == action: newEvent = i return newEvent pygame.display.update() cfg.FPSCLOCK.tick(cfg.FPS)
def playMissionEvent(player, event): eventPos = 0 while True: common_functions.standardEventHandling() event._displayMissionEventBackground() event._displayMissionEventText(event.text[eventPos]) if eventPos > len(event.text) - 2: action = event._displayMissionEventActions() else: action = event._displayMissionEventActions(last=False) player._displayHud() if action: if action == 'Next': eventPos += 1 elif action == 'End': return else: return action pygame.display.update() cfg.FPSCLOCK.tick(cfg.FPS)
def hubScreen(player, hub): currentLocations = [] for i in classes.locationList: if i.hub == hub.name: currentLocations.append(i) while True: common_functions.standardEventHandling() location = hub._displayHubScreen() player._displayPlayerStats() if location: if location == 'Leave': leaveScreen() else: for i in currentLocations: if i.name == location: location = i locationScreen(player, location) pygame.display.update() cfg.FPSCLOCK.tick(cfg.FPS)
def locationScreen(player, location): """ takes a location object, displays the main screen and handles options. """ currentEvents = updateCurrentEvents( location ) #reads progression/reqs and populates currently available events based on current location while True: common_functions.standardEventHandling() event = location._displayLocationScreen( ) #displays location background, events, options player._displayHud() if event: if event == 'Leave': #only returned if you choose to leave the location and return to the parent hub return else: #any other event goes to the function designed for handling events playEvent(player, event, location) currentEvents = updateCurrentEvents( location ) #updates active events without having to reenter the location pygame.display.update() cfg.FPSCLOCK.tick(cfg.FPS)
def morningCamp(player): cfg.SOUNDDICT['Morning'].play() for i in range(255,0,-15): maskSurf = pygame.Surface((800, 600)) maskSurf.fill(cfg.BLACK) maskSurf.set_alpha(i) cfg.DISPLAYSURF.blit(cfg.IMAGEDICT['Camp - Day'], (0,0)) cfg.DISPLAYSURF.blit(maskSurf, (0,0)) pygame.display.update() cfg.FPSCLOCK.tick(cfg.FPS) while True: common_functions.standardEventHandling() cfg.DISPLAYSURF.blit(cfg.IMAGEDICT['Camp - Day'], (0,0)) player._displayHud() optionBackSurf = pygame.Surface((200, 50)) optionBackRect = optionBackSurf.get_rect() optionBackRect.bottomright = (600, 400) resumeSurf = cfg.BASICFONT.render('Resume Trip', True, cfg.WHITE) resumeRect = resumeSurf.get_rect() resumeRect.midleft = (optionBackRect.left + 15, optionBackRect.centery) if optionBackRect.collidepoint(cfg.mouseX, cfg.mouseY): resumeSurf = cfg.BASICFONT.render('Resume Trip', True, cfg.RED) if cfg.mouseClicked: common_functions.fadeout() return cfg.DISPLAYSURF.blit(optionBackSurf, optionBackRect) cfg.DISPLAYSURF.blit(resumeSurf, resumeRect) pygame.display.update() cfg.FPSCLOCK.tick(cfg.FPS)
def _displayJobBoard(self, game): jobPreview = None jobIndex = 0 while True: common_functions.standardEventHandling() game._focusForeground() action = self.availableJobs[jobIndex]._jobPosting() if action == 'Take Job': game.activeJobs.append(self.availableJobs[jobIndex]) return elif action == 'Stop Looking': return nextSurf = cfg.IMAGEDICT['Right One'] nextRect = nextSurf.get_rect() nextRect.midright = (cfg.WINWIDTH - 20, cfg.WINHEIGHT / 2) if nextRect.collidepoint(cfg.mouseX, cfg.mouseY) and not cfg.hudMenu: nextSurf = cfg.IMAGEDICT['Right Two'] if cfg.mouseClicked: jobIndex += 1 if jobIndex > len(self.availableJobs) - 1: jobIndex = 0 cfg.DISPLAYSURF.blit(nextSurf, nextRect) game._displayHud() pygame.display.update() cfg.FPSCLOCK.tick(cfg.FPS)
def nightCamp(game): while True: common_functions.standardEventHandling() cfg.DISPLAYSURF.blit(cfg.IMAGEDICT['Camp - Night'], (0, 0)) game._displayHud() optionBackSurf = pygame.Surface((240, 60)) optionBackSurf.set_alpha(140) optionBackRect = optionBackSurf.get_rect() optionBackRect.topleft = (100, 100) sleepSurf = cfg.BASICFONT.render('Sleep', True, cfg.WHITE) sleepRect = sleepSurf.get_rect() sleepRect.midleft = (optionBackRect.left + 15, optionBackRect.centery) if optionBackRect.collidepoint(cfg.mouseX, cfg.mouseY): sleepSurf = cfg.BASICFONT.render('Sleep', True, cfg.RED) optionBackSurf.fill(cfg.BLUE) optionBackSurf.set_alpha(55) if cfg.mouseClicked: common_functions.fadeout(speed=15) return cfg.DISPLAYSURF.blit(optionBackSurf, optionBackRect) pygame.draw.rect(cfg.DISPLAYSURF, cfg.WHITE, optionBackRect, 2) cfg.DISPLAYSURF.blit(sleepSurf, sleepRect) pygame.display.update() cfg.FPSCLOCK.tick(cfg.FPS)
def _playContinuationEvent(self, player, choice): if choice == '1': text = self.textOne prog = self.progOne elif choice == '2': text = self.textTwo prog = self.progTwo elif choice == '3': text = self.textThree prog = self.progThree self.name = cfg.activeComplexEvent.name self.image = cfg.activeComplexEvent.image eventPos = 0 while True: common_functions.standardEventHandling() player._focusForeground() self._drawEventTextBox() x = self.eventBackRect.left + 10 y = self.eventBackRect.top + 10 for i in text[eventPos]: lineSurf = cfg.BASICFONT.render(i, True, cfg.WHITE) lineRect = lineSurf.get_rect() lineRect.topleft = (x, y) cfg.DISPLAYSURF.blit(lineSurf, lineRect) y += 30 if eventPos > len(text) - 2: conSurf = cfg.BASICFONT.render('Continue', True, cfg.WHITE) conRect = conSurf.get_rect() conRect.bottomright = (self.eventBackRect.right - 20, self.eventBackRect.bottom - 5) if conRect.collidepoint(cfg.mouseX, cfg.mouseY) and not cfg.hudMenu: conSurf = cfg.BASICFONT.render('Continue', True, cfg.RED) if cfg.mouseClicked: if prog: for i, v in prog.items(): cfg.PROGRESSIONDICT[i] = v return cfg.DISPLAYSURF.blit(conSurf, conRect) else: nextSurf = cfg.BASICFONT.render('Next', True, cfg.WHITE) nextRect = nextSurf.get_rect() nextRect.bottomright = (self.eventBackRect.right - 20, self.eventBackRect.bottom - 5) if nextRect.collidepoint(cfg.mouseX, cfg.mouseY) and not cfg.hudMenu: nextSurf = cfg.BASICFONT.render('Next', True, cfg.RED) if cfg.mouseClicked: eventPos += 1 cfg.DISPLAYSURF.blit(nextSurf, nextRect) player._displayHud() pygame.display.update() cfg.FPSCLOCK.tick(cfg.FPS)
def statusScreenMenu(game): menu = ['Player', 'Time', 'Money', 'Inventory', 'Jobs', 'Return'] while True: select = None common_functions.standardEventHandling() game._focusForeground() statusMenuBackSurf = pygame.Surface((250, 325)) statusMenuBackRect = statusMenuBackSurf.get_rect() statusMenuBackRect.midtop = (cfg.WINWIDTH / 2, cfg.WINHEIGHT / 8) cfg.DISPLAYSURF.blit(statusMenuBackSurf, statusMenuBackRect) pygame.draw.rect(cfg.DISPLAYSURF, cfg.BLUE, statusMenuBackRect, 2) x = statusMenuBackRect.centerx y = statusMenuBackRect.top + 20 for i in menu: optionSurf = cfg.AR28.render(i, True, cfg.WHITE) optionRect = optionSurf.get_rect() optionRect.midtop = (x, y) if optionRect.collidepoint(cfg.mouseX, cfg.mouseY): optionSurf = cfg.AR28.render(i, True, cfg.RED) pygame.draw.line(cfg.DISPLAYSURF, cfg.WHITE, (optionRect.left + 5, optionRect.bottom + 1), (optionRect.right - 5, optionRect.bottom + 1), 1) if cfg.mouseClicked: select = i cfg.DISPLAYSURF.blit(optionSurf, optionRect) y += 50 if select == 'Player': playerStatusScreen(game) #done elif select == 'Time': timeStatusScreen(game) elif select == 'Money': moneyStatusScreen(game) elif select == 'Inventory': invStatusScreen(game) elif select == 'Jobs': jobStatusScreen(game) #done elif select == 'Return' or cfg.rightClick: return pygame.display.update() cfg.FPSCLOCK.tick(cfg.FPS)
def mainMenuScreen(): while True: select = None common_functions.standardEventHandling() cfg.DISPLAYSURF.fill(cfg.BLACK) mainMenuBackSurf = pygame.Surface((250, 280)) mainMenuBackRect = mainMenuBackSurf.get_rect() mainMenuBackRect.midtop = (cfg.WINWIDTH / 2, cfg.WINHEIGHT / 8) cfg.DISPLAYSURF.blit(mainMenuBackSurf, mainMenuBackRect) pygame.draw.rect(cfg.DISPLAYSURF, cfg.BLUE, mainMenuBackRect, 2) x = mainMenuBackRect.centerx y = mainMenuBackRect.top + 20 for i in cfg.MAINMENUOPTIONS: optionSurf = cfg.AR28.render(i, True, cfg.WHITE) optionRect = optionSurf.get_rect() optionRect.midtop = (x, y) if optionRect.collidepoint(cfg.mouseX, cfg.mouseY): optionSurf = cfg.AR28.render(i, True, cfg.RED) pygame.draw.line(cfg.DISPLAYSURF, cfg.WHITE, (optionRect.left + 5, optionRect.bottom + 1), (optionRect.right - 5, optionRect.bottom + 1), 1) if cfg.mouseClicked: select = i cfg.DISPLAYSURF.blit(optionSurf, optionRect) y += 50 if select == 'Quick Play': player = player_class.Player('Phil') return player elif select == 'New Game': #maybe in v2 #player = characterCreationScreen() #return player pass elif select == 'Load Game': #long way off from this :P pass elif select == 'Options': pass elif select == 'Exit Game': common_functions.terminate() pygame.display.update() cfg.FPSCLOCK.tick(cfg.FPS)
def _playMissionEvent(self, player): eventPos = 0 while True: common_functions.standardEventHandling() player._focusForeground() self._drawEventTextBox() #same text display function x = self.eventBackRect.left + 10 y = self.eventBackRect.top + 10 for i in self.text[eventPos]: lineSurf = cfg.BASICFONT.render(i, True, cfg.WHITE) lineRect = lineSurf.get_rect() lineRect.topleft = (x, y) cfg.DISPLAYSURF.blit(lineSurf, lineRect) y += 30 x = self.eventBackRect.right - 20 y = self.eventBackRect.bottom - 5 if eventPos == len(self.text) - 1: for i in self.choices[::-1]: choiceSurf = cfg.BASICFONT.render(i, True, cfg.WHITE) choiceRect = choiceSurf.get_rect() choiceRect.bottomright = (x, y) if choiceRect.collidepoint(cfg.mouseX, cfg.mouseY) and not cfg.hudMenu: choiceSurf = cfg.BASICFONT.render(i, True, cfg.RED) if cfg.mouseClicked: return i cfg.DISPLAYSURF.blit(choiceSurf, choiceRect) x -= 100 else: nextSurf = cfg.BASICFONT.render('Next', True, cfg.WHITE) nextRect = nextSurf.get_rect() nextRect.bottomright = (self.eventBackRect.right - 20, self.eventBackRect.bottom - 5) if nextRect.collidepoint(cfg.mouseX, cfg.mouseY) and not cfg.hudMenu: nextSurf = cfg.BASICFONT.render('Next', True, cfg.RED) if cfg.mouseClicked: eventPos += 1 cfg.DISPLAYSURF.blit(nextSurf, nextRect) player._displayHud() pygame.display.update() cfg.FPSCLOCK.tick(cfg.FPS)
def _playTextEvent(self, player): eventPos = 0 #tells the function which page of dialogue to read while True: common_functions.standardEventHandling() player._focusForeground() self._drawEventTextBox() #basic text display function. reads one list at a time x = self.eventBackRect.left + 10 y = self.eventBackRect.top + 10 for i in self.text[eventPos]: lineSurf = cfg.BASICFONT.render(i, True, cfg.WHITE) lineRect = lineSurf.get_rect() lineRect.topleft = (x, y) cfg.DISPLAYSURF.blit(lineSurf, lineRect) y += 30 if eventPos > len(self.text) - 2: conSurf = cfg.BASICFONT.render('Continue', True, cfg.WHITE) conRect = conSurf.get_rect() conRect.bottomright = (self.eventBackRect.right - 20, self.eventBackRect.bottom - 5) if conRect.collidepoint(cfg.mouseX, cfg.mouseY) and not cfg.hudMenu: conSurf = cfg.BASICFONT.render('Continue', True, cfg.RED) if cfg.mouseClicked: if self.progression: for i, v in self.progression.items(): cfg.PROGRESSIONDICT[i] = v return cfg.DISPLAYSURF.blit(conSurf, conRect) else: nextSurf = cfg.BASICFONT.render('Next', True, cfg.WHITE) nextRect = nextSurf.get_rect() nextRect.bottomright = (self.eventBackRect.right - 20, self.eventBackRect.bottom - 5) if nextRect.collidepoint(cfg.mouseX, cfg.mouseY) and not cfg.hudMenu: nextSurf = cfg.BASICFONT.render('Next', True, cfg.RED) if cfg.mouseClicked: eventPos += 1 cfg.DISPLAYSURF.blit(nextSurf, nextRect) player._displayHud() pygame.display.update() cfg.FPSCLOCK.tick(cfg.FPS)
def mapMenu(player, currentHub, destination): while True: common_functions.standardEventHandling() displayMapBackground(currentHub, destination) action = displayTravelMenu(player, currentHub, destination) if action: return action pygame.display.update() cfg.FPSCLOCK.tick(cfg.FPS)
def _displayJobBoard(self, game): jobPreview = None jobIndex = 0 while True: common_functions.standardEventHandling() game._focusForeground() job = self.availableJobs[jobIndex] #make things easier to read action = job._jobPosting() if action == 'Take Job': job.startDay = game.day job.dueDay = job.startDay + job.allowedTime game.activeJobs.append(job) cfg.PROGRESSIONDICT[job.jobName] = 0 return elif action == 'Stop Looking': return nextSurf = cfg.IMAGEDICT['Right One'] nextRect = nextSurf.get_rect() nextRect.midright = (cfg.WINWIDTH - 20, cfg.WINHEIGHT / 2) if nextRect.collidepoint(cfg.mouseX, cfg.mouseY) and not cfg.hudMenu: nextSurf = cfg.IMAGEDICT['Right Two'] if cfg.mouseClicked: jobIndex += 1 if jobIndex > len(self.availableJobs) - 1: jobIndex = 0 cfg.DISPLAYSURF.blit(nextSurf, nextRect) prevSurf = cfg.IMAGEDICT['Left One'] prevRect = prevSurf.get_rect() prevRect.midleft = (20, cfg.WINHEIGHT / 2) if prevRect.collidepoint(cfg.mouseX, cfg.mouseY) and not cfg.hudMenu: prevSurf = cfg.IMAGEDICT['Left Two'] if cfg.mouseClicked: jobIndex -= 1 if jobIndex < 0: jobIndex = len(self.availableJobs) - 1 cfg.DISPLAYSURF.blit(prevSurf, prevRect) game._displayHud() pygame.display.update() cfg.FPSCLOCK.tick(cfg.FPS)
def campScreen(player): while True: common_functions.standardEventHandling() cfg.DISPLAYSURF.blit(cfg.IMAGEDICT['Camp'], (0, 0)) player._displayPlayerStats() if cfg.mouseClicked: return pygame.display.update() cfg.FPSCLOCK.tick(cfg.FPS)
def _playChoiceEvent(self, player, location): eventPos = 0 while True: common_functions.standardEventHandling() location._locationBackground() player._displayHud() self._drawEventTextBox() #same text display function x = self.eventBackRect.left + 10 y = self.eventBackRect.top + 10 for i in self.text[eventPos]: lineSurf = cfg.BASICFONT.render(i, True, cfg.WHITE) lineRect = lineSurf.get_rect() lineRect.topleft = (x, y) cfg.DISPLAYSURF.blit(lineSurf, lineRect) y += 30 #if there are pages of text remaining, the actions function like a simple text event #otherwise, the event choices are presented x = self.eventBackRect.right - 20 y = self.eventBackRect.bottom - 5 if eventPos == len(self.text) - 1: for i in list(self.choices)[::-1]: choiceSurf = cfg.BASICFONT.render(i, True, cfg.WHITE) choiceRect = choiceSurf.get_rect() choiceRect.bottomright = (x, y) if choiceRect.collidepoint(cfg.mouseX, cfg.mouseY): choiceSurf = cfg.BASICFONT.render(i, True, cfg.RED) if cfg.mouseClicked: return self.choices[i] cfg.DISPLAYSURF.blit(choiceSurf, choiceRect) x -= 100 else: conSurf = cfg.BASICFONT.render('Continue', True, cfg.WHITE) conRect = conSurf.get_rect() conRect.bottomright = (self.eventBackRect.right - 5, self.eventBackRect.bottom - 5) if conRect.collidepoint(cfg.mouseX, cfg.mouseY): conSurf = cfg.BASICFONT.render('Continue', True, cfg.RED) if cfg.mouseClicked: eventPos += 1 cfg.DISPLAYSURF.blit(conSurf, conRect) pygame.display.update() cfg.FPSCLOCK.tick(cfg.FPS)
def _selectJobMenu(self, game, jobs): while True: common_functions.standardEventHandling() cfg.DISPLAYSURF.blit(self.image, (0, 0)) nameBackSurf = pygame.Surface((280, 60)) nameBackSurf.set_alpha(140) nameBackSurf.fill(cfg.BLACK) nameBackRect = nameBackSurf.get_rect() nameBackRect.midtop = (cfg.WINWIDTH / 2, 10) nameSurf = cfg.AR25.render(self.name, True, cfg.WHITE) nameRect = nameSurf.get_rect() nameRect.center = nameBackRect.center cfg.DISPLAYSURF.blit(nameBackSurf, nameBackRect) pygame.draw.rect(cfg.DISPLAYSURF, cfg.WHITE, nameBackRect, 2) cfg.DISPLAYSURF.blit(nameSurf, nameRect) backSurf = pygame.Surface((400, 475)) backSurf.fill(cfg.BLACK) backSurf.set_alpha(120) backRect = backSurf.get_rect() backRect.midtop = (cfg.WINWIDTH / 2, 100) cfg.DISPLAYSURF.blit(backSurf, backRect) pygame.draw.rect(cfg.DISPLAYSURF, cfg.WHITE, backRect, 2) y = backRect.top + 15 for i in jobs: jobBackSurf = pygame.Surface((380, 80)) jobBackSurf.fill(cfg.BLUE) jobBackSurf.set_alpha(55) jobBackRect = jobBackSurf.get_rect() jobBackRect.midtop = (backRect.centerx, y) jobSurf = cfg.AR25.render(i.jobName, True, cfg.WHITE) jobRect = jobSurf.get_rect() jobRect.midleft = (jobBackRect.left + 15, jobBackRect.centery) if jobBackRect.collidepoint(cfg.mouseX, cfg.mouseY): jobBackSurf.set_alpha(205) if cfg.mouseClicked: return i cfg.DISPLAYSURF.blit(jobBackSurf, jobBackRect) pygame.draw.rect(cfg.DISPLAYSURF, cfg.WHITE, jobBackRect, 1) cfg.DISPLAYSURF.blit(jobSurf, jobRect) y += 100 pygame.display.update() cfg.FPSCLOCK.tick(cfg.FPS)
def displayTravelMenu(player, destination): """ pops up after clicking on a valid destination. shows travel info and waits for a action choice """ while True: common_functions.standardEventHandling() displayMapBackground(player, destination) action = displayConfirmTravelMenu(player, destination) if action: return action pygame.display.update() cfg.FPSCLOCK.tick(cfg.FPS)
def worldMap(player): while True: common_functions.standardEventHandling() destination = displayMap(player) if destination: action = displayTravelMenu(player, destination) if action == 'Start Trip': return destination pygame.display.update() cfg.FPSCLOCK.tick(cfg.FPS)
def _playInnEvent(self, player): #waits for you to choose yes or no action = None while not action: common_functions.standardEventHandling() player._focusForeground() self._drawEventTextBox() x = self.eventBackRect.left + 10 y = self.eventBackRect.top + 10 for i in self.text: lineSurf = cfg.BASICFONT.render(i, True, cfg.WHITE) lineRect = lineSurf.get_rect() lineRect.topleft = (x, y) cfg.DISPLAYSURF.blit(lineSurf, lineRect) y += 30 x = self.eventBackRect.right - 45 y = self.eventBackRect.bottom - 5 for i in self.actions[::-1]: actionSurf = cfg.BASICFONT.render(i, True, cfg.WHITE) actionRect = actionSurf.get_rect() actionRect.bottomright = (x, y) if actionRect.collidepoint(cfg.mouseX, cfg.mouseY) and not cfg.hudMenu: actionSurf = cfg.BASICFONT.render(i, True, cfg.RED) if cfg.mouseClicked: action = i cfg.DISPLAYSURF.blit(actionSurf, actionRect) x -= 120 player._displayHud() pygame.display.update() cfg.FPSCLOCK.tick(cfg.FPS) if action == 'Yes': self._processInn(player) return
def beforeJob(game): message = ["You arrive ready to work on this contract..."] while True: common_functions.standardEventHandling() cfg.DISPLAYSURF.blit(game.bgImage, (0, 0)) backSurf = pygame.Surface((600, 450)) backSurf.fill(cfg.BLUE) backSurf.set_alpha(200) backRect = backSurf.get_rect() backRect.midtop = (cfg.WINWIDTH / 2, 25) cfg.DISPLAYSURF.blit(backSurf, backRect) pygame.draw.rect(cfg.DISPLAYSURF, cfg.WHITE, backRect, 2) y = backRect.top + 15 for i in message: lineSurf = cfg.BASICFONT.render(i, True, cfg.WHITE) lineRect = lineSurf.get_rect() lineRect.topleft = (backRect.left + 10, y) cfg.DISPLAYSURF.blit(lineSurf, lineRect) y += 30 conBackSurf = pygame.Surface((150, 75)) conBackRect = conBackSurf.get_rect() conBackRect.topright = (backRect.right - 15, backRect.bottom + 5) conSurf = cfg.BASICFONT.render('Continue', True, cfg.WHITE) conRect = conSurf.get_rect() conRect.center = conBackRect.center if conBackRect.collidepoint(cfg.mouseX, cfg.mouseY): conBackSurf.fill(cfg.GREEN) conBackSurf.set_alpha(55) if cfg.mouseClicked: return cfg.DISPLAYSURF.blit(conBackSurf, conBackRect) cfg.DISPLAYSURF.blit(conSurf, conRect) pygame.draw.rect(cfg.DISPLAYSURF, cfg.WHITE, conBackRect, 2) pygame.display.update() cfg.FPSCLOCK.tick(cfg.FPS)
def _shopProcessing(self, player): while True: common_functions.standardEventHandling() player._focusForeground() item = self._drawShopBox() if item: if item == 'Exit': return else: pass #will do more with this when items are more of a thing. no reason to chart this out before items are done. player._displayHud() pygame.display.update() cfg.FPSCLOCK.tick(cfg.FPS)
def locationScreen(player, location): currentEvents = updateCurrentEvents(location) location.events = currentEvents #i can do this better later while True: common_functions.standardEventHandling() event = location._displayLocationScreen() player._displayPlayerStats() if event: if event == 'Leave': return else: playEvent(player, event, location) pygame.display.update() cfg.FPSCLOCK.tick(cfg.FPS)
def hubScreen(player, hub): """ reads the given hub class object and displays available locations. also has options for opening the world map or working on a mission. """ while True: common_functions.standardEventHandling() location = hub._displayHubScreen() #main display for hub options player._displayHud() #always present main character hud if location: if location == 'Leave': #returned only if 'Leave Hub' is selected return 'Leave' else: for i in locations.LOCLIST: #probably a better way to do this, but connects dots to lead into the correct location if i.name == location and i.hub == hub.name: location = i locationScreen(player, location) #location home screen pygame.display.update() cfg.FPSCLOCK.tick(cfg.FPS)
def hubScreen(player, hub): """ reads the given hub class object and displays available locations. also has options for returning options for world map or mission. """ player.bgImage = hub.image while True: common_functions.standardEventHandling() action = hub._displayHubScreen() #main display for hub options player._displayHud() #always present main character hud if action: if action == 'World Map': #returned only if 'World Map' is selected return action else: location_screen.locationScreen(player, action) #location home screen pygame.display.update() cfg.FPSCLOCK.tick(cfg.FPS)
def _playTextEvent(self, player, location): eventPos = 0 #tells the function which page of dialogue to read while True: common_functions.standardEventHandling() location._locationBackground() player._displayHud() self._drawEventTextBox() #basic text display function. reads one list at a time x = self.eventBackRect.left + 10 y = self.eventBackRect.top + 10 for i in self.text[eventPos]: lineSurf = cfg.BASICFONT.render(i, True, cfg.WHITE) lineRect = lineSurf.get_rect() lineRect.topleft = (x, y) cfg.DISPLAYSURF.blit(lineSurf, lineRect) y += 30 #the only option is to continue advancing through the text #progression is updated before returning because events can be accessed in different ways conSurf = cfg.BASICFONT.render('Continue', True, cfg.WHITE) conRect = conSurf.get_rect() conRect.bottomright = (self.eventBackRect.right - 20, self.eventBackRect.bottom - 5) if conRect.collidepoint(cfg.mouseX, cfg.mouseY): conSurf = cfg.BASICFONT.render('Continue', True, cfg.RED) if cfg.mouseClicked: eventPos += 1 if eventPos > len(self.text) - 1: #advancing through the last page returns the function if self.progression: for i, v in self.progression.items(): cfg.PROGRESSIONDICT[i] = v return cfg.DISPLAYSURF.blit(conSurf, conRect) pygame.display.update() cfg.FPSCLOCK.tick(cfg.FPS)
def titleScreen(): backgroundImageOne = pygame.image.load('images/title/title1.png') backgroundImageTwo = pygame.image.load('images/title/title2.png') titleBackSurf = pygame.Surface((780, 100)) titleBackRect = titleBackSurf.get_rect() titleBackRect.topleft = (10, 10) titleSurf = cfg.AR74.render('Zero to Hero', True, cfg.WHITE) titleRect = titleSurf.get_rect() titleRect.center = titleBackRect.center pygame.mixer.music.load('bgm/title.ogg') pygame.mixer.music.play(-1, 0.0) timer = 0 while True: common_functions.standardEventHandling() if timer > 40 and timer < 60: cfg.DISPLAYSURF.blit(backgroundImageTwo, (0, 0)) else: cfg.DISPLAYSURF.blit(backgroundImageOne, (0, 0)) cfg.DISPLAYSURF.blit(titleBackSurf, titleBackRect) cfg.DISPLAYSURF.blit(titleSurf, titleRect) timer += 1 if timer > 200: timer = 0 if cfg.mouseClicked: pygame.mixer.music.fadeout(500) return pygame.display.update() cfg.FPSCLOCK.tick(cfg.FPS)
def _playShopEvent(self, player): action = None while not action: common_functions.standardEventHandling() player._focusForeground() self._drawEventTextBox() x = self.eventBackRect.left + 10 y = self.eventBackRect.top + 10 for i in self.text: lineSurf = cfg.BASICFONT.render(i, True, cfg.WHITE) lineRect = lineSurf.get_rect() lineRect.topleft = (x, y) cfg.DISPLAYSURF.blit(lineSurf, lineRect) y += 30 shopSurf = cfg.BASICFONT.render('Shop', True, cfg.WHITE) shopRect = shopSurf.get_rect() shopRect.bottomright = (self.eventBackRect.right - 45, self.eventBackRect.bottom - 5) if shopRect.collidepoint(cfg.mouseX, cfg.mouseY) and not cfg.hudMenu: shopSurf = cfg.BASICFONT.render('Shop', True, cfg.RED) if cfg.mouseClicked: action = 'Shop' cfg.DISPLAYSURF.blit(shopSurf, shopRect) player._displayHud() pygame.display.update() cfg.FPSCLOCK.tick(cfg.FPS) self._shopProcessing(player) return
def _displayJobBoard(self, player): jobPreview = None while True: common_functions.standardEventHandling() player._focusForeground() if not jobPreview: jobPreview = self._drawAvailableJobs() else: action = jobPreview._viewJobDetails() if action == 'Take Job': player.activeJobs.append(jobPreview) return elif action == 'Keep Looking': jobPreview = None player._displayHud() pygame.display.update() cfg.FPSCLOCK.tick(cfg.FPS)