def __init__(self, id): GameEngineElement.__init__(self, has_draw=True, has_event=True) self.id = id self.rooms = {} self.__images = {} self.__load_dungeon() self.__load_images() profile = self.game_engine.get_object('profile') if profile.position == (-1, -1): x, y = self.start profile.move_to(x, y) self.doorsList = [] self.game_engine.get_scene().addObject( DrawableObject([self.__images['Room']], '')) self.doorsList.append( DrawableObject([self.__images['L']], '', True, 0, 0)) self.doorsList.append( DrawableObject([self.__images['F']], '', True, 360, 0)) self.doorsList.append( DrawableObject( [pygame.transform.flip(self.__images['L'], True, False)], '', True, 990, 0)) #for door in self.doorsList: door.makeTransparent(True) self.add_to_scene(self.doorsList) self.itemsList = [] for i in range(4): surf = pygame.Surface((10, 10)) surf.fill((0, 0, 0)) tempItem = DrawableObject([surf], "", True) self.itemsList.append(tempItem) self.itemsList[0].setPosition( self.game_engine.art_scale(270, 1200, True), self.game_engine.art_scale(330, 900, False)) self.itemsList[1].setPosition( self.game_engine.art_scale(100, 1200, True), self.game_engine.art_scale(600, 900, False)) self.itemsList[2].setPosition( self.game_engine.art_scale(1100, 1200, True), self.game_engine.art_scale(600, 900, False)) self.itemsList[3].setPosition( self.game_engine.art_scale(900, 1200, True), self.game_engine.art_scale(330, 900, False)) self.add_to_scene(self.itemsList) self.add_to_engine()
def __init__(self, dgn): GameEngineElement.__init__(self, has_draw=True, has_event=True) self.dgn = dgn self.current_room = dgn.get_current_room() self.font = pygame.font.SysFont("cmr10", 18, False, False) self.enemy_list = [] #Holds the list of enemies self.magic_list = [] #Holds list of magic used? self.spellType = 0 #0 = non, 1-4 are spells in order, 5 is special self.isMagic = False self.correct = False self.state = PLAYER_WAIT self.player_input = '0' self.active_target = 1 self.battleTimer = -1.0 self.tIndex = 0 for i in range(0, 4): e_index = self.current_room.get_enemy(i) if e_index != '0': curE = get_enemy(e_index) self.enemy_list.append(curE) self.add_to_scene([curE.get_sprite()]) # Preload images self.__drawableObjects = {} for i in ['arrow_select']: self.__drawableObjects[i] = DrawableObject( [pygame.image.load(HUD_PATH + i + ".gif")], '') self.add_to_scene([self.__drawableObjects[i]]) self.__drawableObjects['hp'] = DrawableObject( Spritesheet(HUD_PATH + "hp.gif").img_extract( 11, 1, 100, 100, [255, 0, 255]), '') self.__drawableObjects['bt'] = DrawableObject( Spritesheet(HUD_PATH + "bt.gif").img_extract( 1, 11, 100, 25, [255, 0, 255]), '', True) self.__drawableObjects['hp'].setColorKey((255, 0, 255)) self.__drawableObjects['bt'].setColorKey((255, 0, 255)) self.add_to_scene([self.__drawableObjects['hp']]) self.add_to_scene([self.__drawableObjects['bt']]) self.add_to_engine() self.game_engine.add_object('battlemenu', BattleMenuHolder(self.menu_callback)) self.game_engine.get_object('battlemenu').show_menu('selection') self.game_engine.get_object('mesg').add_line( _('Enemies present, prepare to fight!'))
def __init__(self, options, cols, scene, x=237, y=375): """Initialize the EzMenu! options should be a sequence of lists in the format of [option_name, option_function]""" self.options = options self.scene = scene self.x = x self.y = y self.cols = cols self.font = pygame.font.SysFont("cmr10", 18, False, False) self.option = 0 self.width = 1 self.color = [0, 0, 0] self.hcolor = [255, 0, 0] self.height = len(self.options) * self.font.get_height() self.font_list = [] self.rect_list = [] for o in self.options: self.font_list.append(DrawableFontObject(o[0], self.font)) ren = self.font.render(o[0], 1, [0, 0, 0]) if ren.get_width() > self.width: self.width = ren.get_width() i = 0 # Row Spacing h = 0 # Selection Spacing j = 0 # Col Spacing for o in self.options: newX = self.x + 45 * j newY = self.y + i * 45 surf = pygame.Surface((o[2], 44)) surf.fill((0, 74, 94)) tempDO = DrawableObject([surf], "") tempDO.setPosition(newX, newY) self.rect_list.append(tempDO) surf = pygame.Surface((o[2] - 4, 40)) surf.fill((4, 119, 152)) tempDO = DrawableObject([surf], "") tempDO.setPosition(newX + 2, newY + 2) self.rect_list.append(tempDO) j += o[3] h += 1 if j >= self.cols: i += 1 j = 0 self.scene.addObjects(self.rect_list) self.scene.addObjects(self.font_list)
def __init__(self, recall_string=None, name_entry_cb=None): GameEngineElement.__init__(self) self.name = "" self.dungeon_id = "al1.txt" self.position = (-1, -1) self.playerFacing = NORTH self.hero = Hero() # 4 types of stats and difficulties self.problem_stats = {} self.difficulty = {} for stat in ['mult', 'div', 'geo', 'shop']: # Each type of stat has 3 "levels" easy, medium, hard # Shop uses level for too much, too little, exact self.problem_stats[stat] = [(0, 0), (0, 0), (0, 0)] #Difficulty: 1=Easy 2=Meduim(default) 3=Hard self.difficulty[stat] = 2 self.puzzlesSolved = 0 self.inventory = [] bg = pygame.image.load(MENU_PATH + "mafh_splash.gif").convert() self.background = DrawableObject([bg], '') self.background.scale(self.game_engine.width, self.game_engine.height) self.add_to_scene([self.background]) #create background rect draw_width = self.game_engine.width / 4 draw_height = self.game_engine.height / 4 surf = pygame.Surface((draw_width + 60, draw_height + 60)) surf.fill((150, 150, 255)) self.blueRect = DrawableObject([surf], "") self.add_to_scene([self.blueRect]) font = pygame.font.Font(None, 16) self.text_list = [] self.text_list.append(DrawableFontObject("1", font)) self.text_list.append(DrawableFontObject("2", font)) self.text_list.append(DrawableFontObject("name", font)) self.add_to_scene(self.text_list) if recall_string: self.load_from_json_string(recall_string) if self.name == "": self.name_cb = name_entry_cb self.add_to_engine()
def __init__(self, callback): GameEngineElement.__init__(self, has_draw=True, has_event=False) self.menu = None self.callback = callback self.background = DrawableObject( [pygame.image.load(MENU_PATH + "battleMenubackground.gif")], '') self.background.setPosition(0, 286) self.add_to_scene([self.background])
def __init__(self, callback, background=None, width=1200, height=900): GameEngineElement.__init__(self, has_draw=True, has_event=False) self.menu = None self.callback = callback self.background = DrawableObject( [pygame.image.load(background).convert()], '') self.background.scale(width, height) self.add_to_scene([self.background]) self.width = width self.height = height
def __init__(self, callback): GameEngineElement.__init__(self, has_draw=True, has_event=False) self.menu = None self.callback = callback self.background = DrawableObject( [pygame.image.load(MENU_PATH + "battleMenubackground.gif")], '') self.font = pygame.font.SysFont("cmr10", 18, False, False) self.disp = DrawableFontObject("", self.font) self.sec_disp = DrawableFontObject("", self.font) self.add_to_scene([self.background]) self.add_to_scene([self.disp]) self.add_to_scene([self.sec_disp])
def __init__(self, x, y, width, height, lines): GameEngineElement.__init__(self, has_draw=True, has_event=False) self.max_lines = lines self.x = x self.y = y surf = pygame.Surface((int(width), int(height))) surf.fill([0, 0, 0]) self.box = DrawableObject([surf], "") self.box.setPosition(int(x), int(y)) self.font = pygame.font.Font(None, 28) self.__lines = [] for i in range(lines): self.__lines.append(DrawableFontObject('', self.font)) self.add_to_scene([self.box]) self.add_to_scene(self.__lines) self.add_to_engine()
def __init__(self, dgn): GameEngineElement.__init__(self, has_draw=True, has_event=True) self.draw_macro_set = False #A boolean value to determine whether the large map should draw self.sizeX = dgn.sizeX #A variable that represents the number of rooms wide the dungeon is self.sizeY = dgn.sizeY #A variable that represents the number of rooms tall the dungeon is self.rectSizeX = 38 #A variable representing the X size of a given room on the mini map self.rectSizeY = 38 #A variable representing the Y size of a given room on the mini map self.rects = { } #A dictionary of rectangles that represent the rooms on the map self.fullRooms = {} #A dictionary representing nothing? self.totalSurface = pygame.Surface( (self.sizeX * 40, self.sizeY * 40)) #A rect representing the size of the map as a whole #A Two dimensional For Loop that goes through all of the positions on the map. for y in range(self.sizeY): for x in range(self.sizeX): curRect = pygame.Rect( x * 40, y * 40, self.rectSizeX, self.rectSizeX ) #Creating a rectangle for the current position on the map. self.rects[( x, y )] = curRect #Adds the rectangle associated with the current position to the dictionary using the position on the map as the key. #Each 'if' tests whether there is a door in a given direction at the current position. #If there is a door in the given direction, it fills the square associated with themeans that the position has a room and fills it accordingly. if dgn.rooms.get((x, y)).get_door('N') != '0': self.fullRooms[(x, y)] = True self.totalSurface.fill((255, 255, 255), curRect, 0) elif dgn.rooms.get((x, y)).get_door('S') != '0': self.fullRooms[(x, y)] = True self.totalSurface.fill((255, 255, 255), curRect, 0) elif dgn.rooms.get((x, y)).get_door('E') != '0': self.fullRooms[(x, y)] = True self.totalSurface.fill((255, 255, 255), curRect, 0) elif dgn.rooms.get((x, y)).get_door('W') != '0': self.fullRooms[(x, y)] = True self.totalSurface.fill((255, 255, 255), curRect, 0) self.add_to_engine() #Adds itself and all callbacks to the engine self.myDrawableObject = DrawableObject([pygame.Surface((0, 0))], '') self.add_to_scene([self.myDrawableObject])
def __init__(self, options, spelltype, magic_list, scene): """Initialize the EzMenu! options should be a sequence of lists in the format of [option_name, option_function]""" self.scene = scene self.buttons = [] self.options = options self.x = 0 self.y = 0 self.cols = 2 self.option = 0 self.width = 2 self.spelltype = spelltype self.magic_list = magic_list self.reference = [] lightning = [] fire = [] missile = [] heal = [] fire = Spritesheet(PUZZLE_PATH + "FireGlyph.gif").img_extract( 2, 2, 150, 150, (255, 0, 255)) lightning = Spritesheet(PUZZLE_PATH + "LightningGlyph.gif").img_extract( 2, 2, 150, 150, (255, 0, 255)) missile = Spritesheet(PUZZLE_PATH + "MissileGlyph.gif").img_extract( 2, 2, 150, 150, (255, 0, 255)) heal = Spritesheet(PUZZLE_PATH + "HealGlyph.gif").img_extract( 2, 2, 150, 150, (255, 0, 255)) if (spelltype == 0): #fire attack for i in range(4): self.buttons.append( DrawableObject([pygame.transform.scale(fire[i], (60, 60))], "")) #filler buttons for i in range(0, 2): self.buttons.append( DrawableObject( [pygame.transform.scale(lightning[i], (60, 60))], "")) random.seed() self.buttons.append( DrawableObject([ pygame.transform.scale(heal[random.randint(0, 3)], (60, 60)) ], "")) self.buttons.append( DrawableObject([ pygame.transform.scale(missile[random.randint(0, 3)], (60, 60)) ], "")) self.mainGlyph = pygame.image.load( PUZZLE_PATH + "FireGlyph.gif").convert_alpha() self.glyphs = fire elif (spelltype == 1): #lightning attack for i in range(4): self.buttons.append( DrawableObject( [pygame.transform.scale(lightning[i], (60, 60))], "")) #filler buttons for i in range(0, 2): self.buttons.append( DrawableObject([pygame.transform.scale(fire[i], (60, 60))], "")) random.seed() self.buttons.append( DrawableObject([ pygame.transform.scale(heal[random.randint(0, 3)], (60, 60)) ], "")) self.buttons.append( DrawableObject([ pygame.transform.scale(missile[random.randint(0, 3)], (60, 60)) ], "")) self.mainGlyph = pygame.image.load( PUZZLE_PATH + "LightningGlyph.gif").convert_alpha() self.glyphs = lightning elif (spelltype == 2): #missile attack for i in range(4): self.buttons.append( DrawableObject( [pygame.transform.scale(missile[i], (60, 60))], "")) #filler buttons for i in range(0, 2): self.buttons.append( DrawableObject( [pygame.transform.scale(lightning[i], (60, 60))], "")) random.seed() self.buttons.append( DrawableObject([ pygame.transform.scale(heal[random.randint(0, 3)], (60, 60)) ], "")) self.buttons.append( DrawableObject([ pygame.transform.scale(fire[random.randint(0, 3)], (60, 60)) ], "")) self.mainGlyph = pygame.image.load( PUZZLE_PATH + "MissileGlyph.gif").convert_alpha() self.glyphs = missile elif (spelltype == 3): #heal for i in range(4): self.buttons.append( DrawableObject([pygame.transform.scale(heal[i], (60, 60))], "")) #filler buttons for i in range(0, 2): self.buttons.append( DrawableObject( [pygame.transform.scale(lightning[i], (60, 60))], "")) random.seed() self.buttons.append( DrawableObject([ pygame.transform.scale(missile[random.randint(0, 3)], (60, 60)) ], "")) self.buttons.append( DrawableObject([ pygame.transform.scale(fire[random.randint(0, 3)], (60, 60)) ], "")) self.mainGlyph = pygame.image.load( PUZZLE_PATH + "HealGlyph.gif").convert_alpha() self.glyphs = heal deck = [0, 1, 2, 3, 4, 5, 6, 7] random.seed() random.shuffle(deck) tOptions = [] tButtons = [] for i in range(8): tOptions.append(self.options[deck[i]]) tButtons.append(self.buttons[deck[i]]) self.buttons = tButtons self.options = tOptions surf = pygame.Surface((60, 60)) surf.fill((4, 119, 152)) self.selectRect = DynamicDrawableObject([surf], "") self.selectRect.setPosition(297, 435) self.scene.addObject(self.selectRect) self.scene.addObjects(self.buttons) self.mainGlyph.set_colorkey((255, 0, 255), pygame.RLEACCEL) self.mainGlyphDO = DrawableObject([self.mainGlyph], "") self.mainGlyphDO.setPosition(485, 350) for image in self.glyphs: tempDO = DrawableObject([image], "", True) #tempDO.makeTransparent(True) self.reference.append(tempDO) self.scene.addObjects(self.reference) self.scene.addObject(self.mainGlyphDO) self.height = (len(self.options) * self.buttons[1].getYSize()) / self.cols