Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
STINKpython authored Jan 3, 2023
0 parents commit 76d52c6
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 0 deletions.
45 changes: 45 additions & 0 deletions auxiliar.py
Original file line number Diff line number Diff line change
@@ -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
Binary file added imegenes/soldier/run and point.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 59 additions & 0 deletions soldier_rifle.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 76d52c6

Please sign in to comment.