added dying state and animation to the ennemy
This commit is contained in:
parent
676d173010
commit
81d94ab8af
1 changed files with 24 additions and 7 deletions
29
pyshoot.py
29
pyshoot.py
|
@ -26,6 +26,7 @@ class Globals:
|
||||||
self.bullets_list = pygame.sprite.RenderUpdates()
|
self.bullets_list = pygame.sprite.RenderUpdates()
|
||||||
self.bulletfactory = BulletFactory()
|
self.bulletfactory = BulletFactory()
|
||||||
self.enemies_list = pygame.sprite.RenderUpdates()
|
self.enemies_list = pygame.sprite.RenderUpdates()
|
||||||
|
self.enemies_active_list = pygame.sprite.RenderUpdates()
|
||||||
self.player = None
|
self.player = None
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,6 +40,7 @@ class Object(pygame.sprite.Sprite):
|
||||||
pygame.sprite.Sprite.__init__(self)
|
pygame.sprite.Sprite.__init__(self)
|
||||||
self.speed = speed
|
self.speed = speed
|
||||||
self.frames = frames
|
self.frames = frames
|
||||||
|
self.frames_index = 0
|
||||||
self.image = None
|
self.image = None
|
||||||
self.load()
|
self.load()
|
||||||
self.rect = self.image.get_rect().move(pos)
|
self.rect = self.image.get_rect().move(pos)
|
||||||
|
@ -51,7 +53,7 @@ class Object(pygame.sprite.Sprite):
|
||||||
image.set_colorkey(pygame.Color(255,255,255, 0))
|
image.set_colorkey(pygame.Color(255,255,255, 0))
|
||||||
self.frames[index] = image
|
self.frames[index] = image
|
||||||
index += 1
|
index += 1
|
||||||
self.image = self.frames[0]
|
self.image = self.frames[self.frames_index]
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
self.rect.move_ip(self.speed)
|
self.rect.move_ip(self.speed)
|
||||||
|
@ -168,12 +170,20 @@ class Enemy(Object):
|
||||||
def __init__(self, frames, type, pos):
|
def __init__(self, frames, type, pos):
|
||||||
Object.__init__(self, frames, pos, (-1, 0))
|
Object.__init__(self, frames, pos, (-1, 0))
|
||||||
self.counter = 0
|
self.counter = 0
|
||||||
self.threshold = 10
|
self.threshold = 2
|
||||||
|
self.dying = False
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
if self.counter == self.threshold:
|
if self.counter == self.threshold:
|
||||||
|
if self.dying:
|
||||||
|
self.frames_index += 1
|
||||||
|
if self.frames_index == 6:
|
||||||
|
globals.enemies_list.remove(self)
|
||||||
|
return
|
||||||
|
self.image = self.frames[self.frames_index]
|
||||||
|
else:
|
||||||
self.rect.move_ip(self.speed)
|
self.rect.move_ip(self.speed)
|
||||||
self.count = 0
|
self.counter = 0
|
||||||
else:
|
else:
|
||||||
self.counter += 1
|
self.counter += 1
|
||||||
|
|
||||||
|
@ -182,7 +192,12 @@ class Enemy(Object):
|
||||||
|
|
||||||
def die(self):
|
def die(self):
|
||||||
""" make the enemy dying """
|
""" make the enemy dying """
|
||||||
globals.enemies_list.remove(self)
|
self.dying = True
|
||||||
|
self.threshold = 5
|
||||||
|
self.frames_index = 2
|
||||||
|
self.image = self.frames[self.frames_index]
|
||||||
|
globals.enemies_active_list.remove(self)
|
||||||
|
|
||||||
|
|
||||||
def init_gfx():
|
def init_gfx():
|
||||||
"""graphics initialisation"""
|
"""graphics initialisation"""
|
||||||
|
@ -236,7 +251,9 @@ def process_key(event, player):
|
||||||
elif event.key == K_x:
|
elif event.key == K_x:
|
||||||
player.start_shoot()
|
player.start_shoot()
|
||||||
elif event.key == K_e:
|
elif event.key == K_e:
|
||||||
globals.enemies_list.add(Enemy(['enemy1_1.bmp', 'enemy1_2.bmp'], 0, (500, 200)))
|
e = Enemy(['enemy1_1.bmp', 'enemy1_2.bmp', 'enemy1_3.bmp', 'enemy1_4.bmp', 'enemy1_5.bmp', 'enemy1_6.bmp'], 0, (500, 200))
|
||||||
|
globals.enemies_list.add(e)
|
||||||
|
globals.enemies_active_list.add(e)
|
||||||
elif event.key == K_SPACE:
|
elif event.key == K_SPACE:
|
||||||
player.change_bullet_type()
|
player.change_bullet_type()
|
||||||
|
|
||||||
|
@ -327,7 +344,7 @@ while not globals.die:
|
||||||
globals.enemies_list.update()
|
globals.enemies_list.update()
|
||||||
|
|
||||||
# collisions
|
# collisions
|
||||||
ret = pygame.sprite.groupcollide(globals.bullets_list, globals.enemies_list, False, False)
|
ret = pygame.sprite.groupcollide(globals.bullets_list, globals.enemies_active_list, False, False)
|
||||||
handle_enemies_collisions(ret)
|
handle_enemies_collisions(ret)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue