-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessages.py
28 lines (23 loc) · 912 Bytes
/
messages.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
#!/usr/bin/python2
# -*- coding: utf-8 -*-
import pygame
class Message(object):
def __init__(self, msg, xloc, yloc, msgstate="neutral"):
self.message = msg
self.x = xloc
self.y = yloc
self._lasth = 0
self.state = msgstate if msgstate in ("good", "bad", "neutral") else "neutral"
@property
def alive(self):
return (self.y + self._lasth) > 0
def tick(self, surface, delta, fontmap, colormap):
yoff = 0
for i, line in enumerate(self.message.split("\n")):
mtype = ("msgtitle", "msgtitle") if i == 0 else ("msgbody", "msg%s" % self.state)
(w, h) = fontmap[mtype[0]].size(line)
surface.blit(fontmap[mtype[0]].render(line, True, colormap[mtype[1]]),
(self.x - w // 2, int(self.y) + yoff))
yoff += h + 5
self._lasth = yoff
self.y -= delta / 20.0