def switchMap(self): mapList = myWorld.getMapList() mapWin = pygame.Surface((200 * ((len(mapList) / 10) + 1), 900)) mapWin.fill(colors.black) mapList.sort() mapB = [] numRows = 20 if pygame.font: font = pygame.font.SysFont("arial", 20) y_ = 0 x_ = 0 for map in mapList: b = button.Button((200 + (((x_ / numRows)) * 200), (y_ * 30)), map, os.getcwd() + "/FONTS/gothic.ttf", 14) mapB.append(b) mapWin.blit(b.img, (((x_ / numRows)) * 200, (y_ * 30))) y_ += 1 x_ += 1 y_ = y_ % numRows while True: for event in pygame.event.get(): if event.type == pygame.MOUSEBUTTONDOWN: (mX, mY) = pygame.mouse.get_pos() for b in mapB: (x, y) = pygame.mouse.get_pos() if b.hit(x, y): return myWorld.getMapByName(b.msg) if event.type == pygame.QUIT: os.sys.exit() screen.blit(mapWin, (200, 0)) pygame.display.flip()
def getAction(self, options, game): selection = 0 i = 0 self.buttons = [] for i in range(len(options)): #print ( int(ceil(25*const.scaleFactor)), i*int(ceil(25*const.scaleFactor)) ) (x, y) = self.locations[i] #print (x,y) msg = options[i] self.buttons.append( button.Button( ( x, y ), msg, os.getcwd()+"/FONTS/Squealer.ttf", 8) ) #print self.buttons while True: self.drawStoreScreen(game) for event in pygame.event.get(): if event.type == pygame.MOUSEBUTTONDOWN: (x, y) = pygame.mouse.get_pos() #x = x - 165 #y = y - 190 print x, y for b in self.buttons: if b.hit(int(ceil(x/const.scaleFactor)), int(ceil(y/const.scaleFactor)) ): print b.msg return b.msg event_ = self.inputHandler.getCmd(event) if event_ == pygame.K_t: game.screenShot() if event_ == pygame.QUIT: os.sys.exit() elif event_ == pygame.K_ESCAPE: os.sys.exit()
def __init__(self, screen, iH, menu): self.screen = screen self.battleField, r = load_image.load_image( os.path.join('ANIMATION', 'battlefield.bmp'), None) self.battleField.set_colorkey([255, 0, 0]) self.background = pygame.Surface((300, 300)) self.forestField, r = load_image.load_image( os.path.join('ANIMATION', 'forestField.bmp'), None) self.dungeonField, r = load_image.load_image( os.path.join('ANIMATION', 'dungeonField.bmp'), None) self.townField, r = load_image.load_image( os.path.join('ANIMATION', 'townField.bmp'), None) self.myMenu = menu self.enemyImgs = range(10) self.enemyImg = None self.heroImgs = range(10) self.heroImg = None self.heroImgIdx = 4 self.enemyImgIdx = 6 self.heroStepIdx = 0 self.enemyStepIdx = 0 self.inputHandler = iH self.buttons = [ button.Button((200, 150), 'Fight', os.getcwd() + "/FONTS/Squealer.ttf", 12), button.Button((200, 183), 'Magic', os.getcwd() + "/FONTS/Squealer.ttf", 12), button.Button((200, 216), 'Item', os.getcwd() + "/FONTS/Squealer.ttf", 12), button.Button((200, 249), 'Flee', os.getcwd() + "/FONTS/Squealer.ttf", 12) ]
# this is the static game world i.e. non-generated world # loaded once at startup and used thereafter myWorldBall = None selection = 0 options = ['Begin New Game', 'Load Saved Game', 'Credits', 'Exit'] buttons = [] if pygame.font: font = pygame.font.Font("./FONTS/chancery.ttf", 60) y = 350 for o in options: line = font.render(o, 1, colors.white, colors.black) buttons.append( button.Button(((screen.get_width() / 2) - (line.get_width() / 2), y), o)) y += 75 ifaceImg, r = load_image.load_image(os.path.join('MENU', 'interface_m.png'), None) logo, r = load_image.load_image('logo.png', None) def endScreen(game, msg): spi = os.getcwd() + "/FONTS/SpinalTfanboy.ttf" dev = os.getcwd() + "/FONTS/devinne.ttf" got = os.getcwd() + "/FONTS/gothic.ttf" dScreen = pygame.Surface((screen.get_width(), screen.get_width())) dScreen.fill(colors.black) msgText = text.Text(msg, os.getcwd() + "/FONTS/Squealer.ttf", 18, colors.white,