Advertisement
jcmartinez

Untitled

May 30th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.32 KB | None | 0 0
  1. import pygame
  2. from pygame.locals import *
  3. from Razas import *
  4.  
  5. #---------------------Clase par cargar imagenes--------------------
  6. class CargarImagen(pygame.sprite.Sprite):
  7.     def __init__(self):
  8.         pygame.sprite.Sprite.__init__(self)
  9.  
  10.     def subirImagenes(self,filename, transparent=False):
  11.         try:
  12.             image = pygame.image.load(filename)
  13.         except pygame.error as e:
  14.             raise e
  15.         image = image.convert()
  16.         if transparent:
  17.             color = image.get_at((0,0))
  18.             image.set_colorkey(color,RLEACCEL)
  19.         return image
  20. #---------------------Interfaces---------------------------------
  21.  
  22. class Boton(pygame.sprite.Sprite):
  23.     def __init__(self,img1 ,img2 , x, y):
  24.         pygame.sprite.Sprite.__init__(self)
  25.         #Cargar imagen
  26.         cargarImagen = CargarImagen()
  27.  
  28.         img1 = cargarImagen.subirImagenes(img1, transparent = False)
  29.  
  30.         img2 = cargarImagen.subirImagenes(img2, transparent = False)
  31.  
  32.         self.imagen = img1
  33.  
  34.         self.imagenSeleccion = img2
  35.  
  36.         self.imagenActual = self.imagen
  37.  
  38.         self.rect = self.imagenActual.get_rect()
  39.  
  40.         self.rect.left, self.rect.top = x, y
  41.  
  42.     def update(self, pantalla, cursor):
  43.         if cursor.rect.colliderect(self.rect):
  44.             self.imagenActual = self.imagenSeleccion
  45.         else:
  46.             self.imagenActual = self.imagen
  47.  
  48.         pantalla.blit(self.imagenActual, self.rect)
  49.  
  50.     def transformarBoton(self,width,height,x,y):
  51.         self.imagen = pygame.transform.scale(self.imagen, (width, height))
  52.  
  53.         self.imagenSeleccion = pygame.transform.scale(self.imagenSeleccion, (width, height))
  54.  
  55.         self.imagenActual = self.imagen
  56.  
  57.         self.rect = self.imagenActual.get_rect()
  58.  
  59.         self.rect.left, self.rect.top = x, y
  60.  
  61.  
  62. class Mouse(pygame.sprite.Sprite):
  63.     def __init__(self):
  64.         pygame.sprite.Sprite.__init__(self)
  65.  
  66.         self.rect = Rect(50,50,15,15)
  67.  
  68.     def update(self):
  69.         pos = pygame.mouse.get_pos()
  70.  
  71.         (self.rect.left, self.rect.top) = (pos)
  72.  
  73.  
  74. class Texto(pygame.sprite.Sprite):
  75.  
  76.     def __init__(self, tamañof, dato, x, y, color):
  77.         pygame.sprite.Sprite.__init__(self)
  78.  
  79.         pygame.font.init()
  80.  
  81.         fuente = pygame.font.Font(None,tamañof)
  82.  
  83.         self.texto = fuente.render(dato, True, color)
  84.  
  85.         self.rect = self.texto.get_rect()
  86.  
  87.         self.rect.left, self.rect.top = x, y
  88.  
  89.     def update(self,pantalla):
  90.  
  91.         pantalla.blit(self.texto, self.rect)
  92.  
  93. class MostrarImagenes(pygame.sprite.Sprite):
  94.  
  95.     def __init__(self,recurso, x, y):
  96.         pygame.sprite.Sprite.__init__(self)
  97.  
  98.         cargarImagen = CargarImagen()
  99.  
  100.         self.transparencia = True
  101.  
  102.         data = cargarImagen.subirImagenes(recurso, transparent = self.transparencia)
  103.  
  104.         self.imagen = data
  105.  
  106.         self.rect = self.imagen.get_rect()
  107.  
  108.         self.rect.left, self.rect.top = x, y
  109.  
  110.     def update(self,pantalla):
  111.  
  112.         pantalla.blit(self.imagen, self.rect)
  113.  
  114.     def transformarImagen(self,ancho,alto):
  115.  
  116.         self.imagen = pygame.transform.scale(self.imagen,(ancho,alto))
  117.  
  118. class Rectangulo(pygame.Surface):
  119.     def __init__(self,tamaño, pos):
  120.         pygame.Surface.__init__(self, tamaño)
  121.         self.rect = Rect(pos,tamaño)
  122.         self.pos = pos
  123.         self.tamaño = tamaño
  124.  
  125.     def get_rect(self):
  126.         return self.rect
  127.  
  128.  
  129.  
  130.  
  131. #------------------Clase Jugador-------------------------------
  132.  
  133. class Player(pygame.sprite.Sprite):
  134.    
  135.    
  136.  
  137.     def __init__(self, nombre):
  138.         pygame.sprite.Sprite.__init__(self)
  139.  
  140.         #Nombre del jugador
  141.         self.nombre = nombre
  142.  
  143.         #Nivel del jugador
  144.         self.nivel = 1
  145.  
  146.         #lista de Habilidades
  147.         self.personajes = []
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement