diff --git a/auxiliar.py b/auxiliar.py new file mode 100644 index 0000000..35911bd --- /dev/null +++ b/auxiliar.py @@ -0,0 +1,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 \ No newline at end of file diff --git a/imegenes/soldier/run and point.png b/imegenes/soldier/run and point.png new file mode 100644 index 0000000..c339a2f Binary files /dev/null and b/imegenes/soldier/run and point.png differ diff --git a/soldier_rifle.py b/soldier_rifle.py new file mode 100644 index 0000000..ca8d784 --- /dev/null +++ b/soldier_rifle.py @@ -0,0 +1,59 @@ +from auxiliar import Auxiliar +import pygame + +class Soldier_rifle: + + def __init__(self,x,y): + + # Animaciones + self.run = Auxiliar.getSurfaceFromSpriteSheet("imegenes/soldier/run and point.png",8,1,False,1,1)[:6] + self.atack = Auxiliar.getSurfaceFromSpriteSheet("imegenes/soldier/run and point.png",8,1,False,1,1)[6:8] + self.frame = 0 + self.animation = self.run + self.image = self.animation[self.frame] + # Movimientos y rectangulos + self.rect = self.image.get_rect() + self.rect.x = x + self.rect.y = y + self.rect_radar = pygame.Rect(self.rect.x,self.rect.y,100,10) + #funciones + self.live=True + self.life=100 + self.tiempo_transcurrido = 0 + self.frame_rate_ms = 300 + + def move_x(self): + self.rect.x += 5 + + def move_y(self): + self.rect.y += 0 + + def actions(self,delta_ms,lista_eventos,enemigo): + + if self.rect_radar.colliderect(enemigo): + self.animation=self.atack + + else: + + self.animation=self.run + self.move_x() + + + def update(self,delta_ms,lista_eventos,enemigo): + self.tiempo_transcurrido = 0 + + if self.live: + self.actions(delta_ms,lista_eventos,enemigo) + self.tiempo_transcurrido += delta_ms + + if self.tiempo_transcurrido > self.frame_rate_ms: + if(self.frame < len(self.animation) - 1): + self.frame += 1 + else: + self.frame = 0 + + def draw(self,screen): + + if self.live: + self.image = self.animation[self.frame] + screen.blit(self.image,self.rect) \ No newline at end of file