def createExit(self, j, i): self.stageScale = 50 x = self.stageScale * (j) y = self.stageScale * (i) sprite = Platform() sprite.rect = pygame.Rect((x, y), (self.stageScale, self.stageScale)) sprite.image = self.imageDictionary["exit"] sprite.image = pygame.transform.scale(sprite.image, (self.stageScale, self.stageScale)) self.exitGroup.add(sprite);
def createLimitWall(self, j, i): self.stageScale = 50 x = self.stageScale * (j) y = self.stageScale * (i) sprite = Platform() sprite.rect = pygame.Rect((x, y), (self.stageScale, self.stageScale)) # Define rectangulos que serviran para delimitar etapa y limitar movimiento de la camara if i == 0 and j == 0: self.firstRect = pygame.Rect((x, y), (self.stageScale, self.stageScale)) elif i == (self.height - 1) and j == (self.width - 1): self.lastRect = pygame.Rect((x, y), (self.stageScale, self.stageScale)) self.zGroup.add(sprite)
def CheckCollision(self, player, group, x1, y1): newPos = pygame.Rect(x1, y1, player.sprite.rect.width, player.sprite.rect.height) playerMoved = pygame.sprite.Sprite() playerMoved.rect = newPos spriteListaux = pygame.sprite.spritecollide(playerMoved, group, False) self.spriteList = spriteListaux if len(spriteListaux) >= 1: for sprite in spriteListaux: if sprite.color == player.color or sprite.color == "Todos" or sprite.activada : rect = sprite.rect self.topY = rect.top self.bottomY = rect.top + rect.height self.rightX = rect.left + rect.width self.leftX = rect.left if sprite.color == player.color: sprite.activada = True player.colisionada = sprite return True elif sprite.activada == False and sprite.tipo == "Color": companeroPos = pygame.Rect(player.companero.X, player.companero.Y+1, player.companero.sprite.rect.width, player.companero.sprite.rect.height) companeroMoved = Platform() companeroMoved.color = player.companero.color companeroMoved.rect = companeroPos if companeroMoved.color == sprite.color and pygame.sprite.collide_rect(sprite,companeroMoved): rect = sprite.rect self.topY = rect.top self.bottomY = rect.top + rect.height self.rightX = rect.left + rect.width self.leftX = rect.left sprite.activada = True player.colisionada = sprite return True else: sprite.activada = False companeroPos = pygame.Rect(player.companero.X+1, player.companero.Y, player.companero.sprite.rect.width, player.companero.sprite.rect.height) companeroMoved = Platform() companeroMoved.color = player.companero.color companeroMoved.rect = companeroPos if companeroMoved.color == sprite.color and pygame.sprite.collide_rect(sprite,companeroMoved): rect = sprite.rect self.topY = rect.top self.bottomY = rect.top + rect.height self.rightX = rect.left + rect.width self.leftX = rect.left sprite.activada = True player.colisionada = sprite return True else: sprite.activada = False companeroPos = pygame.Rect(player.companero.X-1, player.companero.Y+1, player.companero.sprite.rect.width, player.companero.sprite.rect.height) companeroMoved = Platform() companeroMoved.color = player.companero.color companeroMoved.rect = companeroPos if companeroMoved.color == sprite.color and pygame.sprite.collide_rect(sprite,companeroMoved): rect = sprite.rect self.topY = rect.top self.bottomY = rect.top + rect.height self.rightX = rect.left + rect.width self.leftX = rect.left sprite.activada = True player.colisionada = sprite return True else: sprite.activada = False sprite.activada = False return False else: return False
def createSprite(self,lines, j, i, character): self.stageScale = 50 # Para que player aparezca en esquina superior izquierda x = self.stageScale * (j) y = self.stageScale * (i) sprite = Platform() sprite.i = i sprite.j = j if character == "a": sprite.image = self.imageDictionary["topCement"] sprite.imagen2 = self.imageDictionary["topCement"] elif character == "t": sprite.image = self.imageDictionary["lowEarth"] sprite.imagen2 = self.imageDictionary["lowEarth"] elif character == "n": sprite.image = self.imageDictionary["grass"] sprite.imagen2 = self.imageDictionary["grass"] elif character == "ñ": sprite.image = self.imageDictionary["topGrass"] sprite.imagen2 = self.imageDictionary["topGrass"] elif character == "s": sprite.image = self.imageDictionary["sand"] sprite.imagen2 = self.imageDictionary["sand"] elif character == "b":################## sprite.image = self.imageDictionary["blueAlpha"]################## sprite.imagen2 = self.imageDictionary["blue"]################## sprite.color = "Blue" ################## elif character == 'r':################## sprite.image = self.imageDictionary["lava"]################## sprite.imagen2 = self.imageDictionary["lava"]################## #sprite.color = "Green"################## elif character == "O": sprite.image = self.imageDictionary["blueAlpha"] sprite.imagen2 = self.imageDictionary["blue"] sprite.id = "Horizontal" sprite.color = "Blue" elif character == "P": sprite.image = self.imageDictionary["greenAlpha"] sprite.imagen2 = self.imageDictionary["green"] #sprite.delta_x = 5 #sprite.lim_x = 20 #sprite.delta_y = 5 #sprite.lim_y = 20 #sprite.delta_y = 5 #sprite.tipo_movimiento = "0" sprite.id = "Horizontal" sprite.color = "Green" elif character == "Q": sprite.image = self.imageDictionary["blueAlpha"] sprite.imagen2 = self.imageDictionary["blue"] sprite.id = "Vertical" sprite.color = "Blue" elif character == "F": sprite.image = self.imageDictionary["greenAlpha"] sprite.imagen2 = self.imageDictionary["green"] sprite.id = "Vertical" sprite.color = "Green" else: sprite.image = self.imageDictionary["grass"] sprite.imagen2 = self.imageDictionary["grass"] sprite.color = "Green" if character == "P" or character == "O": colorlargo = self.createPlatform(lines,j,i,"H") color = colorlargo[0] scale_x = colorlargo[1] scale_y = colorlargo[2] sprite.color = color #scale = 2 x = self.stageScale * (j) y = self.stageScale * (i) sprite.scale_x = scale_x sprite.scale_y = scale_y sprite.x_scale = self.stageScale *scale_x sprite.y_scale = self.stageScale*scale_y sprite.image = pygame.transform.scale(sprite.image, (int(scale_x*self.stageScale), int(scale_y*self.stageScale))) sprite.imagen2 = pygame.transform.scale(sprite.imagen2, (int(scale_x*self.stageScale), int(scale_y*self.stageScale))) sprite.rect = pygame.Rect((x, y), (scale_x*self.stageScale, scale_y*self.stageScale)) sprite.imagenoriginal = sprite.image elif character == "F" or character == "Q": sprite.x_scale = self.stageScale sprite.y_scale = self.stageScale sprite.image = pygame.transform.scale(sprite.image, (int(0.5*self.stageScale), 5*self.stageScale)) sprite.imagen2 = pygame.transform.scale(sprite.imagen2, (int(0.5*self.stageScale), 5*self.stageScale)) sprite.rect = pygame.Rect((x, y), (int(0.5*self.stageScale), 5*self.stageScale)) sprite.imagenoriginal = sprite.image else: sprite.x_scale = self.stageScale sprite.y_scale = self.stageScale sprite.image = pygame.transform.scale(sprite.image, (self.stageScale, self.stageScale)) sprite.imagen2 = pygame.transform.scale(sprite.imagen2, (self.stageScale, self.stageScale)) sprite.rect = pygame.Rect((x, y), (self.stageScale, self.stageScale)) sprite.imagenoriginal = sprite.image # Define rectangulos que serviran para delimitar etapa y limitar movimiento de la camara if i == 0 and j == 0: self.firstRect = pygame.Rect((x, y), (self.stageScale, self.stageScale)) elif i == (self.height - 1) and j == (self.width - 1): self.lastRect = pygame.Rect((x, y), (self.stageScale, self.stageScale)) sprite.colororiginal = sprite.color self.group.add(sprite)