I'm making a complicated (at least for what I've ever done) platformer in pygame. It involves having the player reset to a position when the timer runs out or they get hurt by a spike, but I am having an issue. The player's reset method doesn't work more than once.
In the player's class, I use vector2's for the position and movement:
#Set kinematic constants
self.HORIZONTAL_ACCELERATION = 3
self.HORIZONTAL_FRICTION = .5
self.VERTICAL_ACCELERATION = .5 #Gravity
self.ORIGINAL_POS = vector(x, y)
#Set movement vectors
self.position = vector(x, y)
self.acceleration = vector(0, 0)
self.velocity = vector(0, 0)
And in the reset method, I use this code:
self.velocity = vector(0, 0)
self.position = self.ORIGINAL_POS
self.rect.bottomleft = self.position
But for some reason, the ORIGINAL_POS variable doesn't seem to function properly. In my main script, I have a game class that calls this once a spike collides with the player or the timer runs out:
elif collided_tiles[0].index == 7:
#Spikes, other one is for timer
self.pause_game("Watch out for spikes!", "Press 'ENTER' to continue")
self.player.reset()
self.player.lives -= 1
self.timer = 100
if self.timer < 0:
self.pause_game("Be quicker next time...", "Press 'ENTER' to continue")
self.player.reset()
self.player.lives -= 1
self.timer = 100
I don't know why the code is resetting the ORIGINAL_POS variable, and I can't wrap my head around it. Any help would be very appreciated!
Here is the link to the project.