added laser shot and shot animation
This commit is contained in:
parent
2d829bf19c
commit
9477f8aa39
1 changed files with 35 additions and 7 deletions
42
pyshoot.py
42
pyshoot.py
|
@ -58,11 +58,17 @@ class Object(pygame.sprite.Sprite):
|
||||||
class BulletFactory():
|
class BulletFactory():
|
||||||
""" BulletFactory, create bullets """
|
""" BulletFactory, create bullets """
|
||||||
|
|
||||||
def create(self, type, pos):
|
def create(self, type, pos, wavepos):
|
||||||
""" create bullt of type type """
|
""" 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:
|
if type == 0:
|
||||||
return self.create_type0(pos)
|
return self.create_type0(pos)
|
||||||
|
|
||||||
|
if type == 1:
|
||||||
|
return self.create_type1(pos, wavepos)
|
||||||
|
|
||||||
def create_type0(self, pos):
|
def create_type0(self, pos):
|
||||||
""" create a bullet of type 0
|
""" create a bullet of type 0
|
||||||
temporary linear type """
|
temporary linear type """
|
||||||
|
@ -72,11 +78,14 @@ class BulletFactory():
|
||||||
bullet.damage = 10
|
bullet.damage = 10
|
||||||
return bullet
|
return bullet
|
||||||
|
|
||||||
def create_type1(self, pos):
|
def create_type1(self, pos, wavepos):
|
||||||
""" create a bullet of type 1
|
""" create a bullet of type 1
|
||||||
temporary laser type """
|
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.speed = (10,0)
|
||||||
bullet.damage = 10
|
bullet.damage = 10
|
||||||
return bullet
|
return bullet
|
||||||
|
@ -105,10 +114,18 @@ class Player(Object):
|
||||||
Object.__init__(self, frames, pos, speed)
|
Object.__init__(self, frames, pos, speed)
|
||||||
self.shooting = False
|
self.shooting = False
|
||||||
self.bullet_type = 0
|
self.bullet_type = 0
|
||||||
|
self.bullet_counter = 0
|
||||||
|
self.bullet_threshold = 5
|
||||||
|
|
||||||
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"""
|
||||||
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)
|
globals.bullets_list.add(bullet)
|
||||||
|
|
||||||
def start_move(self, vector):
|
def start_move(self, vector):
|
||||||
|
@ -127,14 +144,22 @@ class Player(Object):
|
||||||
|
|
||||||
def start_shoot(self):
|
def start_shoot(self):
|
||||||
self.shooting = True
|
self.shooting = True
|
||||||
|
self.shoot_wavepos = 0
|
||||||
|
|
||||||
def stop_shoot(self):
|
def stop_shoot(self):
|
||||||
self.shooting = False
|
self.shoot_wavepos = 2
|
||||||
|
|
||||||
|
def change_bullet_type(self):
|
||||||
|
self.bullet_type ^= 1
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
self.rect.move_ip(self.speed)
|
self.rect.move_ip(self.speed)
|
||||||
if self.shooting:
|
if self.shooting:
|
||||||
self.shoot()
|
if self.bullet_counter == self.bullet_threshold:
|
||||||
|
self.shoot()
|
||||||
|
self.bullet_counter = 0
|
||||||
|
else :
|
||||||
|
self.bullet_counter += 1
|
||||||
|
|
||||||
def init_gfx():
|
def init_gfx():
|
||||||
"""graphics initialisation"""
|
"""graphics initialisation"""
|
||||||
|
@ -192,6 +217,9 @@ def process_key(event, player):
|
||||||
player.start_move((1, 0))
|
player.start_move((1, 0))
|
||||||
elif event.key == K_x:
|
elif event.key == K_x:
|
||||||
player.start_shoot()
|
player.start_shoot()
|
||||||
|
elif event.key == K_SPACE:
|
||||||
|
player.change_bullet_type()
|
||||||
|
|
||||||
if event.type == KEYUP:
|
if event.type == KEYUP:
|
||||||
if event.key == K_UP:
|
if event.key == K_UP:
|
||||||
player.stop_move((0, -1))
|
player.stop_move((0, -1))
|
||||||
|
|
Loading…
Reference in a new issue