def dialogueLoop(textList, path): q = 1 # this might actually be useless font = pygame.font.SysFont('Courier New', 30) #initializes pygame.font #font = pygame.font.Font(None, 30) dialogueBox = pygame.image.load(os.path.join('conf','TextBox.png')) #loads the image that holds the text #print "hero: ",Hero.rect.bottom #print "path: ",path windowRect = window.get_rect() x = (windowRect.right - 800)/2 yTest = windowRect.bottom - 300 if Hero.rect.bottom >= yTest - 10: # if the sprite is too close to where the text box would noramlly be, the box is moved to the top y = windowRect.top #print "True" else: y = yTest level = Level(path, windowRect) level.read_map() #redoes the level Textbackground = level.render() #Textbackground = pygame.Surface(windowRect.bottomright) b = 0 textList_broken = [] #empty set to use for the broken up text if len(textList) > 3: while len(textList) != 0: #while there are still things in textList a = 0 tripletset = [] #empty set to hold sets of triple lines while a < 3 and len(textList) != 0: #print "a: ",a #print textList tripletset.append(textList[0]) #adds first line from textList to tripleset textList.pop(0) #removes the line that was just added #print "length :",len(textList) a += 1 if len(textList) !=0: tripletset.append(u'\u25bc') #if it's not the last line, adds a ▼ to the set to show text continues textList_broken.append(tripletset) #adds tripleset to textList_broken # a = 0 #print "broken: ",textList_broken #print "lenght", len(textList) textList = textList_broken #print "list: ",textList # while q <= 200: #rectCoord = Hero.get_rect() #print y #Textbackground.blit(background, (0,0)) for m in range(len(textList)): """This loop here is what puts the text onto the screen. The data structure is set up so that the first is a list of 3 line text blocks (pages) then it is a list of those lines. """ Textbackground.blit(dialogueBox, (x,y)) #blits the dialogue image onto the level background q = 0 while q == 0: for event in pygame.event.get(): for n in range(len(textList[m])): words = font.render(textList[m][n], 1, (0, 0, 0)) Textbackground.blit(words, (x+20, y+20+n*30)) char.update(obstacles) change_Background(Textbackground, (0,0), True, char) pygame.display.flip() if event.key == K_RETURN and event.type == KEYDOWN: #print "STUFF" q = 1
def main(currentWorld, path, windowRect, level, background, obstacles, teleports, position, Hero, char, attack, defense, Enemy, heroSprite, enemySprites): leftcount = 0 while True: fpsClock.tick(45) # max of 45fps for event in pygame.event.get(): #print event if event.type == QUIT: #check for quit signal and properly terminate. shutdown() return if event.type == KEYDOWN: # checks for actions #print event.key if event.key == K_ESCAPE: #escape key exits shutdown() return elif event.key == K_l: Save.saveGame(currentWorld, Hero.getRect().topleft, Hero.health, Enemy.getRect().topleft, Enemy.health, Enemy.world, Enemy.old_state, Enemy.state) elif (event.key == K_LEFT) or (event.key == K_RIGHT) or (event.key == K_DOWN) or (event.key == K_UP): # Checks for arrow keys and moves the character in that direction Hero.start(event.key, obstacles) #Enemy.start(event.key, obstacles) else: k, q = 1,1 #counters while k == 1: if q == 1: #this is a way to prevent a bug where everything was being done twice causing a crash reader = KeyReader(event.key, window, fpsClock.tick(45)) k, backg, track = reader.testKey(background) # from KeyReader.py inventory = InventoryMap(window) #initializes the inventory system if track == 'inventory': item = inventory.moveCursor(False,track) if item != False and item != None: Hero.changeSheet(os.path.join('SpriteDev','Sheets',item.rstrip())) #updates the sprite sheet to be of the character holding the weapon pygame.display.flip() #updates the screen heroSprite = pygame.sprite.RenderPlain(Hero) #renders the sprite break elif track == 'weapons': item = inventory.moveCursor(True,track) if item != False and item != None: Hero.changeSheet(os.path.join('SpriteDev','Sheets',item.rstrip())) #updates the sprite sheet to be of the character holding the weapon pygame.display.flip() #updates the screen heroSprite = pygame.sprite.RenderPlain(Hero) #renders the sprite #if item.rstrip() == "Sword.png": attack, defense = weaponData(item) break elif track == 'swing': kill = swing(Hero, attack, defense, Enemy) if kill == True: Enemy.kill(True) enemycollide = False break if backg != 1 and track == 'talk': #just a testing thing dialogueLoop(k, path) # see documentation there level = Level(path, windowRect) #re parses teh backround level.read_map() background = level.render() #resets the background #if Hero.old_state == None: # print "down" # print attack #elif Hero.state == 'still': #and Hero.state != None: # print Hero.old_state+" old" # print attack #else: # print Hero.state+" current" # print attack #print isinstance(k, int) if k == 42: #42 is the official quit signal for k q = 0 elif isinstance(k, int) != True: # checks to see if k value is a code or string #print "break" break elif event.key == K_ESCAPE: shutdown() #makes sure that pressing escape quits the program return else: q +=1 #iterates the main loop if nothing happens if backg != 1: change_Background(backg, (0,0), True) if track == 'quit': break pygame.display.flip() elif event.type == KEYUP: #stops movement when arrow key is released #print Hero.state,"hero" Hero.stopSimple() #Enemy.stopSimple() #print Hero.state,"hero" herocollide = True if Enemy.alive() == True: herocollide = Enemy.check_collision(Enemy.getRect(),[Hero.getRect()]) enemyCollide = Hero.check_collision(Hero.getRect(),[Enemy.getRect()]) else: enemyCollide = False if herocollide != True: Enemy.AI(Hero.getRect().center, obstacles) #Enemy2.AI(Hero.getRect().center, obstacles) elif Enemy.alive(): Enemy.stop(20) damage = .25-float(defense) if damage < 0: damage = 0 Hero.health -= damage #print "hero: %s" % Hero.health #print Hero.rect.size if leftcount == 140: leftcount = 0 #if leftcount%10 == 0: #print Enemy.rect.center char.update(obstacles) #checks for collisions between sprites if enemyCollide != False and Enemy.alive() == True: #print "Here" Hero.stop(5) path_2 = Hero.check_teleport(currentWorld, teleports) #checks to see if the character has moved to a different world if (path_2 != path) and (path_2 != None): #if path_2 is different than the already existent one, and exists path = path_2 #sets path to path_2 #print "main path:", path level = Level(os.path.join('conf',path), windowRect) level.read_map() #redoes the level render currentWorld = Hero.getWorld() #sets the current word to wherever the hero is so that background can be properly rendered #print currentWorld background = level.render() #makes the background char = pygame.sprite.RenderPlain(Hero) teleports = [] # clears the sets obstacles = [] obstacles, teleports = getTiles() # resets the tiles if Hero.health <= 0: shutdown() #Test = Hero.check_collision(Hero.getRect(),[Enemy.getRect()]) #print Test change_Background(background, (0,0), True, char) updateHearts(Hero.health) # window.blit(background, (0,0)) # char.draw(window) # pygame.display.flip() save = [currentWorld, Hero.getRect().topleft, Hero.health, Enemy.getRect().topleft, Enemy.health]
pygame.display.flip() for event in pygame.event.get(): if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE): #check for quit signal and properly terminate. shutdown() exit() elif event.type == MOUSEBUTTONDOWN: if event.button == 1: if ButtonRect1.collidepoint(event.pos) == True: attack = 1 defense = 0 currentWorld = 'Home' path = os.path.join('conf','levelmap') itemPath = 'ItemData' windowRect = window.get_rect() level = Level(path, windowRect) level.read_map() background = level.render() window.blit(background, (0,0)) obstacles, teleports = getTiles() pygame.display.flip() position = getCharacter() Hero = Sprite.Sprite(position, obstacles, os.path.join('SpriteDev','Sheets','spritesheet1.png'),(os.path.join('SpriteDev','UpStill.png'),os.path.join('SpriteDev','RightStill.png'),os.path.join('SpriteDev','DownStill.png'),os.path.join('SpriteDev','LeftStill.png')), True) Enemy = Enemies.Enemy((400,500), obstacles, os.path.join('SpriteDev','Sheets','enemysheet.png'),(os.path.join('SpriteDev','EnemyUpStill.png'),os.path.join('SpriteDev','EnemyRightStill.png'),os.path.join('SpriteDev','EnemyDownStill.png'),os.path.join('SpriteDev','EnemyLeftStill.png')), currentWorld, True) char = pygame.sprite.RenderPlain(Hero, Enemy) heroSprite = pygame.sprite.RenderPlain(Hero) enemySprites = pygame.sprite.RenderPlain(Enemy) h = 0 main(currentWorld, path, windowRect, level, background, obstacles, teleports, position, Hero, char, attack, defense, Enemy, heroSprite, enemySprites) if ButtonRect2.collidepoint(event.pos) == True: save = [] save = Save.loadGame(window)