Ejemplo n.º 1
0
class Main:

	class Ball:

		def __init__( self, par, radius, spd, color, t ):

			self.par = par
			self.orgspeed = spd[ 0 ]
			self.topspeed = spd[ 1 ]
			self.speed = self.orgspeed
			self.color = color
			self.r = radius
			self.angle = randint( 0, 359 )
			self.x, self.y = [ i / 2. for i in par.size ]

			self.treshold = 20
			self.hitcooldown = -1
			self.dead = False
			self.lasthit = None

			self.btype = t
			self.types = [  ]
			for t in self.btype:
				self.types.append( t( self ) )

		def update( self ):

			self.x += self.speed * cos( self.angle / ( 180. / pi ) )
			self.y += self.speed * sin( self.angle / ( 180. / pi ) )
			self.hitcooldown -= 1

			for p in ( self.par.p1, self.par.p2 ):
				if self.hitcooldown < 0:
					if self.x + self.r > p.x and self.x - self.r < p.x + p.w and \
					   self.y + self.r > p.y and self.y - self.r < p.y + p.h:

						self.angle %= 360
						
						print self.angle

						if p == self.par.p1: 
							if self.par.p1.m < 0: 
								if not ( 270 > self.angle > 220 ):
									self.angle += 30

							elif self.par.p1.m > 0:
								if not ( 90 < self.angle < 160 ):
									self.angle -= 30

						elif p == self.par.p2: 
							if self.par.p2.m < 0: 
								if not ( 270 < self.angle < 320 ):
									self.angle -= 30

							elif self.par.p2.m > 0:
								if not ( 90 > self.angle > 40 ):
									self.angle += 30

						self.angle = 180 + 360 - self.angle
						#+ ( 45 * ( self.y - (p.y + p.h / 2.) ) / ( p.h / 2. ) )    ##randint( -30, 30 ) ## angle on impact


						if p.x + p.w / 2 - self.x > 0:
							self.x = p.x - self.r
						elif p.x + p.w / 2 - self.x < 0:
							self.x = p.x + p.w + self.r

						p.ballhit = True
						self.hitcooldown = p.w / self.speed + 60
						self.lasthit = p

			if self.x - self.r > self.par.s.get_size(  )[ 0 ]:
				self.dead = True
				self.par.score[0] += 1

			elif self.x + self.r < 0:
				self.dead = True
				self.par.score[1] += 1

			if self.y + self.r > self.par.s.get_size(  )[ 1 ]:
				self.angle = ( ( 360 - self.angle ) % 360 ) + randint( -1, 1 )
				self.y = self.par.s.get_size(  )[ 1 ] - self.r

				if 270 < self.angle < 270 + self.treshold:
					self.angle += 1.5 * self.treshold

				if 270 > self.angle > 270 - self.treshold:
					self.angle += -1.5 * self.treshold

			elif self.y - self.r < 0:
				self.angle = ( ( 360 - self.angle ) % 360 ) + randint( -1, 1 )
				self.y = self.r

				if 90 < self.angle < 90 + self.treshold:
					self.angle += 1.5 * self.treshold

				if 90 > self.angle > 90 - self.treshold:
					self.angle += -1.5 * self.treshold

			for t in self.types:
				t.update(  )

		def draw( self ):

			for t in self.types:
				t.draw(  )

	class Paddle:

		def __init__( self, parent, player, ctrlup, ctrldn, side ):

			self.par = parent
			self.name = player
			self.up = ctrlup
			self.down = ctrldn
			self.color = [ 255, 255, 255 ]
			self.speed = 5
			self.timer = 0
			self.m = 0
			
			self.w = 20
			self.orgh = 60
			self.h = self.orgh
			self.y = self.par.size[ 1 ] / 2.
			self.ballhit = False

			if side == "LEFT": self.x = 20
			if side == "RIGHT": self.x = self.par.size[ 0 ] - 20 - self.w

		def update( self ):

			self.timer += 1
			self.y += self.m

			if not self.y >= 0: self.m = 0; self.y = 0
			if not self.y + self.h <= self.par.s.get_height(  ):
				self.m = 0; self.y = self.par.s.get_height(  ) - self.h

			for e in self.par.events:

				if self.y >= 0 and self.y + self.h <= self.par.s.get_height(  ):

					if e.type == p.KEYDOWN:
						if e.key == getattr( p, self.up ):
							self.m = -self.speed

						if e.key == getattr( p, self.down ):
							self.m = self.speed
							

				if e.type == p.KEYUP:
					if e.key == getattr( p, self.up ) and self.m < 0:
						self.m = 0
					if e.key == getattr( p, self.down ) and self.m > 0:
						self.m = 0

			self.ballhit = False

		def draw( self ):

			p.draw.rect( self.par.s, self.color,
				[ int( self.x ), int( self.y ), int( self.w ), int( self.h ) ] )



	def __init__( self ):

		self.size = ( 640, 480 )
		self.s = p.display.set_mode( self.size ) #, p.FULLSCREEN

		self.reset(  )
		self.debug = 0

	def reset( self ):

		self.p1 = self.Paddle( self, "P1", "K_w", "K_s", "LEFT" )
		self.p2 = self.Paddle( self, "P2", "K_UP", "K_DOWN", "RIGHT" )
		self.items = Items( self )
		self.end = False
		self.score = [0, 0]

		self.balllist = [  ]

		for i in range( 2 ):

			self.makeball()

	def makeball(self):
		
		cs = [ 63, 127, 255 ]
		c = [ cs[ randint( 0, 2 ) ],
			  cs[ randint( 0, 2 ) ],
			  cs[ randint( 0, 2 ) ] ]

		self.balllist.append( self.Ball( self, 8, ( 3, 4 ), c, ( BallTypes.SHADE, ) ) )

	def update( self ):
		
		self.p1.update(  )
		self.p2.update(  )

		l = list( self.balllist )
		for b in self.balllist:
			b.update(  )
			if b.dead: l.remove( b )
		self.balllist = l

		self.items.update(  )

		if len( self.balllist ) <= 0:
			self.end = True
			self.reset(  )

		for b in self.balllist:
			if b.speed < 6:
				b.speed += 1 / 600.

	def draw( self ):

		self.p1.draw(  )
		self.p2.draw(  )
		self.items.draw(  )

		for b in self.balllist:
			b.draw(  )

		if self.debug:

			for n in self.balllist:
				try:
					msg( self.s, n.lasthit.name, ( n.x, n.y - 20 ), size=20, centered=True )
				except:
					msg( self.s, n, ( n.x, n.y - 20 ), size=20 )


		msg( self.s, self.score[0], [self.s.get_width() / 2. - 40,30], size=40, centered=True )
		msg( self.s, self.score[1], [self.s.get_width() / 2. + 40,30], size=40, centered=True )

	def loop( self ):

		c = p.time.Clock(  )

		while 1:

			self.events = p.event.get(  )

			self.s.fill( ( 0,0,0 ) )

			for e in self.events:

				if e.type == p.QUIT:
					p.quit(  )
					quit(  )
				if e.type == p.KEYDOWN:
					if e.key == p.K_d:
						self.debug = self.debug * -1 + 1
					if e.key == p.K_ESCAPE:
						p.quit(  )
						quit(  )

			self.update(  )
			self.draw(  )

			p.display.flip(  )

			c.tick( 60 )
Ejemplo n.º 2
0
class PauseState(gameObject):


    def __init__(self, joystickList, screenSize, systemState, container):
        self.font1 = pygame.font.SysFont("arial", 50)
        self.font2 = pygame.font.SysFont("arial", 30)
        self.screenSize = screenSize
        self.joystickList = joystickList
        self.systemState = systemState
        self.container = container
        
        self.buttonPressed = False##
        self.joystickButtonActivated = True
        self.allowButtonPressing = False
        self.button2Pressed = False##
        self.joystickButton2Activated = True
        self.allowButton2Pressing = False
        
        self.player1 = pygame.sprite.Sprite()
        self.player2 = pygame.sprite.Sprite()
        self.player1.image = pygame.image.load("still//fire01.png").convert_alpha()
        self.player2.image = pygame.image.load("still//fire01.png").convert_alpha()

        self.storyboard = StoryBoard2()
        self.stillDictionary1 = self.container.path1
        self.stillDictionary2 = self.container.path12
        self.itemDictionary = self.container.itemAnimation2
        
        self.score1 = 0
        self.score2 = 0
        self.hp1 = 0
        self.hp2 = 0
        self.time = 0
        
        self.lifeSprite = Items(self.itemDictionary, pygame.Rect((0,0), (20,20)))
        self.background = pygame.image.load("blocks//pausa.png").convert_alpha()
        self.background = pygame.transform.scale(self.background, (self.screenSize[0],self.screenSize[1]))  


    # Setea los datos que se imprimiran en pantalla
    def setParams(self, time, score1, score2, hp1, hp2):
        self.time = time
        self.score1 = score1
        self.score2 = score2
        self.hp1 = hp1
        self.hp2 = hp2

            
    # Update del estado
    def update(self, elapsedTime):
        self.joystickButtonManager(0)
        self.joystickButtonManager(1)
            
        if self.button2Pressed:
            self.container.soundDictionary["pause"].play()
            self.changeState("playState")
            pygame.mixer.music.set_volume(1)


    def render(self):
        screen = pygame.display.get_surface()
        screen.blit(self.background, (0,0))

        textSurf  = self.font1.render("PAUSA" , True,(255, 0, 0))
        screen.blit(textSurf, (self.screenSize[0] / 2 - 100, 30))
        
        textSurf2  = self.font2.render("presione b para volver" , True,(255, 0, 0))
        screen.blit(textSurf2, (self.screenSize[0] / 2 - 145, 400))

        self.animation(len(self.stillDictionary1), self.stillDictionary1, self.player1)
        self.animation(len(self.stillDictionary2), self.stillDictionary2, self.player2)
        self.player1.image = pygame.transform.scale(self.player1.image, (50,50))
        self.player2.image = pygame.transform.scale(self.player2.image, (50,50))

        screen.blit(self.player1.image,  (50, 500))
        screen.blit(self.player2.image,  (670, 200))

        for i in range(self.hp2):
            screen.blit(self.lifeSprite.image,  (120 + (i * 25), 500))
        for i in range(self.hp1):
            screen.blit(self.lifeSprite.image,  (720 + (i * 25), 200))
        self.lifeSprite.update()

        
        textSurf3  = self.font2.render("Puntaje player 1: " + str(self.score1) , True,(0, 0, 0))
        screen.blit(textSurf3, (720, 250))
        
        textSurf4  = self.font2.render("Puntaje player 2: " + str(self.score2), True,(0, 0, 0))
        screen.blit(textSurf4, (120, 550))
        
        textSurf5  = self.font2.render("Tiempo restante : "  + str(int(150 - self.time)), True,(255, 0, 0))
        screen.blit(textSurf5, (self.screenSize[0] / 2 - 143, 690))


    # ChangeState
    def changeState(self, stateName):
        self.systemState.changeState(stateName)
        self.systemState.currentState.buttonPressed = False##
        self.systemState.currentState.joystickButtonActivated = True
        self.systemState.currentState.allowButtonPressing = False
        self.systemState.currentState.button2Pressed = False##
        self.systemState.currentState.joystickButton2Activated = True
        self.systemState.currentState.allowButton2Pressing = False


    # Ahora keys son las imagenes que se pasan a storyboard
    def animation(self, number, images, sprite):
        if self.storyboard.inProcess == False:
            self.storyboard.play(number, images)
        elif self.storyboard.inProcess:
            return self.storyboard.update(sprite, False)

        
    ## JOYSTICK
    def joystickButtonManager(self, id):
        if id == 0:
            if  (not self.joystickList[0].get_button(id) and self.joystickButtonActivated):
                self.joystickButtonActivated = False
                self.allowButtonPressing = True
            if (self.joystickList[0].get_button(id) and self.joystickButtonActivated and not self.allowButtonPressing):
                self.buttonPressed = False
            if (self.joystickList[0].get_button(id) and not self.buttonPressed and self.allowButtonPressing):
                self.allowButtonPressing = False
                self.buttonPressed = True
                self.joystickButtonActivated = True
        elif id == 1:
            if (not self.joystickList[0].get_button(id) and self.joystickButton2Activated):
                self.joystickButton2Activated = False
                self.allowButton2Pressing = True
            if (self.joystickList[0].get_button(id) and self.joystickButton2Activated and not self.allowButton2Pressing):
                self.button2Pressed = False
            if (self.joystickList[0].get_button(id) and not self.button2Pressed and self.allowButton2Pressing):
                self.allowButton2Pressing = False
                self.button2Pressed = True
                self.joystickButton2Activated = True
Ejemplo n.º 3
0
class level:

    
    # Constructor
    def __init__(self, joystickList, screenSize, initialPath, container):

        self.screenSize = screenSize
        self.joystickList = joystickList
        self.container = container
        self.font = pygame.font.SysFont("arial", 18)
        self.font.set_bold(True)
        self.pauseGame = False
        self.gameOver = False
        self.playerInDeadZone = False
        self.totalElapsedTime = 0
        self.deadMessage = ""
        
        self.walk  = self.container.soundDictionary["walk"]
        self.walk.set_volume(0.1)
        self.jump = self.container.soundDictionary["jump"]
        self.jump.set_volume(0.1)
        self.slide = self.container.soundDictionary["slide1"]
        self.slide.set_volume(0.1)

        self.background = Background(self.screenSize, initialPath, self.container)        
        self.backgroundImage = self.container.imageDictionary[self.background.levelMaker.actualBackgroundKey]
        self.backgroundImage = pygame.transform.scale(self.backgroundImage, (self.screenSize[0], self.screenSize[1]))

        # Relacionado al hub
        self.lifeSprite = Items(self.background.itemAnimation2, pygame.Rect((0,0), (20,20)))
        self.hub = pygame.image.load("blocks//hub.png").convert_alpha()
        self.hub = pygame.transform.scale(self.hub, (670, 65))

        x = self.background.levelMaker.startXPosition
        y = self.background.levelMaker.startYPosition

        if len(self.joystickList) == 2 and self.joystickList != None:
            self.player1  = Player(self.joystickList[0], ProjectileMotion(), FreeFall(15), StoryBoard2(), self.container, x, y)
            self.player2  = Player(self.joystickList[1], ProjectileMotion(), FreeFall(15), StoryBoard2(), self.container, x, y)
        else:
            self.player1  = Player(self.joystickList[0], ProjectileMotion(), FreeFall(15), StoryBoard2(), self.container, x, y)
            self.player2  = Player(self.joystickList[0], ProjectileMotion(), FreeFall(15), StoryBoard2(), self.container, x, y)
        self.player1.id = "p1"
        self.player2.id = "p2"
        
        self.player1.companero = self.player2
        self.player2.companero = self.player1

        # Flecha guia (para ubicar a otro player
        self.compassImageUp   = pygame.image.load("blocks//arrowUp.png").convert_alpha()
        self.compassImageDown = pygame.image.load("blocks//arrowDown.png").convert_alpha()
        self.compassImageRight = pygame.image.load("blocks//arrowRight.png").convert_alpha()
        self.compassImageLeft = pygame.image.load("blocks//arrowLeft.png").convert_alpha()
        self.compass = pygame.sprite.Sprite()
        self.compass.image = self.compassImageUp
        self.verticalCompassNeeded  = False
        self.horizontalCompassNeeded = False
        self.P1horizontalCompassNeeded = False

        self.buttonPressed = False##
        self.joystickButtonActivated = True
        self.allowButtonPressing = False
        self.button2Pressed = False##
        self.joystickButton2Activated = True
        self.allowButton2Pressing = False

  
    # Update de todas las variables relevantes
    def update(self, elapsedTime):

        # Tiempo
        self.totalElapsedTime += elapsedTime
        if self.totalElapsedTime > 200:
            self.gameOver = True
            self.deadMessage = "TIME'S UP!"

        # Brujula que apunta a player 2
        if  self.player2.Y <= -50 or self.player2.Y >= self.screenSize[1]:
            self.horizontalCompassNeeded = True
        elif self.player2.X <= -50 or self.player2.X >= self.screenSize[0]:
            self.verticalCompassNeeded = True
        else:
            self.horizontalCompassNeeded = False
            self.verticalCompassNeeded = False
            
        # Brujula que apunta a player 1
        if  self.player1.Y <= -50 or self.player1.Y >= self.screenSize[1]:
            self.P1horizontalCompassNeeded = True
        else:
            self.P1horizontalCompassNeeded = False
        
        # Update a las instancias del nivel
        #for sprite in self.background.group:
        #   if sprite.activada:
        #       if not((self.player1.color == sprite.color and pygame.sprite.collide_rect(sprite,self.player1.sprite))) and  not((self.player2.color == sprite.color and pygame.sprite.collide_rect(sprite,self.player2.sprite)))  :
        #            sprite.activada = False
        #       if not((self.player2.color == sprite.color and pygame.sprite.collide_rect(sprite,self.player2.sprite))):
        #           sprite.activada = False
               #else:
               #   sprite.activada = False
        #for sprite in self.background.group:
        #    if sprite.activada:
        #        if (pygame.sprite.collide_rect(sprite,self.player1.sprite)):
        #               if(self.player1.color == sprite.color):
        #                   sprite.activada = True
        #        if (pygame.sprite.collide_rect(sprite,self.player2.sprite)):
        #               if(self.player2.color == sprite.color):
        #                   sprite.activada = True
        
        for sprite in self.background.group:
            sprite.activada = False             
        self.player2.update(elapsedTime, self.background.group, self.background.exitGroup, self.background.damageGroup, self.background.itemsGroup, self.background.zGroup, self.background.groupList)#-----------------#
        self.player1.update(elapsedTime, self.background.group, self.background.exitGroup, self.background.damageGroup, self.background.itemsGroup, self.background.zGroup,  self.background.groupList)
        self.backgroundXMovementManager(self.player1, self.player2)
        self.backgroundYMovementManager(self.player1, self.player2)
        for torreta in self.background.levelMaker.torretas:
            torreta.update(elapsedTime,self.background.group,self.background.xAdvance, self.background.yAdvance, self.player1, self.player2,self.screenSize)
            
        self.background.update(elapsedTime, self.player1.X, self.player1.Y)

        
        """
        # DISTANCIA PERSONAJES (TEMPORAL)
        if abs(self.player1.X - self.player2.X) >= self.screenSize[0]:
            self.player2.X = self.player1.X
            self.player2.Y = self.player1.Y
        if abs(self.player1.Y - self.player2.Y) >= self.screenSize[1]:
            self.player2.X = self.player1.X
            self.player2.Y = self.player1.Y
        #"""   


        ###########CAMBIO_DE_ETAPA##################################
        if self.player1.exitStage or self.player2.exitStage:
            self.player1.exitStage = False
            self.player2.exitStage = False

            self.background.changeBackground()

            self.backgroundImage = self.container.imageDictionary[self.background.backgroundKey]
            self.backgroundImage = pygame.transform.scale(self.backgroundImage, (self.screenSize[0], self.screenSize[1]))
            
            self.player1.X = self.background.levelMaker.startXPosition
            self.player1.Y = self.background.levelMaker.startYPosition
            self.player2.X = self.background.levelMaker.startXPosition 
            self.player2.Y = self.background.levelMaker.startYPosition

        #################GAME_OVER##################################
        if self.player1.dead or self.player2.dead:
            self.gameOver = True
            if self.player1.dead:
                self.deadMessage = self.player1.deadMessage
            else:
                self.deadMessage = self.player2.deadMessage
                 

    # Dibuja en pantalla los sprites y el escenario
    def render(self):
        
        # Instancia de la ventana de pygame
        screen = pygame.display.get_surface()

        # Render a las instancias del nivel
        screen.blit(self.backgroundImage, (0,0))
        
        self.player1.render()   
        self.player2.render()
        self.background.render()
        for torreta in self.background.levelMaker.torretas:
            torreta.render()

        # Brujula que apunta a otro player
        if self.horizontalCompassNeeded or self.P1horizontalCompassNeeded:
            if self.player2.Y <= -50 or self.player1.Y <= -50:
                self.compass.image = self.compassImageUp
                if self.player2.Y <= -50:
                    screen.blit(self.compass.image, (self.player2.X, 0))
                else:
                    screen.blit(self.compass.image, (self.player1.X, 0))
            if self.player2.Y >= self.screenSize[1] or self.player1.Y >= self.screenSize[1]:
                self.compass.image = self.compassImageDown
                if self.player2.Y >= self.screenSize[1]:
                    screen.blit(self.compass.image, (self.player2.X, self.screenSize[1] - 15))
                else:
                    screen.blit(self.compass.image, (self.player1.X, self.screenSize[1] - 15))
        if self.verticalCompassNeeded:
            if self.player2.X <= -50:
                self.compass.image = self.compassImageLeft
                screen.blit(self.compass.image, (0, self.player2.Y))
            if self.player2.X >= self.screenSize[0]:
                self.compass.image = self.compassImageRight
                screen.blit(self.compass.image, ((self.screenSize[0] - 15), self.player2.Y))

        # HUB SCREEN
        screen.blit(self.hub,  (180, 0))
        
        textSurf1 = self.font.render("P1 HP: " , True,(27, 141, 67))
        textSurf2 = self.font.render("P2 HP: " , True,(0, 0, 255))
        textSurf3 = self.font.render("Puntaje: " + str(int(self.player1.score)) , True, (27, 141, 67))
        textSurf4 = self.font.render("Puntaje: " + str(int(self.player2.score)) , True, (0, 0, 255))
        textSurf5 = self.font.render("Tiempo restante: " + str(150 - int(self.totalElapsedTime)) , True,(255, 0, 0))
        
        screen.blit(textSurf1,  (400, 10))
        screen.blit(textSurf2,  (400, 40))
        screen.blit(textSurf3,  (700, 10))
        screen.blit(textSurf4,  (700, 40))
        screen.blit(textSurf5,  (190, 10))
    

        for i in range(self.player1.lives):
            screen.blit(self.lifeSprite.image,  (470 + (i * 20), 10))
        for i in range(self.player2.lives):
            screen.blit(self.lifeSprite.image,  (470 + (i * 20), 40))
        self.lifeSprite.update()
 

    # Intento de arreglar el algoritmo. Veamos como resulta
    def backgroundYMovementManager(self, player1, player2):
 
        # Obtiene los valores de posicion de primer y ultimo sprite del grupo
        firstRect = self.background.levelMaker.firstRect
        lastRect  = self.background.levelMaker.lastRect
        
        # relevante para scrolling horizontal y vertical

        leftStageX = firstRect.left
        rightStageX = lastRect.left
        topStageY = firstRect.top
        bottomStageY = lastRect.top
        halfH = self.screenSize[1]/2.0
        height = self.screenSize[1]

        levelHigherThanScreen = self.background.levelMaker.height * 50 > self.screenSize[1]
    
        _2playerUpperLimit = 0
        _2playerBottomLimit = height - 100
        _2PlayerInScreen = player2.Y >= _2playerUpperLimit and player2.Y <= _2playerBottomLimit
        # El 50 es para tomar en cuenta la altura del personaje
        _2PlayerInRealScreen = _2PlayerInScreen  #player2.Y >= -50 and player2.Y <= height
        _1PlayerInRealScreen = player1.Y >= -50 and player1.Y <= height
                
        deltaDownDeadZone = abs(firstRect.top) # Background moving down
        deltaUpDeadZone = lastRect.top - height # Background moving up

        # Caso en que etapa es demasiado pequena
        if not levelHigherThanScreen:
            player1.Y -= player1.deltaY
            
        # Si player esta centrado y player 2 se encuentra en pantalla ficticia
        # Camara seguira a player 1 hasta que player 2 salga de pantalla por delta de player 1
        # Revisar que se respeten las deadZones
        elif player1.Y == halfH and _2PlayerInScreen:
        
            # Caso en que el player2 esta dentro del area y no toca los bordes
            if (player2.Y + player1.deltaY > _2playerUpperLimit) and (player2.Y + player1.deltaY < _2playerBottomLimit):
                self.background.yAdvance = player1.deltaY
                if   player1.deltaY < 0:
                    self.background.moveBackGroundUp = True
                    self.background.yAdvance = -min(abs(player1.deltaY), deltaUpDeadZone)
                elif player1.deltaY > 0:
                    self.background.moveBackGroundDown = True
                    self.background.yAdvance = min(player1.deltaY, deltaDownDeadZone)

                player2.Y += self.background.yAdvance#---------------------------#
                player1.Y -= player1.deltaY - self.background.yAdvance

            # Si player dos se sale del limite inferior al aplicar movimiento de player 1
            # Player 1 esta subiendo
            elif player2.Y < _2playerBottomLimit and (player2.Y + player1.deltaY > _2playerBottomLimit):
                self.background.moveBackGroundDown = True
                deltaP1 = (player2.Y + player1.deltaY) - _2playerBottomLimit
                deltaBackground =  player1.deltaY - deltaP1
                deltaBackground = min(deltaBackground , deltaDownDeadZone)#######################################################33
                self.background.yAdvance = deltaBackground      
                player1.Y -= deltaP1
                player2.Y += self.background.yAdvance#---------------------------#  
            
            # Si player 2 se sale de limite superior al aplicar movimiento de player 1
            # Player 1 esta cayendo
            elif player2.Y > _2playerUpperLimit and (player2.Y + player1.deltaY < _2playerUpperLimit):
                self.background.moveBackGroundUp = True
                deltaBackground = player2.Y # antes era (-), asi que si cualquier bug aparece, volver a eso
                deltaBackground = -min(deltaBackground , deltaUpDeadZone)#######################################################33
                deltaP1 = (-1) * abs(player1.deltaY - deltaBackground)
                self.background.yAdvance = deltaBackground
                player1.Y -= deltaP1
                player2.Y += self.background.yAdvance#--------------------------#
            
        # Player esta centrado y player 2 no esta en pantalla
        # Camara sigue a player 1 de forma completa
        # Revisar que se respeten las deadZones OK
        elif player1.Y == halfH and not _2PlayerInRealScreen:
            self.background.yAdvance = player1.deltaY
            if   player1.deltaY < 0:
                self.background.moveBackGroundUp = True
                self.background.yAdvance = -min(abs(player1.deltaY), deltaUpDeadZone)
            elif player1.deltaY > 0:
                self.background.moveBackGroundDown = True
                self.background.yAdvance = min(player1.deltaY, deltaDownDeadZone)

            player1.Y -= player1.deltaY - self.background.yAdvance
            player2.Y += self.background.yAdvance
            
        # Si ningun player esta en pantalla, esta se centra automaticamente en player 1
        # es una prueba
        elif not _2PlayerInRealScreen and not _1PlayerInRealScreen :
            self.jump.play()
        
        # Si player 1 no esta centrado : 
        # Si player 2 esta en pantalla, se centrara sujeto a que no quede fuera de pantalla ficticia
        # Si player 2 no esta en pantalla, solo se centrara
        # Revisar que se respeten las deadZones
        elif player1.Y != halfH:

            # Si player 2 esta en el area
            if player2.Y > _2playerUpperLimit and player2.Y < _2playerBottomLimit and (firstRect.top <= 0 and lastRect.top >= height):
                #player2.Y > _2playerUpperLimit and player2.Y < _2playerBottomLimit and 
                deltaP1 = player1.Y - halfH           
                    
                # Esta sobre la linea media. Escenario baja con player 1 para dejarlo centrado
                # No puede pasar que firstRect.top quede mayor que cero (al alejarse de origen)
                if player1.Y < halfH: #and _2PlayerInScreen:
                    deltaDeadZone = abs(firstRect.top)
                    #if player2.deltaY > 0:
                    deltaP1 = -min(abs(_2playerBottomLimit - player2.Y), abs(deltaP1), deltaDeadZone)
                    #elif player2.deltaY <= 0: #and player1.Y + player2.deltaY > 0:
                    #    deltaP1 = - player2.deltaY
                    self.background.moveBackGroundDown = True
                
                # Esta bajo la linea media. Escenario sube con player 1 para dejarlo centrado
                # No puede pasar que lastRect.bottom quede menor que height
                elif player1.Y > halfH: #and _2PlayerInScreen:
                    deltaDeadZone = lastRect.top - height
                    deltaP1 = min(abs(player2.Y), abs(deltaP1), deltaDeadZone)
                    self.background.moveBackGroundUp = True
                
                self.background.yAdvance = -deltaP1
                player2.Y += self.background.yAdvance#-----------------#
                player1.Y -= deltaP1
            
            ## Player 1 se encuentra bajo linea media 
            if player1.Y > halfH:
                # Si saltar lo deja arriba de linea media
                if player1.Y - player1.deltaY <= halfH:
                    deltaP1 = player1.Y - halfH
                    self.background.moveBackGroundDown = True
                    deltaBackground1 = abs(player1.deltaY) - deltaP1
                    deltaBackground2 = min(deltaBackground1, deltaDownDeadZone)#######################################################33
                    self.background.yAdvance = deltaBackground2
                    deltaP1 -= abs(deltaBackground2 - deltaBackground1)
                    player2.Y += self.background.yAdvance#-----------------#
                    player1.Y -= deltaP1
                # Si saltar lo sigue dejando abajo de la linea
                elif player1.Y - player1.deltaY > halfH:
                    player1.Y -= player1.deltaY

            ## Se encuentra sobre linea media
            elif player1.Y < halfH:
                # Si caer lo deja bajo la linea
                if player1.Y - player1.deltaY >= halfH:
                    deltaP1 = player1.Y - halfH
                    deltaBackground1 = abs(player1.deltaY) - abs(deltaP1)
                    deltaBackground2 = - min(deltaBackground1, deltaUpDeadZone)#######################################################33
                    self.background.moveBackGroundUp = True
                    self.background.yAdvance = deltaBackground2
                    deltaP1 -= abs(abs(deltaBackground2) - abs(deltaBackground1))
                    player2.Y += self.background.yAdvance#-----------------#
                    player1.Y -= deltaP1
                # Si caer lo sigue dejando sobre la linea
                elif player1.Y - player1.deltaY < halfH:
                    player1.Y -= player1.deltaY

            ## Se tiene que llegar a esto en caso de que todo el resto no se cumpla
            else:
                player1.Y -= player1.deltaY


    # Se encarga de movimiento horizontal para camara con dos jugadores
    def backgroundXMovementManager(self, player1, player2):

        levelWiderThanScreen = self.background.levelMaker.width * 50 > self.screenSize[0]

        # Obtiene los valores de posicion de primer y ultimo sprite del grupo
        firstRect = self.background.levelMaker.firstRect
        lastRect  = self.background.levelMaker.lastRect
        
        # relevante para scrolling horizontal y vertical
        leftStageX = firstRect.left
        rightStageX = lastRect.left
        halfW = self.screenSize[0]/2.0


        if not levelWiderThanScreen:
            player1.X += player1.deltaX

        elif  ((player1.X + player1.deltaX) - leftStageX <= halfW) and (player1.X - leftStageX > halfW) and player1.deltaX < 0:
            rightPart = player1.X - (halfW + leftStageX)
            leftPart = abs(player1.deltaX) - rightPart

            player1.X += player1.deltaX + rightPart
            self.background.moveBackGroundForward = True
            self.background.xAdvance = abs(rightPart)
        
        elif (player1.X - leftStageX <= halfW) and ((player1.X + player1.deltaX) - leftStageX > halfW) and player1.deltaX > 0 :
            leftPart = (leftStageX + halfW) - player1.X
            rightPart = player1.deltaX - leftPart
                
            player1.X += player1.deltaX - rightPart
            self.background.moveBackGroundBackward = True
            self.background.xAdvance = abs(rightPart) * (-1)
        
        elif (rightStageX - player1.X > halfW) and (rightStageX - (player1.X + player1.deltaX) <= halfW) and player1.deltaX > 0:
            leftPart = (rightStageX - halfW) - player1.X
            rightPart = player1.deltaX - leftPart

            player1.X += player1.deltaX  - leftPart
            self.background.moveBackGroundBackward = True
            self.background.xAdvance = abs(leftPart) * (-1)
        
        elif (rightStageX - player1.X <= halfW) and (rightStageX - (player1.X + player1.deltaX) > halfW) and player1.deltaX < 0:
            rightPart = player1.X - (rightStageX - halfW)
            leftPart = abs(player1.deltaX) - rightPart

            player1.X += player1.deltaX + leftPart
            self.background.moveBackGroundForward = True
            self.background.xAdvance = abs(leftPart)
        
        elif((player1.X - leftStageX) >= halfW) and ((rightStageX - player1.X) >= halfW):
            self.background.xAdvance = -int(player1.deltaX)
            if player1.deltaX > 0:
                self.background.moveBackGroundBackward = True
            elif player1.deltaX < 0:
                self.background.moveBackGroundForward = True
        else:
            player1.X += player1.deltaX


        player2.X += self.background.xAdvance#---------------------------#