ADDING EXPLOSIONS
This commit is contained in:
parent
d93b26e2be
commit
a860c17973
|
@ -55,6 +55,11 @@ class Spaceship(pygame.sprite.Sprite):
|
|||
bullet_group.add(bullet)
|
||||
self.last_shot = time_now
|
||||
|
||||
# update mask
|
||||
self.mask = pygame.mask.from_surface(self.image) # this does pixel perfect collison becasue it ignores anything that is not spaceship
|
||||
|
||||
|
||||
|
||||
pygame.draw.rect(screen, RED, (self.rect.x, (self.rect.bottom +10), self.rect.width, 15))
|
||||
if self.health_remaining > 0:
|
||||
pygame.draw.rect(screen, GREEN, (self.rect.x, (self.rect.bottom +10), int(self.rect.width * (self.health_remaining / self.health_start)), 15) )
|
||||
|
@ -70,6 +75,9 @@ class Bullets(pygame.sprite.Sprite):
|
|||
self.rect.y -= 5
|
||||
if self.rect.bottom < 0:
|
||||
self.kill()
|
||||
if pygame.sprite.spritecollide(self, alien_group, True):
|
||||
self.kill()
|
||||
|
||||
# video for this https://www.youtube.com/watch?v=mqz1_wRSMwo
|
||||
class Aliens(pygame.sprite.Sprite):
|
||||
def __init__(self,x ,y):
|
||||
|
@ -95,7 +103,10 @@ class Alien_Bullets(pygame.sprite.Sprite):
|
|||
def update(self):
|
||||
self.rect.y += 2
|
||||
if self.rect.top > HEIGHT:
|
||||
self.kill()
|
||||
self.kill()
|
||||
if pygame.sprite.spritecollide(self, spaceship_group, False, pygame.sprite.collide_mask):
|
||||
self.kill()
|
||||
spaceship.health_remaining -= 1
|
||||
|
||||
# create sprite groups
|
||||
spaceship_group = pygame.sprite.Group()
|
||||
|
|
Loading…
Reference in New Issue
Block a user