Question: Modify this space invaders game in the following ways. 2 5 Use an SVG image for each alien 2 5 Use an SVG for the

Modify this space invaders game in the following ways. 25 Use an SVG image for each alien
25 Use an SVG for the shooter
25 Add a custom feature (each alien rotates, changes color, undulates, etc.)
25 Add a custom feature for the player (rotates, changes color, explodes, fades out,
etc.) Code to modify included here. import pygame, random
#Initialize pygame
pygame.init()
#Set display surface
WINDOW_WIDTH =1200
WINDOW_HEIGHT =700
display_surface = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
pygame.display.set_caption("Space Invaders")
#Set FPS and clock
FPS =60
clock = pygame.time.Clock()
#Define Classes
class Game():
"""A class to help control and update gameplay"""
def __init__(self, player, alien_group, player_bullet_group, alien_bullet_group):
"""Initialze the game"""
#Set game values
self.round_number =1
self.score =0
self.player = player
self.alien_group = alien_group
self.player_bullet_group = player_bullet_group
self.alien_bullet_group = alien_bullet_group
#Set sounds and music
self.new_round_sound = pygame.mixer.Sound("new_round.wav")
self.breach_sound = pygame.mixer.Sound("breach.wav")
self.alien_hit_sound = pygame.mixer.Sound("alien_hit.wav")
self.player_hit_sound = pygame.mixer.Sound("player_hit.wav")
#Set font
self.font = pygame.font.Font("Facon.ttf",32)
def update(self):
"""Update the game"""
self.shift_aliens()
self.check_collisions()
self.check_round_completion()
def draw(self):
"""Draw the HUD and other information to display"""
#Set colors
WHITE =(255,255,255)
#Set text
score_text = self.font.render("Score: "+ str(self.score), True, WHITE)
score_rect = score_text.get_rect()
score_rect.centerx = WINDOW_WIDTH//2
score_rect.top =10
round_text = self.font.render("Round: "+ str(self.round_number), True, WHITE)
round_rect = round_text.get_rect()
round_rect.topleft =(20,10)
lives_text = self.font.render("Lives: "+ str(self.player.lives), True, WHITE)
lives_rect = lives_text.get_rect()
lives_rect.topright =(WINDOW_WIDTH -20,10)
#Blit the HUD to the display
display_surface.blit(score_text, score_rect)
display_surface.blit(round_text, round_rect)
display_surface.blit(lives_text, lives_rect)
pygame.draw.line(display_surface, WHITE, (0,50),(WINDOW_WIDTH, 50),4)
pygame.draw.line(display_surface, WHITE, (0, WINDOW_HEIGHT -100),(WINDOW_WIDTH, WINDOW_HEIGHT -100),4)
def shift_aliens(self):
"""Shift a wave of aliens down the screen and reverse direction"""
#Determine if alien group has hit an edge
shift = False
for alien in (self.alien_group.sprites()):
if alien.rect.left =0 or alien.rect.right >= WINDOW_WIDTH:
shift = True
#Shift every alien down, change direction, and check for a breach
if shift:
breach = False
for alien in (self.alien_group.sprites()):
#Shift down
alien.rect.y +=10*self.round_number
#Reverse the direction and move the alien off the edge so 'shift' doesn't trigger
alien.direction =-1*alien.direction
alien.rect.x += alien.direction*alien.velocity
#Check if an alien reached the ship
if alien.rect.bottom >= WINDOW_HEIGHT -100:
breach = True
#Aliens breached the line
if breach:
self.breach_sound.play()
self.player.lives -=1
self.check_game_status("Aliens breached the line!", "Press 'Enter' to continue")
def check_collisions(self):
"""Check for collisions"""
#See if any bullet in the player bullet group hit an alien in the alien group
if pygame.sprite.groupcollide(self.player_bullet_group, self.alien_group, True, True):
self.alien_hit_sound.play()
self.score +=100
#See if the player has collided with any bullet in the alien bullet group
if pygame.sprite.spritecollide(self.player, self.alien_bullet_group, True):
self.player_hit_sound.play()
self.player.lives -=1
self.check_game_status("You've been hit!", "Press 'Enter' to continue")
def check_round_completion(self):
"""Check to see if a player has completed a single round"""
#If the alien group is empty, you've completed the round
if not (self.alien_group):
self.score +=1000*self.round_number
self.round_number +=1
self.start_new_round()
def start_new_round(self):
 Modify this space invaders game in the following ways. 25 Use

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!