Skip to content

Commit 3a3a468

Browse files
authored
Added a remove_pipes function and call it in main loop
Added a remove_pipes function which will remove the pipes from the pipe_list when the pipe goes out of the screen This will help to render objects accordingly as only few pipes have to be rendered all the time.
1 parent fd734e7 commit 3a3a468

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

flappy.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ def draw_pipes(pipes):
2222
else:
2323
flip_pipe = pygame.transform.flip(pipe_surface,False,True)
2424
screen.blit(flip_pipe,pipe)
25-
25+
def remove_pipes(pipes):
26+
for pipe in pipes:
27+
if pipe.centerx == -600:
28+
pipes.remove(pipe)
29+
return pipes
2630
def check_collision(pipes):
2731
for pipe in pipes:
2832
if bird_rect.colliderect(pipe):
@@ -152,6 +156,7 @@ def update_score(score, high_score):
152156

153157
# Pipes
154158
pipe_list = move_pipes(pipe_list)
159+
pipe_list = remove_pipes(pipe_list)
155160
draw_pipes(pipe_list)
156161

157162
score += 0.01

0 commit comments

Comments
 (0)