-
Notifications
You must be signed in to change notification settings - Fork 6
/
text.py
109 lines (100 loc) · 7.57 KB
/
text.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import pygame
import math
import random
import util
import sprite
import alien
# character designs from https://github.com/rickwight/meteors, thank you rick
# oh god why
char_points = {
'0': [[-0.5, 0.25], [-0.25, 0.5], [-0.25, 0.5], [0.25, 0.5], [0.25, 0.5], [0.5, 0.25], [0.5, 0.25], [0.5, -0.25], [0.5, -0.25], [0.25, -0.5], [0.25, -0.5], [-0.25, -0.5], [-0.25, -0.5], [-0.5, -0.25], [-0.5, -0.25], [-0.5, 0.25], [-0.25, 0.5], [0.25, -0.5]],
'1': [[0.5, 0.25], [-0.0, 0.5], [-0.0, 0.5], [-0.0, -0.5], [0.5, -0.5], [-0.5, -0.5]],
'2': [[-0.5, -0.5], [0.5, -0.5], [0.5, -0.5], [-0.25, 0.0], [-0.25, 0.0], [-0.5, 0.25], [-0.5, 0.25], [-0.25, 0.5], [-0.25, 0.5], [0.25, 0.5], [0.25, 0.5], [0.5, 0.25]],
'3': [[0.5, 0.25], [0.25, 0.5], [0.25, 0.5], [-0.25, 0.5], [-0.25, 0.5], [-0.5, 0.25], [-0.5, 0.25], [-0.25, 0.0], [-0.25, 0.0], [-0.5, -0.25], [-0.5, -0.25], [-0.25, -0.5], [-0.25, -0.5], [0.25, -0.5], [0.25, -0.5], [0.5, -0.25], [0.25, 0.0], [-0.25, 0.0]],
'4': [[-0.25, -0.5], [-0.25, 0.5], [-0.25, 0.5], [0.5, -0.25], [0.5, -0.25], [-0.5, -0.25]],
'5': [[-0.5, 0.5], [0.5, 0.5], [0.5, 0.5], [0.5, 0.0], [0.5, 0.0], [-0.25, 0.0], [-0.25, 0.0], [-0.5, -0.25], [-0.5, -0.25], [-0.25, -0.5], [-0.25, -0.5], [0.5, -0.5]],
'6': [[-0.5, 0.25], [-0.25, 0.5], [-0.25, 0.5], [0.25, 0.5], [0.25, 0.5], [0.5, 0.25], [0.5, 0.25], [0.5, -0.25], [0.5, -0.25], [0.25, -0.5], [0.25, -0.5], [-0.25, -0.5], [-0.25, -0.5], [-0.5, -0.25], [-0.5, -0.25], [-0.25, 0.0], [-0.25, 0.0], [0.5, 0.0]],
'7': [[0.5, 0.5], [-0.5, 0.5], [-0.5, 0.5], [0.25, -0.5]],
'8': [[0.5, 0.25], [0.25, 0.5], [0.25, 0.5], [-0.25, 0.5], [-0.25, 0.5], [-0.5, 0.25], [-0.5, 0.25], [-0.25, 0.0], [-0.25, 0.0], [-0.5, -0.25], [-0.5, -0.25], [-0.25, -0.5], [-0.25, -0.5], [0.25, -0.5], [0.25, -0.5], [0.5, -0.25], [0.5, -0.25], [0.25, 0.0], [0.25, 0.0], [0.5, 0.25], [0.25, 0.0], [-0.25, 0.0]],
'9': [[0.5, -0.25], [0.25, -0.5], [0.25, -0.5], [-0.25, -0.5], [-0.25, -0.5], [-0.5, -0.25], [-0.5, -0.25], [-0.5, 0.25], [-0.5, 0.25], [-0.25, 0.5], [-0.25, 0.5], [0.25, 0.5], [0.25, 0.5], [0.5, 0.25], [0.5, 0.25], [0.25, 0.0], [0.25, 0.0], [-0.5, 0.0]],
'A': [[0.5, -0.5], [-0.0, 0.5], [-0.0, 0.5], [-0.5, -0.5], [0.25, 0.0], [-0.25, 0.0]],
'B': [[0.5, -0.5], [0.5, 0.5], [0.5, 0.5], [-0.25, 0.5], [-0.25, 0.5], [-0.5, 0.25], [-0.5, 0.25], [-0.25, 0.0], [-0.25, 0.0], [-0.5, -0.25], [-0.5, -0.25], [-0.25, -0.5], [-0.25, -0.5], [0.5, -0.5], [0.5, 0.0], [-0.25, 0.0]],
'C': [[-0.5, -0.25], [-0.25, -0.5], [-0.25, -0.5], [0.25, -0.5], [0.25, -0.5], [0.5, -0.25], [0.5, -0.25], [0.5, 0.25], [0.5, 0.25], [0.25, 0.5], [0.25, 0.5], [-0.25, 0.5], [-0.25, 0.5], [-0.5, 0.25]],
'D': [[0.5, -0.5], [0.5, 0.5], [0.5, 0.5], [-0.25, 0.5], [-0.25, 0.5], [-0.5, 0.25], [-0.5, 0.25], [-0.5, -0.25], [-0.5, -0.25], [-0.25, -0.5], [-0.25, -0.5], [0.5, -0.5]],
'E': [[0.5, 0.5], [-0.5, 0.5], [0.5, 0.0], [-0.25, 0.0], [0.5, -0.5], [-0.5, -0.5], [0.5, -0.5], [0.5, 0.5]],
'F': [[0.5, -0.5], [0.5, 0.5], [0.5, 0.5], [-0.5, 0.5], [0.5, 0.0], [-0.25, 0.0]],
'G': [[-0.5, 0.25], [-0.25, 0.5], [-0.25, 0.5], [0.25, 0.5], [0.25, 0.5], [0.5, 0.25], [0.5, 0.25], [0.5, -0.25], [0.5, -0.25], [0.25, -0.5], [0.25, -0.5], [-0.25, -0.5], [-0.25, -0.5], [-0.5, -0.25], [-0.5, -0.25], [-0.5, 0.0], [-0.5, 0.0], [-0.0, 0.0]],
'H': [[0.5, -0.5], [0.5, 0.5], [-0.5, -0.5], [-0.5, 0.5], [0.5, 0.0], [-0.5, 0.0]],
'I': [[0.25, 0.5], [-0.25, 0.5], [0.25, -0.5], [-0.25, -0.5], [-0.0, -0.5], [-0.0, 0.5]],
'J': [[0.5, -0.5], [-0.0, -0.5], [-0.0, -0.5], [-0.0, 0.5], [0.5, 0.5], [-0.5, 0.5]],
'K': [[0.5, -0.5], [0.5, 0.5], [0.5, 0.0], [-0.5, 0.5], [0.5, 0.0], [-0.5, -0.5]],
'L': [[0.5, -0.5], [0.5, 0.5], [0.5, -0.5], [-0.5, -0.5]],
'M': [[0.5, -0.5], [0.5, 0.5], [0.5, 0.5], [-0.0, 0.0], [-0.0, 0.0], [-0.5, 0.5], [-0.5, 0.5], [-0.5, -0.5]],
'N': [[0.5, -0.5], [0.5, 0.5], [0.5, 0.5], [-0.5, -0.5], [-0.5, -0.5], [-0.5, 0.5]],
'O': [[-0.5, 0.25], [-0.25, 0.5], [-0.25, 0.5], [0.25, 0.5], [0.25, 0.5], [0.5, 0.25], [0.5, 0.25], [0.5, -0.25], [0.5, -0.25], [0.25, -0.5], [0.25, -0.5], [-0.25, -0.5], [-0.25, -0.5], [-0.5, -0.25], [-0.5, -0.25], [-0.5, 0.25]],
'P': [[0.5, -0.5], [0.5, 0.5], [0.5, 0.5], [-0.25, 0.5], [-0.25, 0.5], [-0.5, 0.25], [-0.5, 0.25], [-0.25, 0.0], [-0.25, 0.0], [0.5, 0.0]],
'Q': [[-0.5, 0.25], [-0.25, 0.5], [-0.25, 0.5], [0.25, 0.5], [0.25, 0.5], [0.5, 0.25], [0.5, 0.25], [0.5, -0.25], [0.5, -0.25], [0.25, -0.5], [0.25, -0.5], [-0.25, -0.5], [-0.25, -0.5], [-0.5, -0.25], [-0.5, -0.25], [-0.5, 0.25], [-0.25, -0.25], [-0.5, -0.5]],
'R': [[0.5, -0.5], [0.5, 0.5], [0.5, 0.5], [-0.25, 0.5], [-0.25, 0.5], [-0.5, 0.25], [-0.5, 0.25], [-0.25, 0.0], [-0.25, 0.0], [0.5, 0.0], [-0.25, 0.0], [-0.5, -0.5]],
'S': [[0.5, -0.25], [0.25, -0.5], [0.25, -0.5], [-0.25, -0.5], [-0.25, -0.5], [-0.5, -0.25], [-0.5, -0.25], [-0.25, 0.0], [-0.25, 0.0], [0.25, 0.0], [0.25, 0.0], [0.5, 0.25], [0.5, 0.25], [0.25, 0.5], [0.25, 0.5], [-0.25, 0.5], [-0.25, 0.5], [-0.5, 0.25]],
'T': [[0.5, 0.5], [-0.5, 0.5], [-0.0, 0.5], [-0.0, -0.5]],
'U': [[0.5, 0.5], [0.5, -0.25], [0.5, -0.25], [0.25, -0.5], [0.25, -0.5], [-0.25, -0.5], [-0.25, -0.5], [-0.5, -0.25], [-0.5, -0.25], [-0.5, 0.5]],
'V': [[0.5, 0.5], [-0.0, -0.5], [-0.0, -0.5], [-0.5, 0.5]],
'W': [[0.5, 0.5], [0.5, -0.5], [0.5, -0.5], [-0.0, 0.0], [-0.0, 0.0], [-0.5, -0.5], [-0.5, -0.5], [-0.5, 0.5]],
'X': [[0.5, -0.5], [-0.5, 0.5], [-0.5, -0.5], [0.5, 0.5]],
'Y': [[0.5, 0.5], [-0.0, 0.0], [-0.0, 0.0], [-0.5, 0.5], [-0.0, 0.0], [-0.0, -0.5]],
'Z': [[0.5, 0.5], [-0.5, 0.5], [-0.5, 0.5], [0.5, -0.5], [0.3, -0.5], [-0.5, -0.5]],
'-': [[0.3, 0.0], [-0.3, 0.0]],
'm': [[0.5, -0.8], [0.1, -0.4], [0.1, -0.4], [0.5, -0.4],
[0.5, -0.8], [0.5, 0.4], [0.5, 0.4], [-0.5, 0.6],
[0.5, 0.3], [-0.5, 0.5], [-0.5, 0.6], [-0.5, -0.6],
[-0.5, -0.6], [-0.9, -0.2], [-0.9, -0.2], [-0.5, -0.2]]
}
class Character(sprite.Sprite):
# drawable text object
def __init__(self, world, character, position, scale = 20):
super(Character, self).__init__(world)
self.scale = scale
self.angle = 180
self.position = position
self.character = character
self.points = char_points[character]
self.angular_velocity = 0
self.continuous = False
def impact(self, other):
self.angular_velocity = random.random() * 2 - 1
super(Character, self).impact(other)
def update(self):
if abs(self.angular_velocity) > 0.01:
self.angle += self.angular_velocity
super(Character, self).update()
@classmethod
def string(cls, world, string, position, scale = 20):
kern = 2.5
x = position[0] - len(string) * scale * kern / 2.0
y = position[1]
for ch in string:
if ch in char_points:
pos = [x, y]
Character(world, ch, pos, scale)
x += scale * kern
def draw_string(surface, string, colour, scale, position,
centre = False, angle = 0):
kern = 2.5
x = position[0]
y = position[1]
a = scale * util.cos(angle)
b = scale * -util.sin(angle)
c = -b
d = a
if centre:
x -= a * kern * len(string) / 2.0
y -= c * kern * len(string) / 2.0
for ch in string:
if ch in char_points:
screen = [[int(-a * u - b * v + x),
int(-c * u - d * v + y)]
for u, v in char_points[ch]]
for i in range(0, len(screen), 2):
pygame.draw.line(surface, util.WHITE, screen[i], screen[i + 1])
x += a * kern
y += c * kern