diff --git a/pyshoot.py b/pyshoot.py index 698c26d..e03f311 100755 --- a/pyshoot.py +++ b/pyshoot.py @@ -83,10 +83,22 @@ class Bullet(Object): def __init__(self, frames, type, pos): Object.__init__(self, frames, pos, (0, 0)) self.type = type + + def update(self): + # destroy when collide or when exists the screen + if self.in_screen(): + self.rect.move_ip(self.speed) + else: + globals.bullets_list.remove(self) + + def in_screen(self): + """ detect if bullet is in the screen """ + return self.rect.colliderect(globals.screen.get_rect()) class Player(Object): def __init__(self, frames, pos, speed): Object.__init__(self, frames, pos, speed) + self.shooting = False def shoot(self): """ create a bullet and add it to the global bullet list""" @@ -106,10 +118,15 @@ class Player(Object): globals.moving_objects.remove(self) def start_shoot(self): - self.shoot() + self.shooting = True def stop_shoot(self): - pass + self.shooting = False + + def update(self): + self.rect.move_ip(self.speed) + if self.shooting: + self.shoot() def init_gfx(): """graphics initialisation"""