added constant shoot
FIX: remove the bullet when it exits the screen
This commit is contained in:
parent
1a46e13708
commit
dd81190a4e
1 changed files with 19 additions and 2 deletions
21
pyshoot.py
21
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"""
|
||||
|
|
Loading…
Reference in a new issue