I've made significant progress porting my game from print-output to Pygame over the last few days, and I think I'm almost there!
Unfortunately, I'm beginning to suspect one of the methods I'm using to display my output is deeply flawed when it comes to what I eventually want it to do.
My goal is to create a "Game log" that displays the output from the most recent actions the player has taken.
For example, if the player entered a cabin, searched the cabin, then picked up the key they found there, I would like the gamelog to display
You enter the cabin
You find a Rusty Key
You take the Rusty Key
Currently, any time the gamelog updates, it replaces the previous output. This poses several issues:
1.) In a game of this style, a player can easily forget what the last few things they've done are. Not being able to see recent actions can be tedious and annoying to the player.
2.) The method I use to allow players to check their inventory works through a for-loop. With the way the gamelog works right now, only the most recently picked up item will display.
3.) In some situations, the info I need to display in this output is contained in a set. This system for displaying output can not take sets as an argument.
The code below is what I'm using to generate the output. This comes from this set of functions called "Pygame_Functions"
which has been quite helpful.
I'm beginning to think that this may not be the best way to achieve what I'm trying to do. It seems like this is only really effective for rendering a singular message.
class newLabel(pygame.sprite.Sprite): def __init__(self, text, fontSize, font, fontColour, xpos, ypos, background): pygame.sprite.Sprite.__init__(self) self.text = text self.fontColour = parseColour(fontColour) self.fontFace = pygame.font.match_font(font) self.fontSize = fontSize self.background = background self.font = pygame.font.Font(self.fontFace, self.fontSize) self.renderText() self.rect.topleft = [xpos, ypos] def update(self, newText, fontColour, background): self.text = newText if fontColour: self.fontColour = parseColour(fontColour) if background: self.background = parseColour(background) oldTopLeft = self.rect.topleft self.renderText() self.rect.topleft = oldTopLeft updateDisplay() def renderText(self): lineSurfaces =  textLines = self.text.split("<br>") maxWidth = 0 maxHeight = 0 for line in textLines: lineSurfaces.append(self.font.render(line, True, self.fontColour)) thisRect = lineSurfaces[-1].get_rect() if thisRect.width > maxWidth: maxWidth = thisRect.width if thisRect.height > maxHeight: maxHeight = thisRect.height self.image = pygame.Surface((maxWidth, (self.fontSize+1)*len(textLines)+5), pygame.SRCALPHA, 32) self.image.convert_alpha() if self.background != "clear": self.image.fill(parseColour(self.background)) linePos = 0 for lineSurface in lineSurfaces: self.image.blit(lineSurface,[0,linePos]) linePos+=self.fontSize+1 self.rect = self.image.get_rect()
And this bit here is the function I'm using to update the output after each player action.
def changeLabel(textObject, newText, fontColour=None, background=None): textObject.update(newText, fontColour, background)
My general concept for how to get my gamelog made is that each of these output statements needs to be inserted into the first spot of a list.
Then, display the whole list, and pop off items from the list once they reach a set limit.
If anything on this needs to be clarified, or if other parts of my code are required to understand what my issue is, I'll update this post with whatever is requested.