Pygame: How to ignore collisions -
okay making 2d scroller game pygame want able control when take collisions consideration. example, after player collides , dies respawns straight away in middle of screen, problem there collision object close kills player instantly. want small time period in player immured collisions allowing move away safety first carry on playing ad normal. thinking maybe placing respawns in dummy sprite group on time remove , add group has collisions. don't know.
when player dies, set variable number of frames want invulnerable for. when collision detection, can check if player has frames of invulnerability left, , handle collisions when there no frames left.
def kill_player(player): # handle moving player after death, else need # set player invulnerability 30 frames player_invulnerable_frames = 30 if environment_rect.collides(player_rect) , player_invulnerable_frames = 0: # perform collision response stuff here
in game loop, or maybe update function, can decrease number of invulnerability frames if greater zero
while(running): # game loop stuff if player_invulnerable_frames > 0: player_invulnerable_frames -= 1
Comments
Post a Comment