forked from STINKpython/CASTEL-DEFENSE
-
Notifications
You must be signed in to change notification settings - Fork 1
/
auxiliar.py
45 lines (39 loc) · 2.12 KB
/
auxiliar.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
import pygame
class Auxiliar:
@staticmethod
def getSurfaceFromSpriteSheet(path,columnas,filas,flip=False, step = 1,scale=1):
lista = []
surface_imagen = pygame.image.load(path)
fotograma_ancho = int(surface_imagen.get_width()/columnas)
fotograma_alto = int(surface_imagen.get_height()/filas)
fotograma_ancho_scaled = int(fotograma_ancho*scale)
fotograma_alto_scaled = int(fotograma_alto*scale)
x = 0
for fila in range(filas):
for columna in range(0,columnas,step):
x = columna * fotograma_ancho
y = fila * fotograma_alto
surface_fotograma = surface_imagen.subsurface(x,y,fotograma_ancho,fotograma_alto)
if(scale != 1):
surface_fotograma = pygame.transform.scale(surface_fotograma,(fotograma_ancho_scaled, fotograma_alto_scaled)).convert_alpha()
if(flip):
surface_fotograma = pygame.transform.flip(surface_fotograma,True,False).convert_alpha()
lista.append(surface_fotograma)
return lista
@staticmethod
def getSurfaceFromSeparateFiles(path_format,quantity,flip=False,step = 1,scale=1,w=0,h=0,repeat_frame=1):
lista = []
for i in range(1,quantity+1):
path = path_format.format(i)
surface_fotograma = pygame.image.load(path)
fotograma_ancho_scaled = int(surface_fotograma.get_rect().w * scale)
fotograma_alto_scaled = int(surface_fotograma.get_rect().h * scale)
if(scale == 1 and w != 0 and h != 0):
surface_fotograma = pygame.transform.scale(surface_fotograma,(w, h)).convert_alpha()
if(scale != 1):
surface_fotograma = pygame.transform.scale(surface_fotograma,(fotograma_ancho_scaled, fotograma_alto_scaled)).convert_alpha()
if(flip):
surface_fotograma = pygame.transform.flip(surface_fotograma,True,False).convert_alpha()
for i in range(repeat_frame):
lista.append(surface_fotograma)
return lista