def event_paused_step(self, time_passed, delta_mult): self.show_hud() if self.pairs: #Draw the next cross operation i1, i2 = self.pairs.pop() self.gensprite.draw_clear() self.gensprite.draw_circle(i1.x + i1.bbox_width / 2, i1.y + i1.bbox_height / 2, i1.bbox_width, outline=CITIUS_COLOR) self.gensprite.draw_circle(i2.x + i2.bbox_width / 2, i2.y + i2.bbox_height / 2, i2.bbox_width, outline=CITIUS_COLOR) self.gensprite.draw_line(i1.x + i1.bbox_width / 2, i1.y + i1.bbox_height / 2, i2.x + i2.bbox_width / 2, i2.y + i2.bbox_height / 2, CITIUS_COLOR, thickness=2) children_genes = evolution.recombinate( [(i1, i2)], objects.Invader.gene_props)[0] #And add the new individual desc = objects.Invader(**children_genes) desc.x, desc.y = (i1.x + i2.x) / 2, (i1.y + i2.y) / 2 self.current_room.add(desc) #Slow down painting to visually improve the animation if self.anim_sleep is None: #The animation time is adjusted according to the number of new #individuals. self.anim_sleep = ( 1.0 if len(self.pairs) == 0 else 0 if len(self.pairs) > 50 else min(1.0, 3.0 / len(self.pairs))) if self.score > 4: self.anim_sleep = 0 else: time.sleep(self.anim_sleep) elif self.pairs is not None: #Crossing is finished time.sleep(self.anim_sleep) self.pairs = self.anim_sleep = None self.score += 1 self.last_gen = 0 self.unpause()
os.chdir(os.path.dirname(os.path.realpath("__file__"))) # Create Game object game.InvadersGame() # Load backgrounds wall_sprite = sge.gfx.Sprite(width=game.RESX, height=game.WALL_HEIGHT) wall_sprite.draw_rectangle(0, 0, wall_sprite.width, wall_sprite.height, fill=sge.gfx.Color('white')) layers = [ sge.gfx.BackgroundLayer(wall_sprite, 0, game.RESY - game.WALL_YOFFSET) ] background = sge.gfx.Background(layers, sge.gfx.Color('black')) # Create objects invaders = [objects.Invader() for _ in range(6)] player = objects.Player() #Player is always the first object obj = [player] + invaders # Create room sge.game.start_room = game.GameRoom(obj, background=background) # Remove the mouse to increase performance by avoiding collision detection sge.game.mouse.visible = False sge.game.start_room.remove(sge.game.mouse) # Here we go! sge.game.start()