I'm new to pygame and trying to make a platformer game that's based on this tutorial: http://programarcadegames.com/python_examples/show_file.php?file=platform_scroller.py
I can't quite figure out how to add moving enemies, can you help me?
I'm new to pygame and trying to make a platformer game that's based on this tutorial: http://programarcadegames.com/python_examples/show_file.php?file=platform_scroller.py
I can't quite figure out how to add moving enemies, can you help me?
Moving enemies would be something of a combination of how the
PlayerandPlatformobjects work in the example to which you linked:The enemy class would be a subclass of
pygame.sprite.Sprite, similar to both aforementioned objects.They would have to implement an
update()method, similar toPlayer, to define how they move on each frame. Look atPlayer.update()for guidance; basically, move theEnemy'srectin some way.Instances of the enemy class should be added to a level's
enemy_listobject (which already exists in the example code), which means they would be updated and drawn on every frame. This is similar to howLevel_0xconstructors addPlatforminstances to the level'splatform_listvariable.In short, that would look something like: