Package: game-coroutines
game_coroutinesgame_coroutines is a pure-python lib with no dependencies, to simplify calling
methods over time on game environments.For example, on a game, if you need to move a sprite from point (0, 100) to
(300, 100) over 10 seconds, you will need to deal with frame updates,
delta_times and controlling the position over time.With game_coroutines you can create a coroutine to do that for you, for example:#main.pyimportarcadefromgame_coroutinesimportCoroutine...self.player=#player sprite creation...defmove_player(progress):self.center_x=arcade.lerp(0,300,progress)move_routine=Coroutine(delay=0.0,duration=10,progress_func=move_player)move_routine()Is was maded to work with arcade, but it can run easily on py-game too.Installpip install game_coroutinesConfiguringIt's very easy to configure game_coroutines. You need to call.starton the
setup method and.updateon the on_update.StartCall start on yoursetupmethod:#main.pyfromgame_coroutinesimportCoroutineManager......defsetup(self):...CoroutineManager.start()UpdateUpdate coroutine manager every FPS tick:#main.py......defon_update(self,delta_time):...CoroutineManager.update(delta_time)Call CoroutineNow you can create your Coroutine and call it.#main.pyimportarcadefromgame_coroutinesimportCoroutine...self.player=#player sprite creation...defmove_player(progress):self.center_x=arcade.lerp(0,300,progress)move_routine=Coroutine(delay=0.0,duration=10,progress_func=move_player)move_routine()CallbacksYou can have callbacks to be called after a coroutine finishes.A callback can be any Callable object or a Coroutine (which is a Callable
object too).#main.pyimportarcadefromgame_coroutinesimportCoroutine...self.player=#player sprite creation...defmove_player(progress):self.center_x=arcade.lerp(0,300,progress)defprint_player_x_after():print(f'Finished moving at:{self.player.center_x}')defscale_up_player(progress):self.center_x=arcade.lerp(1,1.5,progress)scale_routine=Coroutine(delay=0.0,duration=10,progress_func=scale_up_player,callback=print_player_x_after)move_routine=Coroutine(delay=0.0,duration=10,progress_func=move_player,callback=scale_routine)move_routine()On the example above we have 2 coroutines:scale_routineandmove_routine.We first callmove_routine. After it finishes, it will start the coroutinescale_routinewhich is defined as callback.Afterscale_routineends, it will call theprint_player_x_afterfunction.SequenceYou can call a sequence of couroutines too:#main.pyimportarcadefromgame_coroutinesimportSequence,Coroutine...self.player=#player sprite creation...defmove_player(progress):self.center_x=arcade.lerp(0,300,progress)defscale_up_player(progress):self.center_x=arcade.lerp(1,1.5,progress)defscale_down_player(progress):self.center_x=arcade.lerp(1.5,1,progress)Sequence(Coroutine(delay=0.0,duration=10,progress_func=move_player),Coroutine(delay=0.1,duration=1,progress_func=scale_up_player),Coroutine(delay=0.1,duration=1,progress_func=scale_down_player))Sequences starts after initializing, don't need to call it.ContributionsFuture Needs:testsaccept callbacks with args[add your needs here]PRs are welcome!How to upload to PipThis section is for the maintainer to remember how to upload to pypi.
Move along.python setup.py sdist
pip install twine
twine upload dist/*