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
|
@ -84,9 +84,21 @@ class Bullet(Object):
|
||||||
Object.__init__(self, frames, pos, (0, 0))
|
Object.__init__(self, frames, pos, (0, 0))
|
||||||
self.type = type
|
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):
|
class Player(Object):
|
||||||
def __init__(self, frames, pos, speed):
|
def __init__(self, frames, pos, speed):
|
||||||
Object.__init__(self, frames, pos, speed)
|
Object.__init__(self, frames, pos, speed)
|
||||||
|
self.shooting = False
|
||||||
|
|
||||||
def shoot(self):
|
def shoot(self):
|
||||||
""" create a bullet and add it to the global bullet list"""
|
""" create a bullet and add it to the global bullet list"""
|
||||||
|
@ -106,10 +118,15 @@ class Player(Object):
|
||||||
globals.moving_objects.remove(self)
|
globals.moving_objects.remove(self)
|
||||||
|
|
||||||
def start_shoot(self):
|
def start_shoot(self):
|
||||||
self.shoot()
|
self.shooting = True
|
||||||
|
|
||||||
def stop_shoot(self):
|
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():
|
def init_gfx():
|
||||||
"""graphics initialisation"""
|
"""graphics initialisation"""
|
||||||
|
|
Loading…
Reference in a new issue