I'm working on a 3rd level of my game. When the 3rd level begins the Camera and Hero position is getting same value which was left by the 2nd level at the end point. I'm not able to find a way around to reset camera and hero position values and start the level with 0 coordinates.
Here is a short video about the issue - https://www.youtube.com/watch?v=KtEW4cbpT5A
What I tried so far,
In game when the player hits the tunnel which appears at the end of the level 2 - value of level variable is changed to 3 so it can load data for 3rd level
# This function works for Tunnel Only def tunnelHit_or_not_2(self, hero, tunnel): hit = pygame.sprite.collide_rect(hero, tunnel) if hit: self.level = 3 self.hero.x = 0 self.CameraX = 0
I've set self.CameraX value to 0 but when player enters 3rd level its not updating CameraX value as the player moves. Same goes with self.hero.x value. Its not updating either. It works well for 1st and 2nd level but not for 3rd level
Here is a code which is responsible to update the camera and hero.x position,
if self.noBorderCross: self.hero.x += self.hero.velocity if self.noCameraCross: if self.level == 3: # Moving Coins self.updateCoinPos(self.coin_forest) # Moving Platform_sky self.updatePlatformPos(self.platform_forest) self.updateEnemyPos(self.enemy_forest) # For moving enemies dead bodies in lvl 2 for e in self.enemy_forest: if e.enemyDead: e.x += self.hero.velocity if self.hero.x >= startScrollingPos_forest: self.noBorderCross = False self.coordinates = 3700 # Updating rect of Platform_sky self.updatePlatformRect(self.platform_forest) self.updateCoinRect(self.coin_forest) self.CameraX += self.hero.velocity if self.CameraX >= self.coordinates: self.noCameraCross = False if self.hero.x < 890 - self.hero.velocity - self.hero.width: self.hero.x += self.hero.velocity #self.level = 2
Can anyone help me out in how to reset camera and hero position in 3rd level where it gets updated when the player moves on screen.
Here is my full code (main class) link - https://pastebin.com/CuGF9pQM
Thanks in Advance