def renderDialog(self, text, right=1, bottom=1): area = (self.window.width - len(text) - 3 - right, self.window.height - 4 - bottom, len(text)+2, 3) r = pygcurse.PygcurseTextbox(self.window, area, fgcolor=(150, 150, 150), bgcolor=(30, 30, 30), text=text, border="else", shadow=1) r.update() self.window.update()
def init_ui(): #Making sure we can access the variables global gamewindow global imgfile global image global box global sidebox global print global input global sound #Defining the UI gamewindow = pygcurse.PygcurseWindow(120, 40) gamewindow.font = pygame.font.Font('terminus.ttf', 14) print = gamewindow.pygprint input = gamewindow.input imgfile = 'bridge.png' image = pygame.image.load(imgfile) pygame.display.set_caption('Universe Mission') box = pygcurse.PygcurseTextbox(gamewindow, (1, 27, 118, 12), fgcolor='black', bgcolor=(148,148,148), border='basic', wrap=True, marginleft=1, marginright=1, margintop=1, caption='Universe Mission') sidebox = pygcurse.PygcurseTextbox(gamewindow, (100, 1, 19, 25), fgcolor='white', bgcolor=(65,65,65), border='basic', wrap=True, marginleft=1, marginright=1, margintop=1, caption='Inventory') box.text = 'This is the Universe Mission test text box.' sidebox.text = 'Tools Mops Other things' sound.play(-1)
def main(): global FPSCLOCK, WINDOWSURF, BOARDBOX pygame.init() FPSCLOCK = pygame.time.Clock() WINDOWSURF = pygcurse.PygcurseWindow(WINDOWWIDTH, WINDOWHEIGHT, 'Textris', font=pygame.font.Font(None, 24)) WINDOWSURF.autoupdate = False BOARDBOX = pygcurse.PygcurseTextbox( WINDOWSURF, (LEFTMARGIN - 1, TOPMARGIN - 1, BOARDWIDTH + 2, BOARDHEIGHT + 2)) showTextScreen('Textris') while True: # main game loop runGame() showTextScreen('Game Over')
def main(): global FPSCLOCK, WINDOWSURF, BOARDBOX pygame.init() FPSCLOCK = pygame.time.Clock() WINDOWSURF = pygcurse.PygcurseWindow(WINDOWWIDTH, WINDOWHEIGHT, 'Textris', font=pygame.font.Font(None, 24)) WINDOWSURF.autoupdate = False BOARDBOX = pygcurse.PygcurseTextbox(WINDOWSURF, (LEFTMARGIN-1, TOPMARGIN-1, BOARDWIDTH+2, BOARDHEIGHT+2)) showTextScreen('Textris') while True: # main game loop if random.randint(0, 1) == 0: pygame.mixer.music.load('tetrisb.mid') else: pygame.mixer.music.load('tetrisc.mid') pygame.mixer.music.play(-1, 0.0) runGame() pygame.mixer.music.stop() showTextScreen('Game Over')
def showMessage(self, header, message, width=20, height=10): """ This function will show a pop up message in the middle of the screen. It waits for the user to acknowledge the message by hitting enter or escape """ # store the current window for easy restore when we are done self.win.push_surface() # Show in the middle of the screen. menu_region = (self.win.centerx / 2, self.win.centery / 2 + (height / 2), width, height) textbox = pygcurse.PygcurseTextbox(self.win, region=menu_region, fgcolor=colors.white, bgcolor=colors.dark_sepia, caption=header, text=message, margin=2, wrap=True, border='.') # tell the textbox to draw itself onto our win canvas textbox.update() # update the screen and handle keypresses self.win.update() menu_busy = True result = '' while menu_busy: key = pygcurse.waitforkeypress(LIMIT_FPS) print(key) if key == 'escape': result = 'Escape' break elif key in ('enter', 'return'): result = 'Enter' break # restore to original window self.win.pop_surface() return result
# Simplified BSD License, Copyright 2011 Al Sweigart import sys import os sys.path.append(os.path.abspath('..')) import pygcurse, pygame from pygame.locals import * win = pygcurse.PygcurseWindow(40, 25) win.autoblit = False box = pygcurse.PygcurseTextbox(win, (4, 4, 20, 14), fgcolor='red', bgcolor='black', border='basic', wrap=True, marginleft=3, caption='Hello world!') box.text = 'The Ojibway aboriginal people in North America used cowry shells which they called sacred Miigis Shells or whiteshells in Midewiwin ceremonies, and the Whiteshell Provincial Park in Manitoba, Canada is named after this type of shell. There is some debate about how the Ojibway traded for or found these shells, so far inland and so far north, very distant from the natural habitat. Oral stories and birch bark scrolls seem to indicate that the shells were found in the ground, or washed up on the shores of lakes or rivers. Finding the cowry shells so far inland could indicate the previous use of them by an earlier tribe or group in the area, who may have obtained them through an extensive trade network in the ancient past. Petroforms in the Whiteshell Provincial Park may be as old as 8,000 years.' eraseBox = False while True: for event in pygame.event.get(): # the event loop if event.type == QUIT or event.type == KEYDOWN and event.key == K_ESCAPE: pygame.quit() sys.exit() if event.type == KEYDOWN: if event.key == K_UP: box.height -= 1 elif event.key == K_DOWN: box.height += 1 elif event.key == K_LEFT:
win.write(char) win.write("\n") pygcurse.waitforkeypress() FPS = 25 WINDOWWIDTH = 26 WINDOWHEIGHT = 27 BOARDWIDTH = 10 BOARDHEIGHT = 20 BLANK = None LEFTMARGIN = 4 TOPMARGIN = 4 MOVESIDEWAYSFREQ = 0.15 MOVEDOWNFREQ = 0.15 print(pygame.color.THECOLORS.keys()) WINDOWSURF = pygcurse.PygcurseWindow(80, 30, 'Textris', font=pygame.font.Font(None, 12)) WINDOWSURF.autoupdate = False BOARDBOX = pygcurse.PygcurseTextbox( WINDOWSURF, (LEFTMARGIN - 1, TOPMARGIN - 1, 10, 10), border="rouded", bgcolor=pygame.color.THECOLORS['springgreen4']) BOARDBOX.update() pygcurse.waitforkeypress()
def renderAll(self): """ This function renders the main screen """ #TODO: display names of objects under the mouse # Frost: this would require running this loop constantly which is not # happening at the moment. Currently it pauses to wait for the player to # hit a key. level = self.game.currentLevel for tile in level.map.explored_tiles: if tile.blocked: # these are wall tiles if tile.inView: # the player can see these bg_color = COLOR_LIGHT_WALL else: # these are out of sight bg_color = COLOR_DARK_WALL else: # and these are floor tiles... if tile.inView: bg_color = COLOR_LIGHT_GROUND else: bg_color = COLOR_DARK_GROUND self.win.putchar(' ', tile.x, tile.y, bgcolor=bg_color) # draw any actors standing on this tile. # includes Monsters and Portals for myActor in tile.actors: if myActor.inView: self.win.putchar(myActor.char, tile.x, tile.y, fgcolor=myActor.color) #Redraw player character (makes sure it is on top) player = self.game.player self.win.putchar(player.char, player.tile.x, player.tile.y, fgcolor=player.color) # show game messages via a PygcurseTextbox. message_box = pygcurse.PygcurseTextbox(self.win, region=MESSAGE_PANEL_REGION, fgcolor=colors.white, bgcolor=colors.black, text='\n'.join(self.messages), wrap=True, border='basic', margin=0) message_box.update() if player is not None: #Player health bar self.renderBar(1, PANEL_Y + 1, BAR_WIDTH, 'HP', player.currentHitPoints, player.maxHitPoints, colors.dark_red, colors.darker_gray) #Player xp bar self.renderBar(1, PANEL_Y + 2, BAR_WIDTH, 'XP', player.xp, player.nextLevelXp, colors.darker_green, colors.darker_gray) if self.game.currentLevel is not None: #Dungeon level self.win.putchars(str(self.game.currentLevel.name), 2, 2) #show on-going effects for effectTuple in self.effects: effect, effectTiles = effectTuple #TODO: Create specific 'flashing' implementations for different effect types. if effect.targetType == EffectTarget.SELF: self._flashBgColor(effect.effectColor, effectTiles) elif effect.targetType == EffectTarget.AREA: self._flashBgColor(effect.effectColor, effectTiles) self._effects = [] self.win.update()
def showMenu(self, header, options, width=20, height=10): """ This function will show a menu. The application waits for user input before returning the selected option. The function will return None if the user escapes the menu. Arguments header - String, text for the header options - String list, text for the options width - Width (in characters) of the menu box """ if len(options) > 26: raise ValueError('Cannot have a menu with more than 26 options.') #store the current view self.win.push_surface() # Show in the middle of the screen. menu_region = (self.win.centerx / 2, self.win.centery / 2 + (height / 2), width, height) # a list from a-n, where n is the length of our options hotkeys = [chr(ord('a') + i) for i in range(0, len(options))] # build a menu from the options list by prefixing each with a hotkey # then join them together with newlines. menu_choices = [] for counter, option_text in enumerate(options): menu_choices.append('(%s) %s' % ((hotkeys[counter]), option_text)) menu_choices = '\n'.join(menu_choices) # construct the menu as a textbox object. It recognizes newlines. # this guy draw a nice border for us too. #TODO: Frost: there is a problem here # the menu_region might be too small to contain all the menu items. # The height has to be calculated based on the number of menu items. # I think the showMessage function suffers from the same problem # (if you give it a really long text) txt = pygcurse.PygcurseTextbox(self.win, region=menu_region, fgcolor=colors.white, bgcolor=colors.transparent, caption=header, text=menu_choices, margin=2, wrap=True, border='.') txt.update() # update the screen and handle keypresses self.win.update() menu_busy = True while menu_busy: key = pygcurse.waitforkeypress(LIMIT_FPS) if key is None or key == 'escape': return_value = None break if key in hotkeys: return_value = hotkeys.index(key) break #go back to the previous view self.win.pop_surface() return return_value