def draw_opponent_pokemon(self): left, top = self.left_top_coords_of_box(9, 0.5) size = self.boxsize * 4 # pygame.draw.rect(self.displaySurface, WHITE, (left, top, size, size)) opponentImage = load_pokemon_sprite(self.opposingPokemon) opponentImage = pygame.transform.scale(opponentImage, (size, size)) self.displaySurface.blit(opponentImage, (left, top)) left, top = self.left_top_coords_of_box(0.75, 0.75) pygame.draw.rect(self.displaySurface, SILVER, (left, top, self.boxsize * 6.125, self.boxsize * 1.5)) pygame.draw.rect(self.displaySurface, BLACK, (left, top, self.boxsize * 6.125, self.boxsize * 1.5), self.halfLinewidth) left, top = self.left_top_coords_of_box(1, 1) opponentText = '{:10s}'.format(self.opposingPokemon.name) textSurf, textRect = make_text(opponentText, BLACK, SILVER, left, top, size=self.textSize) self.displaySurface.blit(textSurf, textRect) left, top = self.left_top_coords_of_box(4.75, 1) opponentText = 'lv.{:2d}'.format(self.opposingPokemon.level) textSurf, textRect = make_text(opponentText, BLACK, SILVER, left, top, size=self.textSize) self.displaySurface.blit(textSurf, textRect)
def draw_player_status(self): hpPct, color = self.playerPokemon.hp_bar() left, top = self.left_top_coords_of_box(10, 5.5) playerText = self.playerPokemon.status.displayText.center(5) if playerText != ''.center(5): textSurf, textRect = make_text( playerText, BLACK, self.playerPokemon.status.displayColor, left, top, size=self.textSize) textRect.right = left pygame.draw.rect( self.displaySurface, BLACK, (textRect.left, textRect.top, textRect.width, textRect.height), self.halfLinewidth) self.displaySurface.blit(textSurf, textRect) else: textSurf, textRect = make_text('HP', GOLD, BLACK, left, top, size=self.textSize) textRect.right = left pygame.draw.rect( self.displaySurface, BLACK, (textRect.left, textRect.top, textRect.width, textRect.height), self.halfLinewidth) self.displaySurface.blit(textSurf, textRect) hpBarLength = int(self.boxsize * 3.5) hpBarHeight = textRect.height left, top = self.left_top_coords_of_box(10, 5.5) pygame.draw.rect(self.displaySurface, SILVER, (left, top, hpBarLength, hpBarHeight)) if hpPct != 0: pygame.draw.rect( self.displaySurface, color, (left, top, int(hpBarLength * hpPct), hpBarHeight)) pygame.draw.rect(self.displaySurface, BLACK, (left, top, hpBarLength, hpBarHeight), self.halfLinewidth) left, top = self.left_top_coords_of_box(10, 6) hpText = '{:3d}/{:3d}'.format(self.playerPokemon.hp, self.playerPokemon.maxHp) textSurf, textRect = make_text(hpText, BLACK, SILVER, left, top, size=self.textSize) # textRect.right = left self.displaySurface.blit(textSurf, textRect)
def draw_messages(self, messages): pygame.draw.rect(self.displaySurface, WHITE, (40, 575, 297, 90)) pygame.draw.rect(self.displaySurface, WHITE, (350, 575, 200, 90)) for message in messages: self.mixer.play_queue() words = message.split(' ') pygame.draw.rect(self.displaySurface, WHITE, (40, 575, 297, 90)) surf, rect = make_text(' '.join(words[:2]), BLACK, WHITE, 40, 575, size=20) self.displaySurface.blit(surf, rect) surf, rect = make_text(' '.join(words[2:]), BLACK, WHITE, 40, 625, size=20) self.displaySurface.blit(surf, rect) pygame.display.update() if self.mixer.get_busy(): wait_for_sound(self.mixer) wait_for_click()
def draw_attack_stats(self, attack): left, top = self.left_top_coords_of_box(10, 7) commandPosition = (left, top, int(self.boxsize * 4.5), int(self.boxsize * 2.5)) pygame.draw.rect(self.displaySurface, WHITE, commandPosition) pygame.draw.rect(self.displaySurface, BLACK, commandPosition, self.linewidth) # pygame.draw.rect(self.displaySurface, WHITE, (350, 575, 200, 90)) left, top = self.left_top_coords_of_box(10.5, 7.5) surf, rect = make_text(attack.type, BLACK, typeColorDict[attack.type], left, top, size=self.textSize) self.displaySurface.blit(surf, rect) left, top = self.left_top_coords_of_box(10.5, 8.5) ppText = 'PP {:2}/{:2}'.format(attack.pp, attack.maxPP) surf, rect = make_text(ppText, BLACK, WHITE, left, top, size=self.textSize) self.displaySurface.blit(surf, rect) pygame.display.update()
def draw_attack_stats(self, attack): pygame.draw.rect(self.displaySurface, WHITE, (350, 575, 200, 90)) surf, rect = make_text(attack.type, BLACK, typeColorDict[attack.type], 350, 575, size=20) self.displaySurface.blit(surf, rect) ppText = 'PP {:2}/{:2}'.format(attack.pp, attack.maxPP) surf, rect = make_text(ppText, BLACK, WHITE, 350, 625, size=20) self.displaySurface.blit(surf, rect) pygame.display.update()
def draw_exp_bar(self): expPct = self.playerPokemon.exp_bar_length() left, top = self.left_top_coords_of_box(9, 6.5) textSurf, textRect = make_text('EXP', GOLD, BLACK, left, top, size=self.textSize) textRect.right = left pygame.draw.rect(self.displaySurface, BLACK, textRect, self.halfLinewidth) expBarLength = self.boxsize * 4.5 expBarHeight = textRect.height self.displaySurface.blit(textSurf, textRect) if expPct != 0: pygame.draw.rect( self.displaySurface, BLUE, (left, top, int(expBarLength * expPct), expBarHeight)) pygame.draw.rect(self.displaySurface, BLACK, (left, top, expBarLength, expBarHeight), self.halfLinewidth)
def draw_opponent_pokemon(self): pygame.draw.rect(self.displaySurface, WHITE, (300, 50, 250, 250)) opponentImage = load_pokemon_sprite(self.opposingPokemon) opponentImage = pygame.transform.scale(opponentImage, (250, 250)) self.displaySurface.blit(opponentImage, (300, 50)) opponentText = '{:11s}'.format(self.opposingPokemon.name) textSurf, textRect = make_text(opponentText, BLACK, WHITE, 50, 45) self.displaySurface.blit(textSurf, textRect) opponentText = 'lv.{:2d}'.format(self.opposingPokemon.level) textSurf, textRect = make_text(opponentText, BLACK, WHITE, 50, 70, size=18) self.displaySurface.blit(textSurf, textRect)
def draw_opponent_status(self): hpPct, color = self.opposingPokemon.hp_bar() left, top = self.left_top_coords_of_box(2.5, 1.5) opponentText = self.opposingPokemon.status.displayText.center(5) if opponentText != ''.center(5): textSurf, textRect = make_text( opponentText, BLACK, self.opposingPokemon.status.displayColor, left, top, size=self.textSize) textRect.right = left pygame.draw.rect( self.displaySurface, BLACK, (textRect.left, textRect.top, textRect.width, textRect.height), self.halfLinewidth) self.displaySurface.blit(textSurf, textRect) else: textSurf, textRect = make_text('HP', GOLD, BLACK, left, top, size=self.textSize) textRect.right = left pygame.draw.rect( self.displaySurface, BLACK, (textRect.left, textRect.top, textRect.width, textRect.height), self.halfLinewidth) self.displaySurface.blit(textSurf, textRect) hpBarLength = int(self.boxsize * 3.5) hpBarHeight = textRect.height pygame.draw.rect(self.displaySurface, SILVER, (left, top, hpBarLength, hpBarHeight)) if hpPct != 0: pygame.draw.rect( self.displaySurface, color, (left, top, int(hpBarLength * hpPct), hpBarHeight)) pygame.draw.rect(self.displaySurface, BLACK, (left, top, hpBarLength, hpBarHeight), self.halfLinewidth)
def draw_messages(self, messages, skipLastClick=False): left, top = self.left_top_coords_of_box(0.5, 7) messagePosition = (left, top, self.boxsize * 9, int(self.boxsize * 2.5)) pygame.draw.rect(self.displaySurface, WHITE, messagePosition) pygame.draw.rect(self.displaySurface, BLACK, messagePosition, self.linewidth) for i, message in enumerate(messages): self.mixer.play_queue() words = message.split(' ') left, top = self.left_top_coords_of_box(0.5, 7) pygame.draw.rect(self.displaySurface, WHITE, messagePosition) pygame.draw.rect(self.displaySurface, BLACK, messagePosition, self.linewidth) left, top = self.left_top_coords_of_box(1, 7.5) surf, rect = make_text(' '.join(words[:2]), BLACK, WHITE, left, top, size=self.textSize) self.displaySurface.blit(surf, rect) left, top = self.left_top_coords_of_box(1, 8.5) surf, rect = make_text(' '.join(words[2:]), BLACK, WHITE, left, top, size=self.textSize) self.displaySurface.blit(surf, rect) pygame.display.update() if self.mixer.get_busy(): wait_for_sound(self.mixer) # if (i+1) != len(messages): # wait_for_click() # elif not skipLastClick: # wait_for_click() # else: # # wait_for_sound() # # pass wait_for_click()
def draw_player_status(self): hpPct, color = self.playerPokemon.hp_bar() pygame.draw.rect(self.displaySurface, BLACK, (350, 470, 200, 30), 4) pygame.draw.rect(self.displaySurface, WHITE, (352, 472, 196, 26)) if hpPct != 0: pygame.draw.rect(self.displaySurface, color, (352, 472, int(196 * hpPct), 26)) hpText = 'HP {:3}/{:3}'.format(self.playerPokemon.hp, self.playerPokemon.maxHp) textSurf, textRect = make_text(hpText, BLACK, WHITE, 350, 505) self.displaySurface.blit(textSurf, textRect) playerText = self.playerPokemon.status.displayText.center(5) textSurf, textRect = make_text(playerText, BLACK, self.playerPokemon.status.displayColor, 475, 425) self.displaySurface.blit(textSurf, textRect)
def draw_player_pokemon(self): pygame.draw.rect(self.displaySurface, WHITE, (50, 300, 250, 250)) playerImage = load_pokemon_sprite(self.playerPokemon, frontBack='back') playerImage = pygame.transform.scale(playerImage, (250, 250)) # playerImage = pygame.transform.flip(playerImage, True, False) self.displaySurface.blit(playerImage, (50, 300)) playerText = '{:11s}'.format(self.playerPokemon.name) textSurf, textRect = make_text(playerText, BLACK, WHITE, 350, 420) self.displaySurface.blit(textSurf, textRect) playerText = 'lv.{:2d}'.format(self.playerPokemon.level) textSurf, textRect = make_text(playerText, BLACK, WHITE, 350, 445, size=18) self.displaySurface.blit(textSurf, textRect) self.draw_exp_bar()
def draw_set_params(): keys = setParams.keys() rects = [] left, top = left_top_coords_of_box(11.75, 16.25, mapArea=False) pygame.draw.rect(DISPLAYSURF, WHITE, (left, top, BOXSIZE * 9, BOXSIZE * 5), 4) for i, key in enumerate(keys): left, top = left_top_coords_of_box(12, 16.5 + (i / 2), mapArea=False) text = '%s: %s' % (key, setParams[key]) surf, rect = make_text(text, WHITE, BLACK, left, top, size=FONTSIZE) DISPLAYSURF.blit(surf, rect) rects.append(rect) return rects
def draw_opponent_status(self): hpPct, color = self.opposingPokemon.hp_bar() pygame.draw.rect(self.displaySurface, BLACK, (50, 95, 200, 30), 4) pygame.draw.rect(self.displaySurface, WHITE, (52, 97, 196, 26)) if hpPct != 0: pygame.draw.rect(self.displaySurface, color, (52, 97, int(196 * hpPct), 26)) opponentText = self.opposingPokemon.status.displayText.center(5) textSurf, textRect = make_text( opponentText, BLACK, self.opposingPokemon.status.displayColor, 175, 50) self.displaySurface.blit(textSurf, textRect)
def draw_player_pokemon(self): left, top = self.left_top_coords_of_box(2, 3) size = self.boxsize * 4 # pygame.draw.rect(self.displaySurface, WHITE, (left, top, size, size)) playerImage = load_pokemon_sprite(self.playerPokemon, frontBack='back') playerImage = pygame.transform.scale(playerImage, (size, size)) # playerImage = pygame.transform.flip(playerImage, True, False) self.displaySurface.blit(playerImage, (left, top)) left, top = self.left_top_coords_of_box(7.75, 4.75) pygame.draw.rect(self.displaySurface, SILVER, (left, top, self.boxsize * 6.125, self.boxsize * 2.5)) pygame.draw.rect(self.displaySurface, BLACK, (left, top, self.boxsize * 6.125, self.boxsize * 2.5), self.halfLinewidth) left, top = self.left_top_coords_of_box(8, 5) playerText = '{:10s}'.format(self.playerPokemon.name) textSurf, textRect = make_text(playerText, BLACK, SILVER, left, top, size=8 * (self.scale - 1)) self.displaySurface.blit(textSurf, textRect) left, top = self.left_top_coords_of_box(11.75, 5) playerText = 'lv.{:2d}'.format(self.playerPokemon.level) textSurf, textRect = make_text(playerText, BLACK, SILVER, left, top, size=8 * (self.scale - 1)) self.displaySurface.blit(textSurf, textRect) self.draw_exp_bar()
def draw_menu(self): pygame.draw.rect(self.displaySurface, WHITE, (350, 575, 200, 90)) message = 'What will %s do?' % self.playerPokemon.name words = message.split(' ') pygame.draw.rect(self.displaySurface, WHITE, (40, 575, 297, 90)) surf, rect = make_text(' '.join(words[:2]), BLACK, WHITE, 40, 575, size=20) self.displaySurface.blit(surf, rect) surf, rect = make_text(' '.join(words[2:]), BLACK, WHITE, 40, 625, size=20) self.displaySurface.blit(surf, rect) fightSurf, fightRect = make_text('{:8s}'.format('Fight'), BLACK, WHITE, 350, 575, size=24) self.displaySurface.blit(fightSurf, fightRect) pokeSurf, pokeRect = make_text('{:8s}'.format('Pokémon'), BLACK, WHITE, 450, 575, size=24) self.displaySurface.blit(pokeSurf, pokeRect) bagSurf, bagRect = make_text('{:8s}'.format('Bag'), BLACK, WHITE, 350, 625, size=24) self.displaySurface.blit(bagSurf, bagRect) runSurf, runRect = make_text('{:8s}'.format('Run'), BLACK, WHITE, 450, 625, size=24) self.displaySurface.blit(runSurf, runRect) options = [fightRect, bagRect, pokeRect, runRect] return options
def draw_tile_params(mapSquare, area): left, top = left_top_coords_of_box(.5, 32.5, mapArea=True) if len(area) > 1 or len(area[-1]) > 1: pygame.draw.rect(DISPLAYSURF, BLACK, (left, top, BOXSIZE * 8, BOXSIZE * 5), 4) else: x, y = area[-1][-1] tilePassingParams = mapSquare[x][y].get_passing_params() keys = tilePassingParams.keys() pygame.draw.rect(DISPLAYSURF, WHITE, (left, top, BOXSIZE * 8, BOXSIZE * 5), 4) for i, key in enumerate(keys): left, top = left_top_coords_of_box(1, 33 + i, mapArea=True) text = '%s: %s' % (key, tilePassingParams[key]) surf, rect = make_text(text, WHITE, BLACK, left, top, size=FONTSIZE) DISPLAYSURF.blit(surf, rect)
def main(): global DISPLAYSURF, FPSCLOCK, FPS pygame.init() FPSCLOCK = pygame.time.Clock() FPS = 15 global XMARGIN, YMARGIN, BOXSIZE, FONTSIZE width, height = pygame.display.Info().current_w, pygame.display.Info( ).current_h windowHeight = int(0.8 * height) windowWidth = int(1.9 * windowHeight) XMARGIN = YMARGIN = int(windowHeight / 40) BOXSIZE = int((windowHeight - 2 * YMARGIN) / 36) FONTSIZE = int(0.8 * BOXSIZE) DISPLAYSURF = pygame.display.set_mode((windowWidth, windowHeight)) pygame.display.set_caption('Map Square Maker') global setParams setParams = {} setParams['isWalkable'] = True setParams['isRunnable'] = True setParams['isBikeable'] = True setParams['isSurfable'] = False draw_set_params() squareX = squareY = 0 yMin, yMax = 0, 31 xMin, xMax = 0, 31 mouseX = mouseY = 0 tileCoords = (36, 0) xStart, xEnd = squareX, squareX + 1 yStart, yEnd = squareY, squareY + 1 tileSets = [x[1] for x in os.walk('tiles')][0] tileSets.sort() tileSetNum = 0 tileSetFolder = tileSets[tileSetNum] left, top = left_top_coords_of_box(0, 17, mapArea=False) surf, prevRect = make_text('Prev', WHITE, BLACK, left, top, size=FONTSIZE) DISPLAYSURF.blit(surf, prevRect) left, top = left_top_coords_of_box(4, 17, mapArea=False) surf, nextRect = make_text('Next', WHITE, BLACK, left, top, size=FONTSIZE) DISPLAYSURF.blit(surf, nextRect) try: mapSquare = load_map_square(sys.argv[1]).tiles except: mapSquare = fill_map(tileSetFolder, tileCoords)[0] mapImages = load_map(mapSquare) draw_map(mapImages) area = [] global mapCoords mapCoords = [] for x in range(len(mapSquare)): column = [] for y in range(len(mapSquare)): column.append((x, y)) mapCoords.append(column) while True: DISPLAYSURF.fill(BLACK) tileSetFolder = tileSets[tileSetNum] left, top = left_top_coords_of_box(2, 17, mapArea=False) text = '%s/%i' % (str(tileSetNum + 1).zfill(2), len(tileSets)) surf, rect = make_text(text, WHITE, BLACK, left, top, size=FONTSIZE) DISPLAYSURF.blit(surf, rect) left, top = left_top_coords_of_box(0, 17, mapArea=False) surf, prevRect = make_text('Prev', WHITE, BLACK, left, top, size=FONTSIZE) DISPLAYSURF.blit(surf, prevRect) left, top = left_top_coords_of_box(4, 17, mapArea=False) surf, nextRect = make_text('Next', WHITE, BLACK, left, top, size=FONTSIZE) DISPLAYSURF.blit(surf, nextRect) left, top = left_top_coords_of_box(12, 34, mapArea=True) surf, saveRect = make_text('Save', WHITE, BLACK, left, top, size=FONTSIZE) DISPLAYSURF.blit(surf, saveRect) draw_map(mapImages) draw_tileSet(tileSetFolder) paramRects = draw_set_params() for event in pygame.event.get(): keys = pygame.key.get_pressed() if not keys[K_LSHIFT]: xStart, xEnd = squareX, squareX + 1 yStart, yEnd = squareY, squareY + 1 if event.type == QUIT or (event.type == KEYUP and event.key == K_ESCAPE): quit() elif event.type == KEYDOWN: if event.key in [K_UP, K_w]: if squareY != yMin: squareY -= 1 else: squareY = yMax if keys[K_LSHIFT]: yStart -= 1 elif event.key in [K_LEFT, K_a]: if squareX != xMin: squareX -= 1 else: squareX = xMax if keys[K_LSHIFT]: xStart -= 1 elif event.key in [K_RIGHT, K_d]: if squareX != xMax: squareX += 1 else: squareX = xMin if keys[K_LSHIFT]: xEnd += 1 elif event.key in [K_DOWN, K_s]: if squareY != yMax: squareY += 1 else: squareY = yMin if keys[K_LSHIFT]: yEnd += 1 elif event.key == K_SPACE: columns = mapCoords[xStart:xEnd] area = [y[yStart:yEnd] for y in columns] highlight_area(area) mapSquare, tileCoords = set_tiles(mapSquare, area, tileSetFolder, tileCoords) mapImages = load_map(mapSquare) elif event.key == K_b: columns = mapCoords[xStart:xEnd] area = [y[yStart:yEnd] for y in columns] highlight_area(area) mapSquare, tileCoords = set_decoration( mapSquare, area, tileSetFolder, tileCoords) mapImages = load_map(mapSquare) elif keys[K_LCTRL] and event.key == K_f: mapArea, tileCoords = fill_map(tileSetFolder, tileCoords) if mapArea != None: mapSquare = mapArea mapImages = load_map(mapSquare) elif keys[K_LCTRL] and event.key == K_e: columns = mapCoords[xStart:xEnd] area = [y[yStart:yEnd] for y in columns] highlight_area(area) edit_tile_params(mapSquare, area) elif keys[K_LCTRL] and event.key == K_r: mapSquare[squareX][squareY].rotate() mapImages[squareX][squareY] = mapSquare[squareX][ squareY].draw(BOXSIZE) elif keys[K_LCTRL] and event.key == K_h: mapSquare[squareX][squareY].flip_horizontal() mapImages[squareX][squareY] = mapSquare[squareX][ squareY].draw(BOXSIZE) elif keys[K_LCTRL] and event.key == K_v: mapSquare[squareX][squareY].flip_vertical() mapImages[squareX][squareY] = mapSquare[squareX][ squareY].draw(BOXSIZE) elif event.type == MOUSEBUTTONUP: mouseX, mouseY = event.pos tileCoords = (36, 0) if nextRect.collidepoint(mouseX, mouseY): tileSetNum += 1 if tileSetNum == len(tileSets): tileSetNum = 0 elif prevRect.collidepoint(mouseX, mouseY): tileSetNum -= 1 if tileSetNum < 0: tileSetNum = len(tileSets) - 1 elif saveRect.collidepoint(mouseX, mouseY): save(mapSquare) else: paramKeys = list(setParams.keys()) for i in range(len(setParams)): if paramRects[i].collidepoint(mouseX, mouseY): setParams[ paramKeys[i]] = not setParams[paramKeys[i]] else: continue columns = mapCoords[xStart:xEnd] area = [y[yStart:yEnd] for y in columns] draw_tile_params(mapSquare, area) highlight_area(area) FPSCLOCK.tick(FPS)
def choose_battler_from_party(self): self.displaySurface.fill(WHITE) pygame.draw.rect(self.displaySurface, BLACK, (25, 25, 550, 650), 5) pygame.draw.rect(self.displaySurface, BLACK, (25, 555, 550, 120), 5) pygame.display.update() pokeCoords = [(40, 250), (300, 50), (300, 145), (300, 240), (300, 335), (300, 430)] rects = [] # draw boxes for i in range(6): left, top = pokeCoords[i] rect = pygame.draw.rect(self.displaySurface, BLACK, (left, top, 250, 90), 4) rects.append(rect) for i, pokemon in enumerate(self.player.party): left, top = pokeCoords[i] # pokemon image image = load_pokemon_sprite(pokemon) image = pygame.transform.scale(image, (85, 85)) self.displaySurface.blit(image, (left + 4, top + 3)) # pokemon name, status surf, rect = make_text('{:12}'.format(pokemon.name), BLACK, WHITE, left + 115, top + 6, size=18) self.displaySurface.blit(surf, rect) surf, rect = make_text('lv. %i' % pokemon.level, BLACK, WHITE, left + 115, top + 24, size=16) self.displaySurface.blit(surf, rect) # pokemon hp hpPct, color = pokemon.hp_bar() pygame.draw.rect(self.displaySurface, BLACK, (left + 115, top + 45, 130, 20), 2) if pokemon.hp != 0: pygame.draw.rect(self.displaySurface, color, (left + 117, top + 47, 127 * hpPct, 17)) statusText = pokemon.status.displayText.center(5) surf, rect = make_text(statusText, BLACK, pokemon.status.displayColor, left + 190, top + 24, size=16) self.displaySurface.blit(surf, rect) if pokemon.fainted: statusText = 'FNT'.center(5) surf, rect = make_text(statusText, BLACK, GRAY, left + 190, top + 24, size=16) self.displaySurface.blit(surf, rect) pygame.display.update() selected = False while not selected: messages = [] for event in pygame.event.get(): if event.type == QUIT or (event.type == KEYUP and event.key == K_ESCAPE): pygame.quit() sys.exit() elif event.type == KEYUP: if event.key == K_q: return None elif event.type == MOUSEBUTTONDOWN: mousex, mousey = event.pos for i in range(len(self.player.party)): if rects[i].collidepoint(mousex, mousey): if i == 0: messages.append('%s is already in battle!' % self.player.party[0].name) break pokeNumber = i selected, messages = self.player.party[i].select() if messages: self.draw_messages(messages) pygame.draw.rect(self.displaySurface, WHITE, (40, 575, 250, 90)) pygame.display.update() return pokeNumber
def _blit_text(self, *args, **kwds): self.screen.blit(*make_text(*args, **kwds))
def draw_menu(self): left, top = self.left_top_coords_of_box(0.5, 7) messagePosition = (left, top, self.boxsize * 9, int(self.boxsize * 2.5)) pygame.draw.rect(self.displaySurface, WHITE, messagePosition) pygame.draw.rect(self.displaySurface, BLACK, messagePosition, self.linewidth) left, top = self.left_top_coords_of_box(9, 7) commandPosition = (left, top, int(self.boxsize * 5.5), int(self.boxsize * 2.5)) pygame.draw.rect(self.displaySurface, WHITE, commandPosition) pygame.draw.rect(self.displaySurface, BLACK, commandPosition, self.linewidth) message = 'What will %s do?' % self.playerPokemon.name words = message.split(' ') left, top = self.left_top_coords_of_box(1, 7.5) surf, rect = make_text(' '.join(words[:2]), BLACK, WHITE, left, top, size=self.textSize) self.displaySurface.blit(surf, rect) left, top = self.left_top_coords_of_box(1, 8.5) surf, rect = make_text(' '.join(words[2:]), BLACK, WHITE, left, top, size=self.textSize) self.displaySurface.blit(surf, rect) left, top = self.left_top_coords_of_box(9.5, 7.5) fightSurf, fightRect = make_text('{:5s}'.format('Fight'), BLACK, WHITE, left, top, size=self.textSize) self.displaySurface.blit(fightSurf, fightRect) left, top = self.left_top_coords_of_box(11.5, 7.5) pokeSurf, pokeRect = make_text('{:7s}'.format('Pokémon'), BLACK, WHITE, left, top, size=self.textSize) self.displaySurface.blit(pokeSurf, pokeRect) left, top = self.left_top_coords_of_box(9.5, 8.5) bagSurf, bagRect = make_text('{:5s}'.format('Bag'), BLACK, WHITE, left, top, size=self.textSize) self.displaySurface.blit(bagSurf, bagRect) left, top = self.left_top_coords_of_box(11.5, 8.5) runSurf, runRect = make_text('{:7s}'.format('Run'), BLACK, WHITE, left, top, size=self.textSize) self.displaySurface.blit(runSurf, runRect) options = [fightRect, bagRect, pokeRect, runRect] return options
def fight(self): left, top = self.left_top_coords_of_box(0.5, 7) messagePosition = (left, top, self.boxsize * 9.5, int(self.boxsize * 2.5)) pygame.draw.rect(self.displaySurface, WHITE, messagePosition) pygame.draw.rect(self.displaySurface, BLACK, messagePosition, self.linewidth) attacks = self.playerPokemon.attacks while len(attacks) < 4: attacks.append(NoAttack()) attackCoords = [ self.left_top_coords_of_box(1, 7.5), self.left_top_coords_of_box(5.5, 7.5), self.left_top_coords_of_box(1, 8.5), self.left_top_coords_of_box(5.5, 8.5) ] rects = [] for i in range(4): left, top = attackCoords[i] surf, atkRect = make_text('{:12}'.format(attacks[i].name), BLACK, WHITE, left, top, size=self.textSize) rects.append(atkRect) self.displaySurface.blit(surf, atkRect) pygame.display.update() selected = self.playerPokemon.keepUsingAttack if selected: attackNumber = self.playerPokemon.continueAttackNumber while not selected: messages = [] for event in pygame.event.get(): if event.type == QUIT or (event.type == KEYUP and event.key == K_ESCAPE): pygame.quit() sys.exit() elif event.type == KEYUP: if event.key == K_q: return None elif event.type == MOUSEMOTION: mousex, mousey = event.pos for i in range(4): if rects[i].collidepoint(mousex, mousey): self.draw_attack_stats(attacks[i]) break else: pygame.draw.rect(self.displaySurface, WHITE, (350, 575, 200, 90)) pygame.display.update() elif event.type == MOUSEBUTTONDOWN: mousex, mousey = event.pos for i in range(4): if rects[i].collidepoint(mousex, mousey): attackNumber = i selected, messages = self.playerPokemon.attacks[ i].select() if messages: self.draw_messages(messages) pygame.draw.rect(self.displaySurface, WHITE, (40, 575, 250, 90)) for i in range(4): left, top = attackCoords[i] surf, atkRect = make_text('{:10}'.format(attacks[i].name), BLACK, WHITE, left, top, size=20) rects.append(atkRect) self.displaySurface.blit(surf, atkRect) pygame.display.update() return attackNumber
def main(): global DISPLAYSURF, FPSCLOCK, FPS pygame.init() FPSCLOCK = pygame.time.Clock() FPS = 15 global XMARGIN, YMARGIN, BOXSIZE, FONTSIZE width, height = pygame.display.Info().current_w, pygame.display.Info( ).current_h windowHeight = int(0.8 * height) windowWidth = int(1.9 * windowHeight) XMARGIN = YMARGIN = int(windowHeight / 40) BOXSIZE = int((windowHeight - 2 * YMARGIN) / 36) FONTSIZE = int(0.8 * BOXSIZE) DISPLAYSURF = pygame.display.set_mode((windowWidth, windowHeight)) pygame.display.set_caption('Map Maker') squareX = squareY = 0 yMin, yMax = 0, 4 xMin, xMax = 0, 4 mouseX = mouseY = 0 tileCoords = (36, 0) mapSquares = [x[2] for x in os.walk('mapSquares')][0] mapSquares.sort() # left, top = left_top_coords_of_box(0, 17, mapArea=False) # surf, prevRect = make_text('Prev', WHITE, BLACK, left, top, size=FONTSIZE) # DISPLAYSURF.blit(surf, prevRect) # left, top = left_top_coords_of_box(4, 17, mapArea=False) # surf, nextRect = make_text('Next', WHITE, BLACK, left, top, size=FONTSIZE) # DISPLAYSURF.blit(surf, nextRect) mapImages = [] mapData = [] for file in mapSquares: filename = 'mapSquares' + sep + file if 'main_map' in file: pass elif 'png' in file: mapImages.append(load_image(filename)) elif 'pickle' in file: mapData.append(load_map_square(filename)) # print(mapData) draw_mapSquares(mapImages) pygame.display.update() area = [] global mapCoords mapCoords = [] mainMap = [] mainMapData = [] for x in range(5): column1 = [] column2 = [] column3 = [] for y in range(5): column1.append((x, y)) column2.append(None) column3.append(None) mapCoords.append(column1) mainMap.append(column2) mainMapData.append(column3) mainMapImages = mainMap while True: DISPLAYSURF.fill(BLACK) # left, top = left_top_coords_of_box(2, 17, mapArea=False) # text = '%s/%i' % (str(tileSetNum+1).zfill(2), len(tileSets)) # surf, rect = make_text(text, WHITE, BLACK, left, top, size=FONTSIZE) # DISPLAYSURF.blit(surf, rect) # left, top = left_top_coords_of_box(0, 17, mapArea=False) # surf, prevRect = make_text('Prev', WHITE, BLACK, left, top, size=FONTSIZE) # DISPLAYSURF.blit(surf, prevRect) # left, top = left_top_coords_of_box(4, 17, mapArea=False) # surf, nextRect = make_text('Next', WHITE, BLACK, left, top, size=FONTSIZE) # DISPLAYSURF.blit(surf, nextRect) left, top = left_top_coords_of_box(12, 34, mapArea=True) surf, saveRect = make_text('Save', WHITE, BLACK, left, top, size=FONTSIZE) DISPLAYSURF.blit(surf, saveRect) draw_map(mainMapImages) draw_mapSquares(mapImages) for event in pygame.event.get(): keys = pygame.key.get_pressed() if not keys[K_LSHIFT]: xStart, xEnd = squareX, squareX + 1 yStart, yEnd = squareY, squareY + 1 if event.type == QUIT or (event.type == KEYUP and event.key == K_ESCAPE): quit() elif event.type == KEYDOWN: if event.key in [K_UP, K_w]: if squareY != yMin: squareY -= 1 else: squareY = yMax if keys[K_LSHIFT]: yStart -= 1 elif event.key in [K_LEFT, K_a]: if squareX != xMin: squareX -= 1 else: squareX = xMax if keys[K_LSHIFT]: xStart -= 1 elif event.key in [K_RIGHT, K_d]: if squareX != xMax: squareX += 1 else: squareX = xMin if keys[K_LSHIFT]: xEnd += 1 elif event.key in [K_DOWN, K_s]: if squareY != yMax: squareY += 1 else: squareY = yMin if keys[K_LSHIFT]: yEnd += 1 elif event.key == K_SPACE: columns = mapCoords[xStart:xEnd] area = [y[yStart:yEnd] for y in columns] highlight_area(area) mainMapData, mainMapImages, tileCoords = set_tiles( mainMapData, mainMapImages, area, mapData, mapImages, tileCoords) elif event.type == MOUSEBUTTONUP: mouseX, mouseY = event.pos if saveRect.collidepoint(mouseX, mouseY): # print(mainMapData) # print('\n\n') # print(mainMapImages) save(mainMapData) else: pass else: continue columns = mapCoords[xStart:xEnd] area = [y[yStart:yEnd] for y in columns] highlight_area(area) FPSCLOCK.tick(FPS)