def success(self, ev, mount): self.clock.tick_busy_loop() self.play = False self.win = True self.newchar.mountsClimbed += 1 self.newchar.setPosition(0) path = displaylib.getpath("Assets", "success.png") winim = displaylib.image(path, 0) mounttext = displaylib.font(24, mount.name, (255, 255, 255), True) routetext = displaylib.font( 20, "You climbed: " + str(mount.routeLength) + " m", (255, 255, 255), False) # timetext = displaylib.font(24, ("Time: {0:.2f} minutes").format(self.clock.get_time()), (255,255,255), False) while (True): for event in pygame.event.get(): ev.on_event(event, self.game, self) self.game._display_surf.fill([0, 0, 0]) self.game._display_surf.blit( mounttext.text_surf, ((self.game.windowSize[0] / 2 - mounttext.text_surf.get_width()), self.game.windowSize[1] / 2)) self.game._display_surf.blit( routetext.text_surf, ((self.game.windowSize[0] / 2 - routetext.text_surf.get_width()), self.game.windowSize[1] / 2 + 30)) # self.game._display_surf.blit(timetext.text_surf, (( # self.game.windowSize[0]/2 - timetext.text_surf.get_width()), self.game.windowSize[1]/2 + 60)) pygame.display.update() if (self.game.onHomeScreen == True): break
def rest(self, ev, climber, mount): restpath = displaylib.getpath("Assets", "resting.png") restimage = displaylib.image(restpath, 0) mnttxt = displaylib.font(20, "Resting on " + mount.name, (255, 255, 255), True) self.isResting = True w = (self.game.windowSize[1] / restimage.h() * 1.5) * restimage.w() restimage._image_surf = pygame.transform.scale( restimage._image_surf, (int(w), int(self.game.windowSize[1] * .9))) while (self.isResting): for event in pygame.event.get(): ev.on_event(event, self.game, self) # while(climber.getHealth() < 100): resttxt = displaylib.font( 20, "Your Health... " + str(climber.getHealth()), (255, 255, 255), True) self.game._display_surf.fill([0, 0, 0]) self.game._display_surf.blit(restimage._image_surf, (300, 100)) self.game._display_surf.blit(mnttxt.text_surf, ((self.game.windowSize[0] * .6), 0)) self.game._display_surf.blit(resttxt.text_surf, ((self.game.windowSize[0] * .2), 0)) pygame.display.update() pygame.time.delay(1200) self.resnum = self.progress.calcRestProg(climber) print("Resting Players Health... " + str(self.resnum)) climber.setHealth(self.resnum) if (climber.getHealth() >= 100): fresttxt = displaylib.font(20, "Your health is full", (255, 255, 255), True) print("Climber's Health is already at Max ") climber.setHealth(100) self.game._display_surf.fill([0, 0, 0]) self.game._display_surf.blit( fresttxt.text_surf, ((self.game.windowSize[0] * 3), 0)) pygame.display.update() self.isResting = False
def on_init(self): self.onHomeScreen = True pygame.init() pygame.mixer.init() pygame.display.set_caption("Ascension (demo)") self._display_surf = pygame.display.set_mode( (1280, 720), pygame.HWSURFACE | pygame.DOUBLEBUF | pygame.RESIZABLE) if os.name == 'nt': hwnd = win32gui.GetForegroundWindow() win32gui.ShowWindow(hwnd, win32con.SW_MAXIMIZE) self.windowSize = [ self._display_surf.get_width(), self._display_surf.get_height()] self._running = True self.openingMusic = displaylib.music(displaylib.getpath("Assets","tobias_weber_-_Between_Worlds_(Instrumental).mp3")) openPath = displaylib.getpath("Assets", "ascensionopenscreen.png") self.openingScreen = displaylib.image(openPath, 0) self.Ascensiontitletext = displaylib.font( 75, "Ascension", (0, 0, 0), False) self.startleveltext = displaylib.font( 30, "Press Enter to start level", (0, 0, 0), False)
def textRender(self): maxtxt = displaylib.font(20, "99999m", [255, 255, 255], False) try: falltxt = displaylib.font(20, ("{0:^5.0f}m".format(self.fallLength)), [255, 255, 255], False) healthtxt = displaylib.font(20, ("{0:>3}".format(self.newchar.health)), [255, 255, 255], False) posText = displaylib.font( 20, ("{0:^5.0f}m".format(self.newchar.position)), [255, 255, 255], False) progText = displaylib.font( 25, ("Progress: {0:<7.0f} %".format(self.progress.getProgress())), [255, 255, 255], False) except: posText = displaylib.font(20, ("{0:^5.0f}m".format(0)), [255, 255, 255], False) falltxt = displaylib.font(20, ("{0:^5.0f}m".format(0)), [255, 255, 255], False) healthtxt = displaylib.font(20, ("{0:>3}".format(100)), [255, 255, 255], False) progText = displaylib.font(25, "Progress: 0.0 %", [255, 255, 255], False) w = self.game.windowSize[0] / 2 - (self.levelMount.hudImage.w() / 2) h = (self.game.windowSize[1] * .05) + 20 self.game._display_surf.blit(posText.text_surf, ((w + self.levelMount.hudImage.w() / 4 + maxtxt.text_surf.get_width() / 3), h)) self.game._display_surf.blit(falltxt.text_surf, ((w + self.levelMount.hudImage.w() / 2 + maxtxt.text_surf.get_width() / 2), h)) self.game._display_surf.blit( healthtxt.text_surf, ((w + maxtxt.text_surf.get_width() / 2), h)) self.game._display_surf.blit(progText.text_surf, ((self.game.windowSize[0] / 2), 680))
def death(self, ev): self.play = False self.dead = True self.newchar.position = 0 self.game._display_surf.fill([0, 0, 0]) pygame.display.flip() deathtext = displaylib.font(36, "You have died", (255, 255, 255), False) while (True): for event in pygame.event.get(): ev.on_event(event, self.game, self) self.game._display_surf.fill([0, 0, 0]) self.game._display_surf.blit( deathtext.text_surf, (self.game.windowSize[0] / 2, self.game.windowSize[1] / 2)) pygame.display.flip() if (self.game.onHomeScreen == True): break