def __init__(self, g): self.g = g #store globals self.dlog = dialog.ChoiceDialog( self.g, "standard") #initialize new dialog for choices #initialize new surface to draw stuff on self.surf = pygame.Surface((settings.screen_x, settings.screen_y)) #load and create surfaces for all the title screen parts self.logo = data.load_image("titlescreen/bronzelogo.png") self.logo.convert_alpha() self.bg = data.load_image("titlescreen/background.png") self.bg.convert() self.logomask = data.load_image("titlescreen/logomask.png") self.logomask.convert() self.shine = data.load_image("titlescreen/shine.png") self.shine.convert_alpha() self.textbg = data.load_image("titlescreen/fadetoblack.png") self.textbg.convert_alpha() #create a surface to draw the shine on with the same dimensions as the logo self.shinesurf = pygame.Surface(self.logo.get_size(), SRCALPHA) #create a surface for the text self.textsurf = pygame.Surface(self.textbg.get_size(), SRCALPHA) #now, we need to draw Press X! on screen f = font.Font("fonts/selfdialog_font.xml") #load font to draw with f.render("Press X!", self.textbg, (15, 2)) #calculate dimensions for everything self.shine_y = (self.logo.get_height() - self.shine.get_height()) / 2 self.shine_x = -40 #current x position of shine #set up variables for fading text self.fadein = True self.textopacity = 10 #opacity goes backwards for faster drawing self.check_environment() #make sure the environment is up to snuff self.start_main() #start main function
def handleDittoError(e, screen): """Deal with a problem with the files supplied to Ditto""" #fill the screen white screen.fill((255, 255, 255)) pygame.display.flip() #try to use the game font to write the problem on the screen try: f = font.Font(os.path.join(settings.path, "data", globs.FONT)) lines = e.describe() i = 0 for line in lines: f.writeText(line, screen, (10, 10 + (i * (f.height + 2)))) i += 1 pygame.display.flip() raw_input() #if that doesn't work, just print out to the console except: print "Ditto ran into a problem!" print "-" * 20 lines = e.describe() for line in lines: print line print "-" * 20 raw_input("Press enter to exit")
def __init__(self, menu): self.game = menu.game #store parameters self.g = menu.g self.menu = menu #initialize stuff self.font = font.Font( "fonts/dialog_font.xml") #create font for drawing
def setup(self, game): """ Get the script engine ready to run scripts. game - the Game object to run scripts on. """ #store game object self.game = game self.font = font.Font(os.path.join(settings.path, "data", globs.FONT)) #create the font #initialise variables needed to run self.running = False self.queue = [] self.currentCommand = 0 self.waiting = False self.waitingFor = None self.countDown = 0 #initialise script variables self.variables = {} self.result = None #determine behaviour scripts tree = data.getTree(globs.BEHAVIOURS) root = tree.getroot() self.behaviours = {} for behaviourNode in data.getChildren(root, "behaviour", globs.BEHAVIOURS): i = data.getAttr(behaviourNode, "index", data.D_INT, globs.BEHAVIOURS) s = data.getChild(behaviourNode, "script", globs.BEHAVIOURS) self.behaviours[i] = Script(s, False)
def gameInfo(self, information): self.gameinfo = information self.Status = False self.nextStage = 'mainmenu' self.font = font.Font("gameover", self.gameinfo) self.time = 0 self.duration = 4000
def _setFont(self, aFont): if isinstance(aFont, dict): aFont = font.Font(aFont, aParent=self) else: # Bind the font to this widget. aFont._parent = self self._font = aFont aWxFont = aFont._getFont() self.SetFont(aWxFont)
def default_font(self): """ Return a default font. """ self.__def_font = font.Font() self.__def_font.font = "Arial" self.__def_font.slant = cairo.FONT_SLANT_NORMAL self.__def_font.weight = cairo.FONT_WEIGHT_NORMAL self.__def_font.size = 15 return self.__def_font
def gameInfo(self, information): self.gameinfo = information self.Status = False self.nextStage = 'startgame' self.font = font.Font("story", self.gameinfo) self.time = pygame.time.get_ticks() self.duration = 8000
def __init__(self): """ Constructor of Transition and default values will be initialised. """ # call constructor of parent class super(Transition, self).__init__() self._dim = [0., 0.] self._rate = 1. self._font_rate = font.Font() #self._get_default_font()
def __init__(self, screen, infoNode, poke): """ aa screen - the screen to blit to. infoNode - the <info> node from the menu XML file. poke - the pokemon. """ self.screen = screen fFont = font.Font( os.path.join(settings.path, "data", data.getAttr(infoNode, "font", data.D_STRING))) size = ((self.screen.get_width() / 2) - (OBJECTBUFFER * 2), (self.screen.get_height() / 2) - (OBJECTBUFFER * 2)) fn = os.path.join(settings.path, "data", data.getAttr(infoNode, "box", data.D_STRING)) self.infoBox = box.Box(size, fn).convert(self.screen) info = { "No.": data.getAttr(poke.speciesNode, "dex", data.D_STRING), "Name": poke.getName(), "Type": "TODO", "OT": str(poke.trainer), "ID No.": str(poke.trainerID), "Item": str(poke.heldItem) } order = ["No.", "Name", "Type", "OT", "ID No.", "Item"] pointerY = BORDER for inf in order: fFont.writeText(inf, self.infoBox, (BORDER, pointerY)) text = info[inf] fFont.writeText( text, self.infoBox, (size[0] - fFont.calcWidth(text) - BORDER, pointerY)) pointerY += fFont.height + LINEBUFFER self.infoBoxLocation = (self.screen.get_width() - size[0] - OBJECTBUFFER, OBJECTBUFFER) size = (self.screen.get_width() - (OBJECTBUFFER * 2), (self.screen.get_height() / 2) - (OBJECTBUFFER * 2)) self.memoBox = box.Box(size, fn).convert(self.screen) pointerY = BORDER fFont.writeText("%s nature." % "TODO", self.memoBox, (BORDER, pointerY)) pointerY += fFont.height + LINEBUFFER fFont.writeText("Met in %s." % "TODO", self.memoBox, (BORDER, pointerY)) self.memoBoxLocation = (OBJECTBUFFER, self.screen.get_height() - size[1] - OBJECTBUFFER)
def gameInfo(self,information): self.gameinfo=information self.Status=False self.nextStage='startgame' self.font=font.Font("win",self.gameinfo) self.magician=pygame.image.load(r'magician.png') self.hero=pygame.image.load(r'hero.png') self.time=pygame.time.get_ticks() self.duration=4000 music.s5.play()
def __init__(self, text, screen, drawCursor=True): """ Create the dialog box and load cursors. text - a list of lines of text to go in the dialog. font - the font with which to write the text. screen - the surface to draw the dialog onto. soundManager - the sound manager. drawCursor - whether a continuation cursor should be drawn when the text has finished writing. """ #store variables we'll need again self.text = text.split(LINESEP) self.screen = screen self.drawCursor = drawCursor #determine the speed to write at, in characters per tick if settings.textSpeed == "SLOW": self.speed = 1 elif settings.textSpeed == "MEDIUM": self.speed = 2 elif settings.textSpeed == "FAST": self.speed = 4 #parse the dialog xml file fn = os.path.join(settings.path, "data", globs.DIALOG) root = data.getTreeRoot(fn, "Ditto main") transparency = data.getAttr(root, "transparency", data.D_INT3LIST) #create font fontPath = os.path.join(settings.path, "data", globs.FONT) self.font = font.Font(fontPath) #create the box size = ((self.screen.get_width()-(OBJECTBUFFER*2), (len(self.text)*(self.font.height+LINEBUFFER))-LINEBUFFER+(BORDER*2))) self.box = box.Box(size).convert(self.screen) #load the cursors cursorPath = os.path.join(settings.path, "data", data.getAttr(root, "cursor", data.D_STRING)) self.cursor = data.getImage(cursorPath).convert(self.screen) self.cursor.set_colorkey(transparency) self.cursorLocation = (self.screen.get_width()-OBJECTBUFFER-BORDER-self.cursor.get_width(), self.screen.get_height()-OBJECTBUFFER-BORDER-self.cursor.get_height()) cursorPath = os.path.join(settings.path, "data", data.getAttr(root, "sidecursor", data.D_STRING)) self.sideCursor = data.getImage(cursorPath).convert(self.screen) self.sideCursor.set_colorkey(transparency) #calculate location of dialog box self.location = OBJECTBUFFER, self.screen.get_height()-self.box.get_height()-OBJECTBUFFER #start progress at 0 and set drawing and busy self.progress = 0 self.writing = True self.busy = True
def __init__(self): """ Constructor of Place and default values will be initialised. """ # call constructor of parent class super(Place, self).__init__() self._radius = 0. self._marking = 0 self._step_size = 1 self._capacity = 0 self._font_marking = font.Font() #self._get_default_font()
def __init__(self): ## Maps (fontName, fontSize) to Font instances self.fontMap = dict() configPath = os.path.join(constants.fontPath, constants.fontFilename) fontModule = game.dynamicClassManager.loadModuleItems(configPath, ['fonts']) for fontName, fontConfig in fontModule.fonts.iteritems(): fontSizes = [] if 'sizes' in fontConfig: fontSizes = fontConfig['sizes'] for size in fontSizes: self.fontMap[(fontName, size)] = font.Font(fontName, size)
def onSelectFont(self, evt): wName, wClass = self.wComponentList.GetStringSelection().split(" : ") widget = self.parentApp.getCurrentBackground().components[wName] f = widget.font if f is None: desc = font.fontDescription(widget.GetFont()) f = font.Font(desc) result = dialog.fontDialog(self, f) if result.accepted: #color = dlg.getColor() f = result.font self.wField.SetValue("%s" % f)
def __init__(self, position = [0., 0.], dimension = [0., 0.], edge = (0., 0., 0.), fill = (0., 0., 0.)): """ Constructor of Transition and default values will be initialised for the not defined parameter. """ # call constructor of parent class super(Transition, self).__init__() self._pos = position self._dim = dimension self._edge = edge self._fill = fill self._label_pos = [self._pos[0] - self._dim[0], self._pos[1] - 3] self._rate = 1. self._font_rate = font.Font() #self._get_default_font()
def __init__(self): """ Constructor of Component and default values will be initialised. """ self._label = "" self._descr = "" self._key = "" self._x_offset = 0 self._y_offset = 0 self._font_label = font.Font() #self.default_font() self._font_description = font.Font() #self.default_font() self._label_pos = [0., 0.] self._pos = [0., 0.] self._edge = [0., 0., 0.] self._fill = [255., 255., 255.] self._ctr_inputs = 0 self._ctr_outputs = 0 self._limit = 0 self._limit_inputs = 0 self._limit_outputs = 0
def exception_handler(g, e): #handles exception tb = traceback.format_exc() #get exception try: #attempt to load a font g.font = font.Font("fonts/selfdialog_font.xml") g.surf = pygame.Surface( (settings.screen_x, settings.screen_y)) #and a surface to draw on g.surf.fill((0, 0, 100)) #fill with pretty blue g.linepos = 0 except: #if there was an error loading it g.font = None #set font to none try: #attempt to open an output file g.out = open("exception.txt", "w") except: #if that couldn't be done g.out = None #set it to none #write header exception_write( g, "We're terribly sorry, but an internal error has occurred :(") t = "This will be written to the console" #only say file if file could be opened if g.out: t += " and a file named exception.txt in the current directory" exception_write(g, t + ".") exception_write(g, "Press ESCAPE to exit (if displayed on-screen)") try: #attempt to make a backup save g.game.save("error.pokesav") #say if it could be done successfully exception_write(g, "Game was saved to error.pokesav.") except: exception_write(g, "Game could not be saved.") lines = tb.split("\n") #lines of exception exception_write(g, lines[-2]) #show last line of exception #now write out traceback for line in lines: exception_write(g, line) exception_write(g, "Error handler finished.") #now, finish display if g.out is not None: g.out.close() #close output file if it was opened if g.font is None: return #return if the font was never opened #otherwise, draw font and do a short event loop pygame.transform.scale(g.surf, (settings.screen_x*settings.screen_scale, \ settings.screen_y*settings.screen_scale), g.screen) #draw the screen scaled properly pygame.display.flip() #flip double buffers running = True while running: #do a brief event loop that watches for escape key for event in pygame.event.get(): if event.type == QUIT: #if we're being told to quit running = False #stop running break #and stop processing events elif event.type == KEYDOWN: #if a key has been pressed if event.key == K_ESCAPE: #and it was escape running = False #stop running break #and processing events time.sleep(0.1)
def __init__(self, parent): self.name = 'word/fontTable.xml' self.tag = 'w:fonts' self.content_type = "application/vnd.openxmlformats-officedocument.wordprocessingml.fontTable+xml" self.rId = 0 self.parent = parent self.separator = self.parent.separator self.tab = self.parent.tab self.xml_header = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' if not self.separator: self.xml_header += '\n' self.fonts = {'Calibri': font.Font(self.parent, 'Calibri'), 'Times New Roman': font.Font(self.parent, 'Times New Roman'), 'Calibri Light': font.Font(self.parent, 'Calibri Light')} self.xmlns = { 'mc': "http://schemas.openxmlformats.org/markup-compatibility/2006", 'r': "http://schemas.openxmlformats.org/officeDocument/2006/relationships", 'w': "http://schemas.openxmlformats.org/wordprocessingml/2006/main", 'w14': "http://schemas.microsoft.com/office/word/2010/wordml", 'w15': "http://schemas.microsoft.com/office/word/2012/wordml"} self.ignorable = 'w14 w15'
def gameInfo(self, information): self.gameinfo = information self.background = pygame.image.load('startinterface.png') self.rect = v.screen.get_rect() self.font = font.Font("mainmenu", self.gameinfo) self.Status = False self.nextStage = 'story' #choose cursor self.cursor = pygame.sprite.Sprite() self.cursor.image = tool.getImage("role.png", 0, 0, 48, 48, 1) self.cursor.rect = self.cursor.image.get_rect() self.cursor.rect.x = 400 self.cursor.rect.y = 340 self.cursor.state = "start"
def OnInit(self): if isinstance(WaxConfig.default_font, tuple): WaxConfig.default_font = font.Font(*WaxConfig.default_font) else: print >> sys.stderr, "Warning: This construct will not work in future wxPython versions" self.mainframe = self.frameklass(*self.args, **self.kwargs) if hasattr(self.mainframe.__class__, "__ExceptHook__"): sys.excepthook = self.mainframe.__ExceptHook__ self.Bind(wx.EVT_ACTIVATE_APP, self.OnActivate) self.mainframe.Show(True) self.SetTopWindow(self.mainframe) return True
def __init__(self, screen, game, fn): self.screen = screen self.game = game self.font = font.Font(os.path.join(settings.path, "data", globs.FONT)) #create the font self.menuNode = data.getTreeRoot(fn) self.foregroundObject = None self.objectBuffer = 2 self.border = 10 self.lineBuffer = 3 self.choices = ["POKEDEX", "POKEMON", "BAG", "OPTIONS", "SAVE", "EXIT"] self.current = 0 fn = os.path.join(settings.path, "data", globs.DIALOG) root = ET.parse(fn).getroot() self.transparency = map(int, root.attrib["transparency"].split(",")) self.sideCursor = pygame.image.load( os.path.join( settings.path, "data", root.attrib["sidecursor"])).convert( self.screen) ##load the side cursor image, and convert self.sideCursor.set_colorkey(self.transparency) ##set the transparency width = max( map(self.font.calcWidth, self.choices)) + self.border * 2 + self.sideCursor.get_width() self.size = (width, (self.border * 2) + (self.font.height * len(self.choices)) + (self.lineBuffer * (len(self.choices) - 1))) self.location = (self.screen.get_width() - self.size[0] - self.objectBuffer, self.objectBuffer) self.box = box.Box(self.size) i = 0 for choice in self.choices: location = self.border + self.sideCursor.get_width(), ( i * (self.font.height + self.lineBuffer)) + self.border self.font.writeText(choice, self.box, location) i += 1 self.busy = True
def meet(gameinfo, surface, image1, ini1, image2, ini2, dest, height): fon = font.Font("win", gameinfo) surface.blit(image1, (ini1, height)) surface.blit(image2, (ini2, height)) while True: if ini1 <= dest and ini2 >= dest: pygame.display.update() surface.blit(pygame.image.load("win.png"), (0, 0)) surface.blit(image1, (ini1, height)) surface.blit(image2, (ini2, height)) fon.draw(surface) ini1 += 25 ini2 -= 25 pygame.time.Clock().tick(5) else: break return
def __init__(self): """ Constructor of Arc and default values will be initialised. """ # call constructor of parent class super(Arc, self).__init__() # 0, 1 (input), 2 (output) self._arc_type = 0 self.__ctr = 0 self._origin = None self._target = None self._target_position = None self._arrow = None self._weight = 1. self._line_type = self.LINE_TYPE_STRAIGHT self._font_weight = font.Font() #self._get_default_font() self._head = standard_arrow_head.StandardArrowHead()
def __init__(self, position=[0., 0.], radius=0., edge=(0., 0., 0.), fill=(255., 255., 255.)): """ Constructor of Place and default values will be initialised for the not defined parameter. """ # call constructor of parent class super(Place, self).__init__() self._pos = position self._radius = radius self._edge = edge self._fill = fill self._marking = 0 self._step_size = 1 self._capacity = 0 self._font_marking = font.Font() #self._get_default_font()
def __init__(self, screen): """ Create the continue and new game boxes, and a shadow to darken non-selected boxes. screen - the screen to draw to. """ #store the screen for blitting to later self.screen = screen #create the font fFont = font.Font(os.path.join(settings.path, "data", globs.FONT)) #initialise list of boxes self.boxes = [] #get a list of save files #if any exist, get info from them and create a box for them savefiles = os.listdir(os.path.join(settings.path, "saves")) #get list of save files if savefiles: info = { "PLAYER": "BOB", "TIME": "06:01", "POKEDEX": "42", "BADGES": "1" } order = ["PLAYER", "TIME", "POKEDEX", "BADGES"] continueBox = Infobox(self.screen, fFont, "CONTINUE", info, order) self.savegame = os.path.join(settings.path, "saves", savefiles[0]) self.boxes.append(continueBox) #create the box for a new game newgameBox = Infobox(self.screen, fFont, "NEW GAME") self.boxes.append(newgameBox) #create the shadow used to darken non-selected boxes self.shadow = pygame.Surface( (self.screen.get_width(), self.screen.get_height())) self.shadow.fill((10, 10, 10)) self.shadow.set_alpha(100) #start with the topmost box selected self.current = 0
def __init__(self, screen, skillsNode, poke): """ aa screen - the screen to blit to. statsNode - the <stats> node from the menu XML file. poke - the pokemon. """ self.screen = screen fFont = font.Font( os.path.join(settings.path, "data", data.getAttr(skillsNode, "font", data.D_STRING))) size = ((self.screen.get_width() / 2) - (OBJECTBUFFER * 2), (self.screen.get_height() / 2) - (OBJECTBUFFER * 2)) fn = os.path.join(settings.path, "data", data.getAttr(skillsNode, "box", data.D_STRING)) self.statsBox = box.Box(size, fn).convert(self.screen) stats = { "HP": pokemon.ST_HP, "Attack": pokemon.ST_ATTACK, "Defense": pokemon.ST_DEFENSE, "Sp Attack": pokemon.ST_SPATTACK, "Sp Defense": pokemon.ST_SPDEFENSE, "Speed": pokemon.ST_SPEED } order = ["HP", "Attack", "Defense", "Sp Attack", "Sp Defense", "Speed"] pointerY = BORDER for stat in order: fFont.writeText(stat, self.statsBox, (BORDER, pointerY)) text = str(poke.stats[stats[stat]]) fFont.writeText( text, self.statsBox, (size[0] - fFont.calcWidth(text) - BORDER, pointerY)) pointerY += fFont.height + LINEBUFFER self.statsBoxLocation = (self.screen.get_width() - size[0] - OBJECTBUFFER, OBJECTBUFFER)
def __init__(self, g, type, dlog=None): self.g = g #store parameters if dlog is not None: #if a dialog has been provided #copy its parameters self.type = dlog.type self.choice_tiles = dlog.choice_tiles self.dlog_font = dlog.dlog_font self.dlog = dialogs[self.type] else: #otherwise, if none was given dlog = dialogs[type] #get type self.choice_tiles = tileset.Tileset(dlog["choice_file"], 8, 8) #load choice tileset self.dlog_font = font.Font(dlog["font"]) #load font self.dlog = dlog self.type = type self.choices = [] #list of choices self.drawing = False #whether we're currently showing choices self.curr_choice = None #index of the currently selected choice self.cursor_tile = pygame.Surface( (8, 8), SRCALPHA) #surface to hold cursor tile
def gameInfo(self, information): self.gameinfo = information self.Status = False self.rect = v.screen.get_rect() self.nextStage = 'win' self.font = font.Font("startgame", self.gameinfo) self.background = pygame.image.load('map1.png') self.backgroundRect = self.background.get_rect() self.gameGround = pygame.Surface( (self.backgroundRect.width, self.backgroundRect.height)) self.roleGroup = pygame.sprite.Group() self.setRole() self.setEnemy() self.bossGroup = pygame.sprite.Group() self.setBoss() self.bossAtkGroup = pygame.sprite.Group() self.bossAtkTime = 0 self.gameWindow = v.screen.get_rect() self.setItem() self.treasureGroup1 = pygame.sprite.Group() self.treasureGroup2 = pygame.sprite.Group() self.treasureGroup3 = pygame.sprite.Group()
def __init__(self, aParent, aResource): component.Component.__init__(self, aResource) self._parent = aParent self._resource = aResource self._setUserdata(self._resource.userdata) # KEA 2004-04-23 # Controls are enabled and visible by default # so no need to enable and call Show unless False. if not self._resource.enabled: self._setEnabled(self._resource.enabled) if not self._resource.visible: self._setVisible(self._resource.visible) if self._resource.foregroundColor is not None: self._setForegroundColor(self._resource.foregroundColor) if self._resource.backgroundColor is not None: self._setBackgroundColor(self._resource.backgroundColor) if self._resource.toolTip != "": self._setToolTip(self._resource.toolTip) if self._resource.font is None: self._font = None else: self._setFont(font.Font(self._resource.font, self))