-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessenger.py
68 lines (61 loc) · 2.15 KB
/
messenger.py
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#
# Ceibal Chess - A chess activity for Sugar.
# Copyright (C) 2008, 2009 Alejandro Segovia <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
import pygame
#class DebugMessenger:
# def __init__(self):
# print "creating new debug messenger"
# self.messages = []
# self.y_spacing = 25
# self.surface_h = 200
#
# def render_messages(self, surface):
# self.surface_h = surface.get_height()
# y = 10
# for message in self.messages:
# font = pygame.font.Font(None, 25)
# text_color = font.render(message, 1, (90, 255, 90))
# surface.blit(text_color, (10, y))
# y += self.y_spacing
#
# def add_message(self, message):
# '''Add a message to this messenger. Always use this method to
# add messages, since the internal structure of this class may
# be changed in the future.'''
# self.messages.append(message)
# while len(self.messages)*self.y_spacing > self.surface_h/2:
# print "pop"
# self.messages.pop(0)
class Message():
def __init__(self, text, x = 0, y = 0, color = (0, 255, 0)):
self.x = x
self.y = y
self.text = text
self.color = color
class Messenger():
def __init__(self):
#print "creating new messenger"
self.messages = {}
self.font = None
def render_messages(self, surface):
if self.font is None:
self.font = pygame.font.Font(None, 25)
for key,message in self.messages.iteritems():
text_sface = self.font.render(message.text, 1, message.color)
surface.blit(text_sface, (message.x, message.y))
messenger = Messenger()