def create_obstacle(self, x_start, y_start,offset_x):
for row_index, row in enumerate(self.shape):
for col_index,col in enumerate(row):
if col == 'x':
x = x_start + col_index * self.block_size + offset_x
y = y_start + row_index * self.block_size
block = obstacle.Block(self.block_size,(241,79,80),x,y)
self.blocks.add(block)
def create_multiple_obstacles(self,*offset,x_start,y_start):
for offset_x in offset:
self.create_obstacle(x_start,y_start,offset_x)
def alien_setup(self,rows,cols,x_distance = 60,y_distance = 48,x_offset = 70, y_offset = 100):
for row_index, row in enumerate(range(rows)):
for col_index, col in enumerate(range(cols)):
x = col_index * x_distance + x_offset
y = row_index * y_distance + y_offset
# player lasers
if self.player.sprite.lasers:
for laser in self.player.sprite.lasers:
# obstacle collisions
if pygame.sprite.spritecollide(laser,self.blocks,True):
laser.kill()
# alien collisions
aliens_hit = pygame.sprite.spritecollide(laser,self.aliens,True)
if aliens_hit:
for alien in aliens_hit:
self.score += alien.value
laser.kill()
self.explosion_sound.play()
# extra collision
if pygame.sprite.spritecollide(laser,self.extra,True):
self.score += 500
laser.kill()
# alien lasers
if self.alien_lasers:
for laser in self.alien_lasers:
# obstacle collisions
if pygame.sprite.spritecollide(laser,self.blocks,True):
laser.kill()
if pygame.sprite.spritecollide(laser,self.player,False):
laser.kill()
self.lives -= 1
if self.lives <= 0:
pygame.quit()
sys.exit()
# aliens
if self.aliens:
for alien in self.aliens:
pygame.sprite.spritecollide(alien,self.blocks,True)
if pygame.sprite.spritecollide(alien,self.player,False):
pygame.quit()
sys.exit()
def display_lives(self):
for live in range(self.lives - 1):
x = self.live_x_start_pos + (live * (self.live_surf.get_size()[0] + 10))
screen.blit(self.live_surf,(x,8))
class CRT:
def __init__(self):
self.tv = pygame.image.load('../graphics/tv.png').convert_alpha()
self.tv = pygame.transform.scale(self.tv,(screen_width,screen_height))
def create_crt_lines(self):
line_height = 3
line_amount = int(screen_height / line_height)
for line in range(line_amount):
y_pos = line * line_height
pygame.draw.line(self.tv,'black',(0,y_pos),(screen_width,y_pos),1)