-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame_messages.py
More file actions
27 lines (21 loc) · 784 Bytes
/
game_messages.py
File metadata and controls
27 lines (21 loc) · 784 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import tcod as libtcod
import textwrap
class Message:
def __init__(self, text, color = libtcod.white):
self.text = text
self.color = color
class MessageLog:
def __init__(self, x, width, height):
self.messages = []
self.x = x
self.width = width
self.height = height
def add_message(self, message):
# Split the message if necessary among multilines
new_msg_lines = textwrap.wrap(message.text, self.width)
for line in new_msg_lines:
# If the buffer is full, remove the first line to make room for the new one
if len(self.messages) == self.height:
del self.messages[0]
# Add new line
self.messages.append(Message(line, message.color))