예제 #1
0
 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["goldBrick"]
     sprite.image = pygame.transform.scale(sprite.image, (self.stageScale, self.stageScale))
                                            
     self.exitGroup.add(sprite);
예제 #2
0
    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 == "b":
            sprite.image = self.imageDictionary["water"]
            sprite.imagen2 = self.imageDictionary["watert"]
            sprite.color = "Blue"     
        elif character == "l":
            sprite.image = self.imageDictionary["lavat"]
            sprite.imagen2 = self.imageDictionary["lavat"]
        elif character == "s":
            sprite.image = self.imageDictionary["sand"]
            sprite.imagen2 = self.imageDictionary["sand"]
        elif character == "w":
            sprite.image = self.imageDictionary["watert"]
            sprite.imagen2 = self.imageDictionary["watert"]
        elif character == 'r':
            sprite.image = self.imageDictionary["lava"]
            sprite.imagen2 = self.imageDictionary["lava"]
            #sprite.color = "Green"
        elif character == "O":
             sprite.image = self.imageDictionary["water"]
             sprite.imagen2 = self.imageDictionary["watert"]
             sprite.color = "Blue" 
        elif character == "P":
            sprite.image = self.imageDictionary["lava"]
            sprite.imagen2 = self.imageDictionary["lavat"]
            sprite.color = "Green"
        elif character == "Q":
            sprite.image = self.imageDictionary["water"]
            sprite.imagen2 = self.imageDictionary["watert"]
            sprite.color = "Blue" 
        elif character == "F":
            sprite.image = self.imageDictionary["lava"]
            sprite.imagen2 = self.imageDictionary["lavat"]
            sprite.color = "Green"    

        else: 
            sprite.image = self.imageDictionary["lava"]
            sprite.imagen2 = self.imageDictionary["lavat"]
            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   
            if character == "F":
                sprite.color = "Green"
            elif character == "Q":
                sprite.color = "Blue"
        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); 
예제 #3
0
    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