-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfundo.py
84 lines (71 loc) · 2.47 KB
/
fundo.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
# coding: utf-8
import random, pygame, os, xml.dom
import geral, object, tile
class Fundo:
def __init__(self):
self.coisasadesenhar = []
self.coisasacolidir = []
@staticmethod
def XML(node):
tipo = node.getAttribute('tipo')
tela = node.parentNode
x = int(tela.getAttribute('x'))
y = int(tela.getAttribute('y'))
fundo = Fundo()
if tipo == 'flores':
fundo.fundo = gerafundoflores((x, y))
elif tipo == 'ladrilhado':
imagem = node.getAttribute('imagem')
fundo.fundo = gerafundoladrilhado(imagem, (x, y))
elif tipo == '':
fundo.fundo = pygame.Surface(geral.size)
else:
raise Exception
for elemento in node.childNodes:
if elemento.nodeType != xml.dom.Node.ELEMENT_NODE:
continue
elif elemento.tagName == 'objeto':
o = object.Object.XML(elemento)
fundo.coisasadesenhar.append(o)
if o.colisao is not None:
fundo.coisasacolidir.append(o)
elif elemento.tagName == 'tile':
t = tile.Tile.XML(elemento)
fundo.coisasadesenhar.append(t)
else:
raise Exception
return fundo
def render(self, screen):
screen.blit(self.fundo, (0, 0))
for coisa in self.coisasadesenhar:
coisa.render(screen)
RandomFundo = random.Random()
def gerafundoflores(tela):
seed = 0x345678
for item in (hash(geral.seed), tela[0], tela[1]):
seed = (1000003 * seed) ^ item
seed = seed ^ 3
RandomFundo.seed(seed)
pasto = pygame.image.load(os.path.join('imagens', 'tiles', 'grama.png'))
flor = pygame.image.load(os.path.join('imagens', 'tiles', 'gramaflor.png'))
pasto = pygame.transform.scale(pasto, [int(geral.px * i) for i in pasto.get_rect()][2:]).convert_alpha()
pastorect = pasto.get_rect()
flor = pygame.transform.scale(flor, [int(geral.px * i) for i in flor.get_rect()][2:]).convert_alpha()
fundo = pygame.Surface(geral.size)
for i in range(0, geral.size[0], pastorect[2]):
for j in range(0, geral.size[1], pastorect[3]):
if RandomFundo.random() > 0.92:
fundo.blit(flor, (i, j))
else:
fundo.blit(pasto, (i, j))
return fundo
def gerafundoladrilhado(imagem, tela):
RandomFundo.seed((geral.seed, tela[0], tela[1]))
ladrilho = pygame.image.load(os.path.join('imagens', 'tiles', imagem + '.png'))
ladrilho = pygame.transform.scale(ladrilho, [int(geral.px * i) for i in ladrilho.get_rect()][2:]).convert_alpha()
ladrilhorect = ladrilho.get_rect()
fundo = pygame.Surface(geral.size)
for i in range(0, geral.size[0], ladrilhorect[2]):
for j in range(0, geral.size[1], ladrilhorect[3]):
fundo.blit(ladrilho, (i, j))
return fundo