I'm dipping my toes into neuralnetworks/neuroevolution, but I keep running into this issue in pygame where the pipes in flappy bird are spawning twice in rapid succesion at the start of a new generation. How can I stop this?
Relevant code:
SPAWNPIPE = pg.USEREVENT
pg.time.set_timer(SPAWNPIPE, 1000)
while True:
clock.tick(60)
for event in pg.event.get():
if event.type == pg.QUIT:
pg.quit()
if event.type == SPAWNPIPE and canspawn:
pipelist.append(Pipe())
if game_active:
#draw bg/fground
screen.blit(bgsurface, (0,0))
ground_x -= 1
if ground_x <= -512:
ground_x = -256
screen.blit(ground, (ground_x, height/1.4))
#draw pipes
for pipe in pipelist:
pipe.move()
pipe.draw()
if pipe.delete():
pipelist.remove(pipe)
#birds stuff
fitness += 1
displayscore(generation, fitness)
if birds.update(pipelist) == 0:
fitness = 0
pipelist.clear()
canspawn = False
generation += 1
birds.newgen(pop, mrate)
canspawn = True
pg.display.update()