Question: Assignment 5 A: Meteor Evader In this assignment, you will create a game where the player controls a spaceship and must navigate through space to
Assignment A: Meteor Evader
In this assignment, you will create a game where the player controls a spaceship and must navigate through space to avoid incoming meteors. The goal is to survive as long as possible by dodging meteors coming from all directions. The game will increase in diiculty over time, with more meteors appearing. The game ends when the player collides with a meteor.
Requirements:
The game window must be pixels wide by pixels tall.
Player Control:
o The player controls a spaceship using the W A S D keys up left, down, and right respectively
o The spaceship should be represented using a Pygame Rect eg a x pixel rectangle
o Ensure that the player cannot move outside the game window boundaries.
Meteors should spawn from the edges of the screen top bottom, left, and right
A random side is chosen for each meteors spawn location.
Based on the side from which a meteor spawns:
o Top: Moves downward. o Bottom: Moves upward. o Left: Moves rightward. o Right: Moves leftward.
Meteor Movement:
o Each meteor should have a horizontal dx and vertical dy speed component to control its movement direction.
o The speed components are determined based on the side from which the meteor spawns so that it moves inward toward the center of the screen.
o The meteors should vary in size and speed randomly generate meteor sizes between x and x pixels and randomize their speed components
New meteors should spawn every seconds.
Gradually increase the spawn rate or speed of the meteors as the player survives
longer.
Timer:
o Implement a timer that displays how long the player has survived.
o The timer will start when the game loop begins.
o The timer will stop when the spaceship collides with a meteor game ends
o The game will display the final survival time after a collision and reset the game.
The longer the player survives, the more meteors should spawn, making the game progressively harder.
Use Pygames colliderect method to detect collisions between the player's spaceship and meteors.
If the spaceship collides with any meteor, the game should end.
Implement a scoreboard to display the player's longest survival time.
The longest survival time should be stored and displayed even after the player loses.
When the players spaceship collides with a meteor, play a crashlike or destructionlike sound.
Play a sound eect every time a new meteor spawns to alert the player.
Ensure the sound files are loaded using pygame.mixer.Sound and play the sounds
at the appropriate events during gameplay.
Gradually speed up or slow down the meteors over time based on how long the player survives.
Make meteors visually distinct eg dierent colors or random shapes
Optional: Add background music to play throughout the game
using pygame.mixer.music.
Hints:
Use pygame.Rect to represent both the spaceship and meteors for easy collision detection.
Randomize the spawning side and speed of each meteor using random.choice and random.randint
Use pygame.time.getticks or pygame.time.Clock to manage meteor spawn timings and track the player's survival time.
Adjust meteor direction and speed using the dx and dy values based on where the meteor spawns.
Use pygame.font.Font to display the timer and score on the screen.
To load and play sound eects use pygame.mixer.Soundfilenamempplay
For background music,
use pygame.mixer.music.load and pygame.mixer.music.play to loop it continuously.
SAMPLE OUTPUT:
Meteor Evader
Time: s
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
