def __init__(self, num): self.num = num numOfCols = int( math.ceil(float(num) / float(CHARACTER_SELECT_PANELS_PER_COL))) numOfPanelsInCol = [] for i in range(numOfCols): numOfPanelsInCol.append(0) count = 0 currCol = 0 while count < num: numOfPanelsInCol[currCol] += 1 count += 1 currCol += 1 if currCol == numOfCols: currCol = 0 self.characterPanels = [] for i in range(len(numOfPanelsInCol)): colMid = (SCREEN_SIZE[0] / (len(numOfPanelsInCol) + 1)) * (i + 1) for j in range(numOfPanelsInCol[i]): rect = Rect((0, 0), CHARACTER_SELECT_PANEL_SIZE) rect.centerx = colMid rect.top = (CHARACTER_SELECT_GROUP_FROM_TOP + ((CHARACTER_SELECT_PANEL_SIZE[1] + CHARACTER_SELECT_GROUP_SPACING) * j)) self.characterPanels.append(CharacterPanel(rect, None))
def __init__(self, num): self.num = num numOfCols = int(math.ceil(float(num) / float(CHARACTER_SELECT_PANELS_PER_COL))) numOfPanelsInCol = [] for i in range(numOfCols): numOfPanelsInCol.append(0) count = 0 currCol = 0 while count < num: numOfPanelsInCol[currCol] += 1 count += 1 currCol += 1 if currCol == numOfCols: currCol = 0 self.characterPanels = [] for i in range(len(numOfPanelsInCol)): colMid = (SCREEN_SIZE[0] / (len(numOfPanelsInCol) + 1)) * (i + 1) for j in range(numOfPanelsInCol[i]): rect = Rect((0, 0), CHARACTER_SELECT_PANEL_SIZE) rect.centerx = colMid rect.top = CHARACTER_SELECT_GROUP_FROM_TOP + ( (CHARACTER_SELECT_PANEL_SIZE[1] + CHARACTER_SELECT_GROUP_SPACING) * j ) self.characterPanels.append(CharacterPanel(rect, None))
def __init__(self, fade): super(Model, self).__init__() self.bg = pygame.Surface(SCREEN_SIZE) self.bg = scrollingbackground.ScrollingBackground(Rect((0, 0), SCREEN_SIZE), MAIN_MENU_BACKGROUND_IMAGE, [0.2, 0.5]) tempRect = Rect( (50, 50), (200, 0) ) menuOptions = ["Play Single Player", "Play via Network", "Character Setup", "Options", "Credits", "Exit"] self.menu = minimenu.MiniMenu(tempRect, menuOptions, MAIN_MENU_FONT, MAIN_MENU_COLOR_ON, MAIN_MENU_COLOR_OFF, MAIN_MENU_COLOR_BG) self.menu.center(ENTIRE_SCREEN, False, True) self.menu.rect.left = MAIN_MENU_OFFSET_FROM_SIDE self.textMessages = [ ("Fimbulvetr", 3, ALMOST_BLACK, WHITE, 1, True), ("War of the Great Winter", 2, ALMOST_BLACK, WHITE, 1, True)] self.textRects = [] for i in self.textMessages: f = FONTS[i[1]] size = (SCREEN_SIZE[0], f.get_linesize() + f.get_height()) tempRect = Rect( (0, 0), size ) self.textRects.append(textrect.render_textrect( i[0], f, tempRect, i[2], i[3], i[4], i[5])) self.transSurface = pygame.Surface(SCREEN_SIZE) self.transSurface.fill((INTRO_MAX_FADE, INTRO_MAX_FADE, INTRO_MAX_FADE)) self.transAlpha = boundint.BoundInt(0, 255, 255) self.transChecker = True self.transDirection = False if not fade: self.transAlpha.value = 0 self.transChecker = False
def createButtons(self, itemWidth, marginWidth, spacingWidth, items, itemMatrix): self.buttons = [] for row in range(itemMatrix[1]): for col in range(itemMatrix[0]): itemIndex = (itemMatrix[0] * row) + col if (itemIndex >= len(items)): return item = items[itemIndex] xPos = (itemWidth * col) + (spacingWidth * (col)) + marginWidth yPos = (itemWidth * row) + (spacingWidth * (row)) + marginWidth rect = Rect((xPos, yPos), (itemWidth, itemWidth)) if (isinstance(item, mapchar.MapChar)): images = [] icons = [item.images[0][0], item.images[1][0]] for i in range(len(icons)): icon = icons[i] iconRect = Rect((0, 0), icon.get_size()) iconRect.centerx = (rect.width / 2) iconRect.centery = (rect.height / 2) surface = pygame.Surface(rect.size) surface.fill(CHARACTER_SELECTION_DIALOG_BUTTON_COLOR) surface.blit(icon, iconRect.topleft) images.append(surface) self.buttons.append( DetailDialogButton(rect, images[0], images[1], item))
def updateStructureCount(self, fortressCount, spireCount, altarCount): self.fortressCount = fortressCount self.spireCount = spireCount self.altarCount = altarCount self.structureCountPanel = pygame.Surface(self.structureCountPanelRect.size) self.structureCountPanel.fill(UNIT_HUD_COLORS[self.team]) self.structureCountPanel.blit(self.fortressIcon, self.fortressIconRect.topleft) self.structureCountPanel.blit(self.spireIcon, self.spireIconRect.topleft) self.structureCountPanel.blit(self.altarIcon, self.altarIconRect.topleft) textRect = Rect((0,0), (100, STRUCTURE_COUNT_FONT.get_height() + 4)) textSurface = textrect.render_textrect(" x" + str(self.fortressCount), STRUCTURE_COUNT_FONT, textRect, ALMOST_BLACK, BLACK, 0, True) textRect.bottomleft = self.fortressIconRect.bottomright self.structureCountPanel.blit(textSurface, textRect.topleft) textSurface = textrect.render_textrect(" x" + str(self.spireCount), STRUCTURE_COUNT_FONT, textRect, ALMOST_BLACK, BLACK, 0, True) textRect.left = self.spireIconRect.right - 3 self.structureCountPanel.blit(textSurface, textRect.topleft) textSurface = textrect.render_textrect(" x" + str(self.altarCount), STRUCTURE_COUNT_FONT, textRect, ALMOST_BLACK, BLACK, 0, True) textRect.left = self.altarIconRect.right - 3 self.structureCountPanel.blit(textSurface, textRect.topleft)
def changeVal(self, val=None): if not val is None: self.val = val self.panel = pygame.Surface(self.rect.size) self.panel.blit(self.backPanel, (0, 0)) font = CHARACTER_SELECTION_FONT textHeight = font.get_linesize() + 2 tempRect = Rect((0, 0), (self.rect.width, textHeight)) text = textrect.render_textrect( self.name, font, tempRect, CHARACTER_SELECTION_FONT_COLOR, ALMOST_BLACK, 0, True ) tempRect = Rect((0, 0), text.get_size()) tempRect.top = (CHARACTER_SELECT_PANEL_SIZE[1] / 2) - (tempRect.height / 2) loc = (tempRect.left + CHARACTER_SELECT_PANEL_BORDER_WIDTH + CHARACTER_SELECT_PANEL_BORDER_SIZE, tempRect.top) self.panel.blit(text, loc) if self.ready: msg = "READY" color = CHARACTER_SELECTION_READY_COLOR else: msg = str(self.val) + "/" + str(self.maxVal) color = CHARACTER_SELECTION_FONT_COLOR text = textrect.render_textrect(msg, font, tempRect, color, ALMOST_BLACK, 2, True) loc = (tempRect.left - CHARACTER_SELECT_PANEL_BORDER_WIDTH - CHARACTER_SELECT_PANEL_BORDER_SIZE, tempRect.top) self.panel.blit(text, loc)
def changeVal(self, val=None): if not val is None: self.val = val self.panel = pygame.Surface(self.rect.size) self.panel.blit(self.backPanel, (0, 0)) font = CHARACTER_SELECTION_FONT textHeight = font.get_linesize() + 2 tempRect = Rect((0, 0), (self.rect.width, textHeight)) text = textrect.render_textrect(self.name, font, tempRect, CHARACTER_SELECTION_FONT_COLOR, ALMOST_BLACK, 0, True) tempRect = Rect((0, 0), text.get_size()) tempRect.top = ((CHARACTER_SELECT_PANEL_SIZE[1] / 2) - (tempRect.height / 2)) loc = (tempRect.left + CHARACTER_SELECT_PANEL_BORDER_WIDTH + CHARACTER_SELECT_PANEL_BORDER_SIZE, tempRect.top) self.panel.blit(text, loc) if self.ready: msg = "READY" color = CHARACTER_SELECTION_READY_COLOR else: msg = str(self.val) + "/" + str(self.maxVal) color = CHARACTER_SELECTION_FONT_COLOR text = textrect.render_textrect(msg, font, tempRect, color, ALMOST_BLACK, 2, True) loc = (tempRect.left - CHARACTER_SELECT_PANEL_BORDER_WIDTH - CHARACTER_SELECT_PANEL_BORDER_SIZE, tempRect.top) self.panel.blit(text, loc)
def createButtons(self, itemWidth, marginWidth, spacingWidth, items, itemMatrix): self.buttons = [] for row in range(itemMatrix[1]): for col in range(itemMatrix[0]): itemIndex = (itemMatrix[0] * row) + col if (itemIndex >= len(items)): return item = items[itemIndex] xPos = (itemWidth * col) + (spacingWidth * (col)) + marginWidth yPos = (itemWidth * row) + (spacingWidth * (row)) + marginWidth rect = Rect((xPos, yPos), (itemWidth, itemWidth)) if (isinstance(item, mapchar.MapChar)): images = [] icons = [item.images[0][0], item.images[1][0]] for i in range(len(icons)): icon = icons[i] iconRect = Rect((0, 0), icon.get_size()) iconRect.centerx = (rect.width / 2) iconRect.centery = (rect.height / 2) surface = pygame.Surface(rect.size) surface.fill(CHARACTER_SELECTION_DIALOG_BUTTON_COLOR) surface.blit(icon, iconRect.topleft) images.append(surface) self.buttons.append(DetailDialogButton(rect, images[0], images[1], item))
def drawZoomMap(self): #Draw winter to Map winterSize = self.mapWinterImage.get_size() dualMap = pygame.Surface(winterSize) dualMap.blit(self.mapWinterImage, (0, 0)) #Create Green Overlay sizeX = winterSize[0] - self.fimbulvetrPos sizeY = winterSize[1] if sizeX > 0 and sizeY > 0: greenOverlay = pygame.Surface((sizeX, sizeY)) greenOverlay.blit(self.mapOrigImage, (-self.fimbulvetrPos, 0)) #Draw green to map dualMap.blit(greenOverlay, (self.fimbulvetrPos, 0)) newSize = (int(self.map.mapSize[0] * self.zoomVal), int(self.map.mapSize[1] * self.zoomVal)) if not self.mapRect is None: diff = ((self.mapRect.width - newSize[0]), (self.mapRect.height - newSize[1])) newPos = ((self.mapRect.left + (diff[0] / 2)), (self.mapRect.top + (diff[1] / 2))) self.mapRect = Rect(newPos, newSize) else: self.mapRect = Rect((0, 0), newSize) self.mapImage = pygame.transform.scale(dualMap, newSize)
def setRect(self, pos, size): oldRect = Rect(pos, size) if self.isRight: xRef = oldRect.right else: xRef = oldRect.left self.rect = Rect((0, 0), self.image.get_size()) self.rect.center = (xRef, oldRect.centery)
def __init__(self, inPos, inChar): super(MapCharacterBar, self).__init__() self.character = inChar self.createEffectIcons() team = self.character.team b = MAP_CHAR_BAR_BORDER p = MAP_CHAR_BAR_PADDING ps = MAP_CHAR_BAR_PADDING_SMALL height = (MAP_CHAR_BAR_PORTRAIT_SIZE[1] + (b * 2) + (p * 2)) width = (MAP_CHAR_BAR_PORTRAIT_SIZE[0] + (b * 2) + (p * 4) + MAP_CHAR_BAR_ENERGY_BAR_SIZE[0] + EFFECT_ICON_SIZE[0]) self.rect = Rect(inPos, (width, height)) staticSurface = pygame.Surface((width, height)) staticSurface.fill(MAP_CHAR_BAR_COLOR_BORDER[team]) staticSurface.fill(MAP_CHAR_BAR_COLOR_BG[team], Rect((b, b), (width - (b * 2), height - (b * 2)))) staticSurface = staticSurface.convert() self.staticSurfaces = [] for i in range(2): self.staticSurfaces.append(copy.copy(staticSurface)) colorSwap(self.staticSurfaces[1], MAP_CHAR_BAR_COLOR_BORDER[team], MAP_CHAR_BAR_COLOR_SELECTED, 5) for s in self.staticSurfaces: s.blit(self.character.portrait, ((b + p), (b + p))) x = (b + (p * 2) + MAP_CHAR_BAR_PORTRAIT_SIZE[0]) y = (b + p + MAP_CHAR_BAR_PORTRAIT_SIZE[1] - MAP_CHAR_BAR_ENERGY_BAR_SIZE[1]) tempRect = Rect((x, y), MAP_CHAR_BAR_ENERGY_BAR_SIZE) self.superBar = energybar.EnergyBar( self.character.battleChar.superEnergy, tempRect, MAP_CHAR_BAR_ENERGY_BAR_BORDERS, SUPER_BAR_COLORS, 2) y = y - ps - MAP_CHAR_BAR_ENERGY_BAR_SIZE[1] tempRect = Rect((x, y), MAP_CHAR_BAR_ENERGY_BAR_SIZE) self.healthBar = energybar.EnergyBar(self.character.battleChar.hp, tempRect, MAP_CHAR_BAR_ENERGY_BAR_BORDERS, HEALTH_BAR_COLORS, 2, self.character.name, None, 3) self.setActive(False) self.pastHP = -1 self.pastSuperEnergy = -1
def createGoPanel(self): if (self.playerNum == 0 and (not self.readyPanels[0] is None and self.readyPanels[0].data.value == True) and (not self.readyPanels[1] is None and self.readyPanels[1].data.value == True)): rect = Rect((0,0), GO_PANEL_SIZE) rect.centerx = SCREEN_SIZE[0] / 2 rect.bottom = SCREEN_SIZE[1] - CHARACTER_SELECTION_PANEL_SPACING goPanel = Panel(0, True, rect) goPanel.setData(GoData()) self.goPanel = goPanel
def createBars(self): self.bars = [] p = self.players[self.cameraPlayer] q = self.players[self.reverse01(self.cameraPlayer)] x = BATTLE_PORTRAIT_SIZE[0] + HEALTH_BAR_OFFSET[ 0] + BATTLE_PORTRAIT_OFFSET[0] y = HEALTH_BAR_OFFSET[1] self.bars.append( energybar.EnergyBar(p.hp, Rect( (x, y), HEALTH_BAR_SIZE), HEALTH_BAR_BORDERS, HEALTH_BAR_COLORS, HEALTH_BAR_PULSE, p.name)) x = SCREEN_SIZE[0] - HEALTH_BAR_OFFSET[0] - HEALTH_BAR_SIZE[ 0] - BATTLE_PORTRAIT_SIZE[0] - BATTLE_PORTRAIT_OFFSET[0] y = HEALTH_BAR_OFFSET[1] self.bars.append( energybar.EnergyBar(q.hp, Rect((x, y), HEALTH_BAR_SIZE), HEALTH_BAR_BORDERS, HEALTH_BAR_COLORS, HEALTH_BAR_PULSE, q.name, None, 2, False)) x = (SCREEN_SIZE[0] / 2) - (RETREAT_BAR_SIZE[0] / 2) y = HEALTH_BAR_OFFSET[1] self.retreatBar = energybar.EnergyBar(self.retreatProhibitTime, Rect((x, y), RETREAT_BAR_SIZE), RETREAT_BAR_BORDERS, RETREAT_BAR_COLORS, 5, "Battle", None, 1) self.bars.append(self.retreatBar) x = BATTLE_PORTRAIT_SIZE[0] + HEALTH_BAR_OFFSET[ 0] + BATTLE_PORTRAIT_OFFSET[0] y = HEALTH_BAR_OFFSET[1] + HEALTH_BAR_SIZE[1] + SPECIAL_BAR_OFFSET if isinstance(p, hare.Hare): self.bars.append( energybar.EnergyBar(p.hareEnergy, Rect( (x, y), SPECIAL_BAR_SIZE), SPECIAL_BAR_BORDERS, SPECIAL_BAR_COLORS, SPECIAL_BAR_PULSE, HARE_ENERGY_NAME, HARE_ENERGY_USAGE)) if isinstance(p, cat.Cat): self.catBar = energybar.EnergyBar(p.catEnergy, Rect((x, y), SPECIAL_BAR_SIZE), SPECIAL_BAR_BORDERS, SPECIAL_BAR_COLORS, SPECIAL_BAR_PULSE, CAT_ENERGY_NAME, CAT_ENERGY_MAX + 1) self.bars.append(self.catBar)
def createGoPanel(self): if (self.playerNum == 0 and (not self.readyPanels[0] is None and self.readyPanels[0].data.value == True) and (not self.readyPanels[1] is None and self.readyPanels[1].data.value == True)): rect = Rect((0, 0), GO_PANEL_SIZE) rect.centerx = SCREEN_SIZE[0] / 2 rect.bottom = SCREEN_SIZE[1] - CHARACTER_SELECTION_PANEL_SPACING goPanel = Panel(0, True, rect) goPanel.setData(GoData()) self.goPanel = goPanel
def createTriggerArea(self, zoom): r = int(self.triggerSize * zoom) d = int(r * 2) self.triggerArea = pygame.Surface((d, d), SRCALPHA) self.triggerArea.fill((0, 0, 0, 0)) pygame.draw.circle(self.triggerArea, self.triggerColor, (r, r), r) self.triggerRect = Rect((0, 0), (d, d))
class PageArrow(object): def __init__(self, isRight, page): self.image = INTERFACE_GRAPHICS[4].copy() self.isRight = isRight if not isRight: self.image = pygame.transform.flip(self.image, True, False) self.visible = (page.maximum > 0) def setRect(self, pos, size): oldRect = Rect(pos, size) if self.isRight: xRef = oldRect.right else: xRef = oldRect.left self.rect = Rect((0, 0), self.image.get_size()) self.rect.center = (xRef, oldRect.centery) def draw(self, screen): if self.visible: screen.blit(self.image, self.rect.topleft) def mouseIsOver(self, mousePos): if not self.visible: return False return self.rect.collidepoint(mousePos)
def __init__(self, inRect, options, inFont, colorOn, colorOff, colorBG): self.rectSingle = inRect self.options = options if len(options) > 0: self.selection = boundint.BoundInt(1, len(options), 1, True) else: self.selection = None self.font = inFont lineSize = self.font.get_height() + self.font.get_linesize() if self.rectSingle.height < lineSize: self.rectSingle.height = lineSize h = self.rectSingle.height * len(self.options) if h <= 0: h = 1 self.rect = Rect(self.rectSingle.topleft, (self.rectSingle.width, h)) self.colorOn = colorOn self.colorOff = colorOff self.colorBG = colorBG self.noSelection = True self.slate = pygame.Surface((self.rect.width, self.rect.height)) self.slate.fill(colorBG) self.update()
def __init__(self): super(Model, self).__init__() self.fadeSurface = pygame.Surface(SCREEN_SIZE) self.fadeSurfaceColor = [] for i in range(3): self.fadeSurfaceColor.append( boundint.BoundInt(0, INTRO_MAX_FADE, 0)) self.transSurface = pygame.Surface(SCREEN_SIZE) self.transSurface.fill( (INTRO_MAX_FADE, INTRO_MAX_FADE, INTRO_MAX_FADE)) self.transAlpha = boundint.BoundInt(0, 255, 255) self.centerTextPos = (0, SCREEN_SIZE[1] / 2) self.stage = 0 self.ticker = 0 self.textMessages = [("Games from Beyond the Farth", 2, ALMOST_BLACK, WHITE, 1, True)] self.textRects = [] for i in self.textMessages: f = FONTS[i[1]] size = (SCREEN_SIZE[0], f.get_linesize() + f.get_height()) tempRect = Rect((0, 0), size) self.textRects.append( textrect.render_textrect(i[0], f, tempRect, i[2], i[3], i[4], i[5]))
def __init__(self, inRect, inImage): self.mainRect = inRect self.mainPane = pygame.Surface( (self.mainRect.width, self.mainRect.height)) pattern = inImage imageSize = inImage.get_size() tempFloat = float(float(inRect.width) / float(imageSize[0])) repeatX = int(math.ceil(tempFloat)) tempFloat = float(float(inRect.height) / float(imageSize[1])) repeatY = int(math.ceil(tempFloat)) sizeX = repeatX * imageSize[0] sizeY = repeatY * imageSize[0] self.subRect = Rect((0, 0), (sizeX, sizeY)) self.subPane = pygame.Surface( (self.subRect.width, self.subRect.height)) for x in range(repeatX): for y in range(repeatY): self.subPane.blit(pattern, ((x * imageSize[0]), (y * imageSize[1]))) self.mainPane.blit(self.subPane, self.subRect.topleft)
def makeMenu(self): if self.stage == 0: if self.isSelectionScreen: menuOptions = ["New", "Delete", "Change Power", "Select"] else: menuOptions = ["New", "Delete", "Change Power", "Done"] elif self.stage == 1: menuOptions = [] self.getSpeciesList() for s in self.currSpeciesList: menuOptions.append(s.speciesName) elif self.stage == 2: menuOptions = [] for i in self.characterToDisplay.superMoves: menuOptions.append(i.name) elif self.stage == 101: menuOptions = ["Nevermind...", "Delete"] tempRect = Rect((50, 50), (200, 0)) self.menu = minimenu.MiniMenu(tempRect, menuOptions, CHAR_EDITOR_FONT, CHAR_EDITOR_COLOR_ON, CHAR_EDITOR_COLOR_OFF, CHAR_EDITOR_COLOR_BG) self.menu.rect.center = (SCREEN_SIZE[0] / 2, SCREEN_SIZE[1] / 2)
def setCharacter(self, c): self.character = c self.panel = pygame.Surface(CHARACTER_SELECT_PANEL_SIZE) self.panel.blit(self.backPanel, (0, 0)) if not self.character is None: font = CHARACTER_SELECTION_FONT msg = self.character.name textHeight = font.get_linesize() + 2 tempRect = Rect((0, 0), (CHARACTER_SELECT_PANEL_SIZE[0], textHeight)) text = textrect.render_textrect(msg, font, tempRect, CHARACTER_SELECTION_FONT_COLOR, ALMOST_BLACK, 1, True) tempRect = Rect((0, 0), text.get_size()) tempRect.left = (CHARACTER_SELECT_PANEL_SIZE[0] / 2) - (tempRect.width / 2) tempRect.top = (CHARACTER_SELECT_PANEL_SIZE[1] / 2) - (tempRect.height / 2) self.panel.blit(text, tempRect.topleft)
def printText(screen, mousePos): pos = getZoomPos(mousePos) pixelPos = posRelatedToAnchor(pos) text = textrect.render_textrect( str(pixelPos), FONTS[0], Rect( (0, 0), (SCREEN_SIZE[0], SCREEN_SIZE[1])), (250, 250, 250), (5, 5, 5), 0, True) screen.blit(text, (mousePos[0] + 15, mousePos[1] - 10))
def __init__(self, team, waypoint=False): if waypoint: self.image = INTERFACE_GRAPHICS[11] else: self.image = INTERFACE_GRAPHICS[2] colorSwap(self.image, (250, 250, 250, 255), TOKEN_BORDER_OFF[team], 200) self.rect = Rect((0, 0), self.image.get_size())
def setCameraPlayer(self, c): if (c >= 0) and (c <= 1): self.cameraPlayer = c self.createBars() self.youIconImage = INTERFACE_GRAPHICS[18] colorSwap(self.youIconImage, (215, 215, 215, 255), TOKEN_BORDER_HIGHLIGHTED[self.cameraPlayer], 200) self.youIconRect = Rect((0, 0), self.youIconImage.get_size())
def getBoxAbsRect(self, box, inOffset): if self.facingRight: boxPos = box.rect.topleft else: boxPos = flipRect(box.rect) topleft = add_points(add_points(self.preciseLoc, boxPos), inOffset) return Rect(topleft, box.rect.size)
def __init__(self): super(Model, self).__init__() tempRect = Rect( (50, 50), (200, 0) ) menuOptions = ["Combat Debug", "Map Debug", "Character Select Debug", "Play Game Normally", "Exit"] self.debugMenu = minimenu.MiniMenu(tempRect, menuOptions, MINIMENU_FONT, (250, 250, 250), (125, 125, 125), (15, 15, 15)) self.debugMenu.center(ENTIRE_SCREEN, True, True)
def __init__(self, time): self.time = time self.tick = boundint.BoundInt(0, FRAME_RATE, 0, True) size = (SCREEN_SIZE[0], COUNTDOWN_FONT.get_linesize() + 4) pos = (0, (SCREEN_SIZE[1] / 2) - (size[1] / 2) - 15) self.rect = Rect(pos, size) self.startFlag = False self.updateImage()
def buildHurtboxes(self, data): self.hurtboxes = [] for d in data: topleft = (d[0], d[1]) width = d[2] - d[0] height = d[3] - d[1] size = (width, height) rect = Rect(topleft, size) self.hurtboxes.append(hurtbox.Hurtbox(rect))
def createDescription(self, name=None, desc=None): if name is None: self.descSurface = None else: text = str(name + "\n\n" + desc) self.descSurface = textrect.render_textrect( text, CHAR_EDITOR_FONT, Rect(self.charMenu.rect.topleft, self.idealSize), CHAR_EDITOR_COLOR_OFF, CHAR_EDITOR_BLACK_PANEL_COLOR)
def __init__(self, title, banList=[], ip=False, maxLength=None): super(Model, self).__init__() if maxLength is None: self.maxLength = TEXT_ENTRY_LENGTH_MAX else: self.maxLength = maxLength self.ipCheck = ip self.font = TEXT_ENTRY_FONT self.response = [] self.banList = banList size = (TEXT_ENTRY_LINE_WIDTH + (TEXT_ENTRY_BORDER_SIZE * 2), self.font.get_linesize() + self.font.get_height() + (TEXT_ENTRY_BORDER_SIZE * 2)) pos = [0, 0] for i in range(2): pos[i] = (SCREEN_SIZE[i] / 2) - (size[i] / 2) self.rect = Rect(pos, size) self.base = pygame.Surface(size) self.base.fill(BLACK) pygame.draw.rect(self.base, WHITE, (0, 0, size[0], size[1]), 1) pygame.draw.rect( self.base, WHITE, (0 + TEXT_ENTRY_BORDER_SIZE, 0 + TEXT_ENTRY_BORDER_SIZE, size[0] - (TEXT_ENTRY_BORDER_SIZE * 2), size[1] - (TEXT_ENTRY_BORDER_SIZE * 2)), 1) self.updateImage() size = (self.rect.width, self.font.get_linesize() + self.font.get_height()) self.titleRect = Rect((0, 0), size) self.titleRect.bottom = self.rect.top self.titleRect.left = self.rect.left temp = textrect.render_textrect(title, self.font, self.titleRect, WHITE, BLACK, 1) self.titlePanel = pygame.Surface(size) self.titlePanel.blit(temp, (0, (size[1] / 2) - (self.font.get_linesize() / 2)))
def __init__(self, image, pos, anchor, scale): self.image = image self.scale = scale self.rect = Rect(pos, image.get_size()) self.rect.left -= anchor[0] self.rect.top -= anchor[1] self.anchor = anchor print self.rect.topleft
def createSuperIcons(self): self.superIcons = [] x = self.iconRect.left y = self.iconRect.top + self.iconRect.height + UNIT_HUD_BORDER_WIDTH for c in self.characters: icon = battle_v.SuperIcon(Rect((x, y), BATTLE_SUPER_ICON_SIZE), c.battleChar.getSuperIcon(), c.battleChar.superEnergy) self.superIcons.append(icon)
def setButton(self, val): if not (val == self.enabled): self.enabled = val self.panel = pygame.Surface(self.rect.size) self.panel.blit(self.backPanel, (0, 0)) if self.enabled: color = CHARACTER_SELECTION_BUTTON_COLOR_ON else: color = CHARACTER_SELECTION_BUTTON_COLOR_OFF font = CHARACTER_SELECTION_FONT textHeight = font.get_linesize() + 2 tempRect = Rect((0, 0), (self.rect.width, textHeight)) text = textrect.render_textrect(self.msg, font, tempRect, color, ALMOST_BLACK, 1, True) tempRect = Rect((0, 0), text.get_size()) tempRect.top = (CHARACTER_SELECT_PANEL_SIZE[1] / 2) - (tempRect.height / 2) self.panel.blit(text, tempRect.topleft)
def printList(screen): global boxList for i, b in enumerate(boxList): pos = (0, i * 15) line = (str(posRelatedToAnchor(b[1].topleft)) + " - " + str(posRelatedToAnchor(b[1].bottomright))) text = textrect.render_textrect( line, FONTS[0], Rect((0, 0), (SCREEN_SIZE[0], SCREEN_SIZE[1])), (250, 250, 250), (5, 5, 5), 0, True) screen.blit(text, pos)
def buildIdealSize(self): tempList = [] for i in range(CHAR_EDITOR_NUM_PER_PAGE): tempList.append("!") tempRect = Rect((50, 50), (200, 0)) temp = minimenu.MiniMenu(tempRect, tempList, CHAR_EDITOR_FONT, CHAR_EDITOR_COLOR_ON, CHAR_EDITOR_COLOR_OFF, CHAR_EDITOR_BLACK_PANEL_COLOR) return temp.rect.size
def setImage(self, inImage, o): size = inImage.get_size() if self.facingRight: offset = o self.image = inImage else: offset = (-o[0] + size[0], o[1]) self.image = pygame.transform.flip(inImage, True, False) self.offset = offset self.rect = Rect(self.getRectPos(), size)
def selectMap(self, map, wasRandom): self.mapPanel.setData(MapData(map, wasRandom)) numOfCharacterSlots = 0 if not map is None: numOfCharacterSlots = len(map.startingPoints[0]) self.characterPanels = [] for i in range(2): xMid = (SCREEN_SIZE[0] / 4) * (1 + (i * 2)) yMid = SCREEN_SIZE[1] / 2 if (numOfCharacterSlots % 2 == 0): numToDisplaceFromCenter = (numOfCharacterSlots / 2) - 1 yMid -= (CHARACTER_SELECTION_PANEL_SPACING / 2) + (CHARACTER_SELECTION_PANEL_SIZE[1] / 2) else: numToDisplaceFromCenter = int(numOfCharacterSlots / 2) yMid -= (CHARACTER_SELECTION_PANEL_SPACING + CHARACTER_SELECTION_PANEL_SIZE[1]) * numToDisplaceFromCenter for j in range(numOfCharacterSlots): rect = Rect((0,0), CHARACTER_SELECTION_PANEL_SIZE) rect.centerx = xMid rect.centery = yMid + ((CHARACTER_SELECTION_PANEL_SPACING + CHARACTER_SELECTION_PANEL_SIZE[1]) * j) self.characterPanels.append(Panel(i, (self.playerNum == i), rect)) rect = rect = Rect((0,0), READY_PANEL_SIZE) rect.centerx = xMid rect.bottom = SCREEN_SIZE[1] - CHARACTER_SELECTION_PANEL_SPACING readyPanel = Panel(i, (self.playerNum == i), rect) readyPanel.faceUp = True readyPanel.setData(ReadyData(False)) self.readyPanels[i] = readyPanel self.subScreen = 0
def __init__(self, isHost): super(Model, self).__init__() self.bgs = [scrollingbackground.ScrollingBackground(Rect((0, 0), SCREEN_SIZE), CHARACTER_SELECT_BG_SKY, [0, 0]), scrollingbackground.ScrollingBackground(Rect((0, SCREEN_SIZE[1] - CHARACTER_SELECT_BG_MOUNTAINS_FAR.get_size()[1] - 70), SCREEN_SIZE), CHARACTER_SELECT_BG_MOUNTAINS_FAR, [-0.3, 0]), scrollingbackground.ScrollingBackground(Rect((0, SCREEN_SIZE[1] - CHARACTER_SELECT_BG_MOUNTAINS_NEAR.get_size()[1]), SCREEN_SIZE), CHARACTER_SELECT_BG_MOUNTAINS_NEAR, [-0.8, 0]) ] self.starting = False self.map = None self.netMessage = None self.subScreen = 0 if isHost: self.playerNum = 0 else: self.playerNum = 1 #Create Map-selection Panel rect = Rect((0,0), CHARACTER_SELECTION_PANEL_SIZE) rect.centerx = SCREEN_SIZE[0] / 2 rect.top = CHARACTER_SELECTION_PANEL_SPACING self.mapPanel = Panel(0, isHost, rect) self.characterPanels = [] tempRect = Rect( (50, 50), (200, 0) ) menuOptions = [] for map in gamemap.getMapList(): menuOptions.append(map.name + " (" + str(len(map.startingPoints[0])) + ")") menuOptions.append("<RANDOM>") self.mapMenu = minimenu.MiniMenu(tempRect, menuOptions, MAIN_MENU_FONT, MAIN_MENU_COLOR_ON, MAIN_MENU_COLOR_OFF, MAIN_MENU_COLOR_BG) self.mapMenu.center(ENTIRE_SCREEN, True, True) #Create Species Selection Menu speciesClasses = [(mapchar.Hare, hare.Hare), (mapchar.Cat, cat.Cat)] speciesList = [] for speciesClassGroup in speciesClasses: mapClass = speciesClassGroup[0] battleClass = speciesClassGroup[1] speciesList.append(mapClass(self.playerNum, battleClass())) self.speciesDialog = DetailDialog(SPECIES_SELECTION_DIALOG_SLOT_SIZE, SPECIES_SELECTION_DIALOG_MARGIN, SPECIES_SELECTION_DIALOG_SPACING, speciesList, [4, 2] ) self.currCharacterPanel = None self.readyPanels = [None, None] self.goPanel = None
def update(self): if (self.redraw): #Draw Panel Surface if (self.data is None or (isinstance(self.data, ReadyData) and self.data.value == False)): paletteBase = CHARACTER_SELECT_PANEL_BASE_COLORS_OFF paletteDecor = CHARACTER_SELECT_PANEL_DECOR_COLORS_OFF else: paletteBase = CHARACTER_SELECT_PANEL_BASE_COLORS_ON paletteDecor = CHARACTER_SELECT_PANEL_DECOR_COLORS_ON colorBase = paletteBase[self.team] colorDecor = paletteDecor[self.team] self.image = pygame.Surface(self.rect.size) self.image.fill(colorBase) showFront = self.faceUp or self.isOwner if (showFront): decorMargin = CHARACTER_SELECT_PANEL_FACE_DECOR_MARGIN decorWidth = CHARACTER_SELECT_PANEL_FACE_DECOR_WIDTH else: decorMargin = CHARACTER_SELECT_PANEL_BACK_DECOR_MARGIN decorWidth = CHARACTER_SELECT_PANEL_BACK_DECOR_WIDTH decorOuter = pygame.Surface((self.rect.width - (decorMargin * 2), self.rect.height - (decorMargin * 2))) decorOuter.fill(colorDecor) decorInner = pygame.Surface((decorOuter.get_size()[0] - (decorWidth * 2), decorOuter.get_size()[1] - (decorWidth * 2))) decorInner.fill(colorBase) if (not showFront): margins = CHARACTER_SELECT_PANEL_BACK_CIRCLE_MARGINS ovalRect = Rect((margins[0], margins[1]), (decorInner.get_size()[0] - (margins[0] * 2), decorInner.get_size()[1] - (margins[1] * 2))) pygame.draw.ellipse(decorInner, colorDecor, ovalRect) decorOuter.blit(decorInner, (decorWidth, decorWidth)) self.image.blit(decorOuter, (decorMargin, decorMargin)) #Fill Data fillRect = Rect(((decorWidth + decorMargin), (decorWidth + decorMargin)), decorInner.get_size()) if isinstance(self.data, mapchar.MapChar): font = CHARACTER_SELECTION_CAPTION_FONT textHeight = font.get_linesize() + 2 tRect = Rect((0,0), (fillRect.width - 10, textHeight)) tRect.centerx = fillRect.centerx tRect.centery = fillRect.centery text = textrect.render_textrect(self.data.name, font, tRect, CHARACTER_SELECTION_FONT_COLOR, ALMOST_BLACK, 0, True) self.image.blit(text, tRect.topleft) speciesImage = self.data.getSmallImage() speciesRect = Rect((0, 0), speciesImage.get_size()) speciesRect.right = tRect.right speciesRect.centery = self.rect.height / 2 self.image.blit(speciesImage, speciesRect.topleft) elif isinstance(self.data, MapData): font = CHARACTER_SELECTION_CAPTION_FONT textHeight = font.get_linesize() + 2 tRect = Rect((0,0), (fillRect.width - 10, textHeight)) tRect.centerx = fillRect.centerx tRect.centery = fillRect.centery text = textrect.render_textrect(self.data.map.name, font, tRect, CHARACTER_SELECTION_FONT_COLOR, ALMOST_BLACK, 0, True) self.image.blit(text, tRect.topleft) if self.data.wasRandom: image = RANDOM_ICON rect = Rect((0,0), image.get_size()) rect.right = fillRect.right rect.centery = fillRect.centery self.image.blit(image, rect.topleft) elif isinstance(self.data, ReadyData): font = CHARACTER_SELECTION_CAPTION_FONT font = CHARACTER_SELECTION_CAPTION_FONT textHeight = font.get_linesize() + 2 tRect = Rect((0,0), (fillRect.width - 10, textHeight)) tRect.centerx = fillRect.centerx tRect.centery = fillRect.centery if self.data.value: color = READY_PANEL_FONT_COLOR_TRUE text = "READY" else: color = READY_PANEL_FONT_COLOR_FALSE text = "PREPARING..." text = textrect.render_textrect(text, font, tRect, color, ALMOST_BLACK, 1, True) self.image.blit(text, tRect.topleft) if isinstance(self.data, GoData): font = CHARACTER_SELECTION_CAPTION_FONT font = CHARACTER_SELECTION_CAPTION_FONT textHeight = font.get_linesize() + 2 tRect = Rect((0,0), (fillRect.width - 10, textHeight)) tRect.centerx = fillRect.centerx tRect.centery = fillRect.centery color = READY_PANEL_FONT_COLOR_TRUE text = "GO!" text = textrect.render_textrect(text, font, tRect, color, ALMOST_BLACK, 1, True) self.image.blit(text, tRect.topleft) self.redraw = False
def __init__(self, theMap, isHost): super(Model, self).__init__() self.theMap = theMap self.openEditor = False self.sendNetMessage = False self.starting = False self.bg = pygame.Surface(SCREEN_SIZE) self.bg.fill(CHARACTER_SELECT_BG_COLOR) self.group = CharacterPanelGroup(self.theMap.numOfCharactersPerTeam()) self.currSelected = None x = (CHARACTER_SELECT_PANEL_SELECTION_BORDER_WIDTH * 2) + CHARACTER_SELECT_PANEL_SIZE[0] y = (CHARACTER_SELECT_PANEL_SELECTION_BORDER_WIDTH * 2) + CHARACTER_SELECT_PANEL_SIZE[1] self.selectionBorder = pygame.Surface((x, y)) self.selectionBorder.fill(CHARACTER_SELECT_PANEL_SELECTION_BORDER_COLOR) tempRect = Rect((0, 0), CHARACTER_SELECT_PLAYER_SIZE) tempRect.bottom = SCREEN_SIZE[1] - CHARACTER_SELECT_GROUP_FROM_TOP tempRect.centerx = SCREEN_SIZE[0] / 2 self.clientPanel = PlayerPanel(tempRect, "Client", self.group.num) tempRect = Rect((0, 0), CHARACTER_SELECT_PLAYER_SIZE) tempRect.bottom = self.clientPanel.rect.top - CHARACTER_SELECT_GROUP_SPACING tempRect.centerx = SCREEN_SIZE[0] / 2 self.hostPanel = PlayerPanel(tempRect, "Host", self.group.num) if isHost: self.myPanel = self.hostPanel self.theirPanel = self.clientPanel else: self.myPanel = self.clientPanel self.theirPanel = self.hostPanel tempRect = Rect((0, 0), CHARACTER_SELECT_BUTTON_SIZE) tempRect.left = self.myPanel.rect.right + CHARACTER_SELECT_GROUP_SPACING tempRect.top = self.myPanel.rect.top self.readyButton = Button(tempRect, "Ready") if isHost: tempRect = Rect((0, 0), CHARACTER_SELECT_BUTTON_SIZE) tempRect.left = self.theirPanel.rect.right + CHARACTER_SELECT_GROUP_SPACING tempRect.top = self.theirPanel.rect.top self.startButton = Button(tempRect, "Start") else: self.startButton = None x = (CHARACTER_SELECT_PANEL_SELECTION_BORDER_WIDTH * 2) + CHARACTER_SELECT_BUTTON_SIZE[0] y = (CHARACTER_SELECT_PANEL_SELECTION_BORDER_WIDTH * 2) + CHARACTER_SELECT_BUTTON_SIZE[1] self.selectionBorderButton = pygame.Surface((x, y)) self.selectionBorderButton.fill(CHARACTER_SELECT_PANEL_SELECTION_BORDER_COLOR) self.loadingImage = INTERFACE_GRAPHICS[9] self.loadingRect = Rect((0, 0), self.loadingImage.get_size()) self.loadingRect.center = (SCREEN_SIZE[0] / 2, SCREEN_SIZE[1] / 2)
def __init__(self, inChars, terrainLeft, terrainRight): super(Model, self).__init__() self.rect = Rect((0, 0), BATTLE_ARENA_SIZE) self.testBool = False self.testBool2 = False self.players = inChars for p in self.players: p.beginBattle() pos = (self.rect.centerx, self.rect.height - BATTLE_AREA_FLOOR_HEIGHT) self.players[0].setLoc(add_points(pos, ((-BATTLE_PLAYER_START_DISTANCE / 2), 0))) self.players[0].facingRight = True self.players[1].setLoc(add_points(pos, ((BATTLE_PLAYER_START_DISTANCE / 2), 0))) self.players[1].facingRight = False self.keys = [[False, False, False, False, False, False, False, False, False], [False, False, False, False, False, False, False, False, False]] self.keysNow = [[0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0]] self.frameByFrame = [0, 0] self.returnCode = [0, 0] self.projectiles = [] self.retreatProhibitTime = boundint.BoundInt(0, RETREAT_PROHIBIT_TIME, RETREAT_PROHIBIT_TIME) self.retreatPhase = 0 self.cameraPlayer = 0 self.netPlayer = 0 self.catBar = None self.createBars() self.resetHitMemory() self.endingVal = -1 self.endingValTick = 0 self.fx = [] self.platforms = getPlatforms(terrainLeft, terrainRight) self.countdown = countdown.Countdown(BATTLE_COUNTDOWN_LENGTH) self.createEndingText() self.damageTagRects = [] self.damagePercentRects = [] for i in range(2): rect = Rect((0, 0), (80, 100)) if (i == 0): rect.left = 0 else: rect.right = SCREEN_SIZE[0] rect.top = SCREEN_SIZE[1] - 55 self.damageTagRects.append(rect) rect2 = Rect((0, 0), (80, 100)) if (i == 0): rect2.left = 0 else: rect2.right = SCREEN_SIZE[0] rect2.top = rect.top + 18 self.damagePercentRects.append(rect2) self.damageTag = textrect.render_textrect("Strength", STRUCTURE_COUNT_FONT, self.damageTagRects[0], ALMOST_BLACK, BLACK, 1, True)