Code: Alles auswählen
class char ():
def __init__ (self, filename):
# Charset vom C64er laden
self.charset = []
data = open (filename, 'rb')
line = data.read (512)
for byte in range (0, len (line)):
self.charset.append ((struct.unpack ('B', line [byte])[0]))
def makeChar (self, char):
# Bitmap bauen mit (ord) kann ein ASCII nach INT umgewandelt werden
charsurface = pygame.Surface ((8, 8), 16)
charsurface.fill ((0, 0 ,0 ))
lineindex = 0
# Zusammensetzen des Buchstaben
for charindex in range ((ord (char) -96) *8 +2, (ord (char) -96) *8 +8 +2):
if self.charset [charindex] & 128:
charsurface.set_at ((1, lineindex), (255))
if self.charset [charindex] & 64:
charsurface.set_at ((2, lineindex), 255)
if self.charset [charindex] & 32:
charsurface.set_at ((3, lineindex), 255)
if self.charset [charindex] & 16:
charsurface.set_at ((4, lineindex), 255)
if self.charset [charindex] & 8:
charsurface.set_at ((5, lineindex), 255)
if self.charset [charindex] & 4:
charsurface.set_at ((6, lineindex), 255)
if self.charset [charindex] & 2:
charsurface.set_at ((7, lineindex), 255)
if self.charset [charindex] & 1:
charsurface.set_at ((8, lineindex), 255)
lineindex = lineindex +1
return (charsurface)
Ich brauche nur einen kleinen Denkanstoß, wie ich es hinbekomme, nur ein mal den Zeichensatz laden zu müssen? Möchte ungern unnötigen Speicher verballern. Weiß da jemand ne Lösung? Sollte man es überhaupt mit einer Klasse machen?