python - Adding enemies to a pygame platformer -
i'm new pygame , trying make platformer game that's based on tutorial: http://programarcadegames.com/python_examples/show_file.php?file=platform_scroller.py
i can't quite figure out how add moving enemies, can me?
moving enemies of combination of how player , platform objects work in example linked:
the enemy class subclass of
pygame.sprite.sprite, similar both aforementioned objects.they have implement
update()method, similarplayer, define how move on each frame. @player.update()guidance; basically, moveenemy'srectin way.instances of enemy class should added level's
enemy_listobject (which exists in example code), means updated , drawn on every frame. similar howlevel_0xconstructors addplatforminstances level'splatform_listvariable.
in short, like:
class enemy(pygame.sprite.sprite): def __init__(self): # set size, look, initial position, etc. of enemy here... pass def update(self): # define how enemy moves on each frame here... pass class level_01(level): def __init__(self, player): # platform code in example goes here... # add 2 enemies level self.enemy_list.add(enemy()) self.enemy_list.add(enemy())
Comments
Post a Comment