added laser shot and shot animation
This commit is contained in:
parent
2d829bf19c
commit
9477f8aa39
1 changed files with 35 additions and 7 deletions
40
pyshoot.py
40
pyshoot.py
|
@ -58,11 +58,17 @@ class Object(pygame.sprite.Sprite):
|
|||
class BulletFactory():
|
||||
""" BulletFactory, create bullets """
|
||||
|
||||
def create(self, type, pos):
|
||||
""" create bullt of type type """
|
||||
def create(self, type, pos, wavepos):
|
||||
""" create bullt of type type
|
||||
wave paremeter indicate the position of the bullet in the wave :
|
||||
starting the wave (0), middle (1) or ending the wave (2 )"""
|
||||
|
||||
if type == 0:
|
||||
return self.create_type0(pos)
|
||||
|
||||
if type == 1:
|
||||
return self.create_type1(pos, wavepos)
|
||||
|
||||
def create_type0(self, pos):
|
||||
""" create a bullet of type 0
|
||||
temporary linear type """
|
||||
|
@ -72,11 +78,14 @@ class BulletFactory():
|
|||
bullet.damage = 10
|
||||
return bullet
|
||||
|
||||
def create_type1(self, pos):
|
||||
def create_type1(self, pos, wavepos):
|
||||
""" create a bullet of type 1
|
||||
temporary laser type """
|
||||
|
||||
bullet = Bullet(['laser1.bmp', 'laser2.bmp', 'laser3.bmp'], 0, pos)
|
||||
filename = 'laser' + str(wavepos + 1) + '.bmp'
|
||||
#print "filename: " + filename
|
||||
#filename = 'laser1.bmp'
|
||||
bullet = Bullet([filename], 0, pos)
|
||||
bullet.speed = (10,0)
|
||||
bullet.damage = 10
|
||||
return bullet
|
||||
|
@ -105,10 +114,18 @@ class Player(Object):
|
|||
Object.__init__(self, frames, pos, speed)
|
||||
self.shooting = False
|
||||
self.bullet_type = 0
|
||||
self.bullet_counter = 0
|
||||
self.bullet_threshold = 5
|
||||
|
||||
def shoot(self):
|
||||
""" create a bullet and add it to the global bullet list"""
|
||||
bullet = globals.bulletfactory.create(self.bullet_type, self.rect.midright)
|
||||
bullet = globals.bulletfactory.create(self.bullet_type, self.rect.midright, self.shoot_wavepos)
|
||||
if self.shoot_wavepos == 0:
|
||||
self.shoot_wavepos = 1
|
||||
if self.shoot_wavepos == 2:
|
||||
self.shoot_wavepos = 0
|
||||
self.shooting = False
|
||||
|
||||
globals.bullets_list.add(bullet)
|
||||
|
||||
def start_move(self, vector):
|
||||
|
@ -127,14 +144,22 @@ class Player(Object):
|
|||
|
||||
def start_shoot(self):
|
||||
self.shooting = True
|
||||
self.shoot_wavepos = 0
|
||||
|
||||
def stop_shoot(self):
|
||||
self.shooting = False
|
||||
self.shoot_wavepos = 2
|
||||
|
||||
def change_bullet_type(self):
|
||||
self.bullet_type ^= 1
|
||||
|
||||
def update(self):
|
||||
self.rect.move_ip(self.speed)
|
||||
if self.shooting:
|
||||
if self.bullet_counter == self.bullet_threshold:
|
||||
self.shoot()
|
||||
self.bullet_counter = 0
|
||||
else :
|
||||
self.bullet_counter += 1
|
||||
|
||||
def init_gfx():
|
||||
"""graphics initialisation"""
|
||||
|
@ -192,6 +217,9 @@ def process_key(event, player):
|
|||
player.start_move((1, 0))
|
||||
elif event.key == K_x:
|
||||
player.start_shoot()
|
||||
elif event.key == K_SPACE:
|
||||
player.change_bullet_type()
|
||||
|
||||
if event.type == KEYUP:
|
||||
if event.key == K_UP:
|
||||
player.stop_move((0, -1))
|
||||
|
|
Loading…
Reference in a new issue